Strumenti Utente

Strumenti Sito


xmpp-it:guide:configurazione-xmpp-bot

XMPP-BOT - Configurazione/Uso con Forgejo e Uptime-Kuma

Configurazione del bot

    "incomingWebhooks": [
        {
            "path": "/webhooks/kuma-uptime",
            "action": "send_xmpp_template",
            "args": {
                "destination": "groupchat@example.tld",
                "type": "groupchat"
            },
            "template": "${heartbeat.time}\r\n${msg}"
        },
        {
            "path": "/webhooks/forgejo",
            "action": "send_xmpp_template",
            "args": {
                "destination": "groupchat@example.tld",
                "type": "groupchat"
            },
            "template": "Commit da: ${commits[0].committer.username} - Data: ${commits[0].timestamp} - Repository: ${repository.name} - Messaggio: ${commits[0].message}\r\n${compare_url}"
        }

Configurazione notifiche su Kuma-Uptime

Dashboard - Impostazioni - Notifiche - Configura Notifiche - Webhook

Post URL:

  https://example.tld:port/webhooks/kuma-uptime
  

Request Body:

  Predefinito - application/json
  

[x] Headers Aggiuntivi

{

 "Authorization": "Basic <secret>"

}

Configurazione repo su Forgejo

Impostazioni repository - Webhook - Aggiungi Webhook - Forgejo

URL di destinazione:

  
  https://example.tld:port/webhooks/forgejo
  

Metodo HTTP

  
  POST
  

Tipo di contenuto POST

  
  application/json
  

Authorization Header

  
  Basic <secret>
  

Ottenere il segreto <secret>

  
  $ echo -n "joeuser:secretpass" | base64
  

“joeuser:secretpass” andrà inserito nella configurazione di xmpp-bot alla seguente sezione:

  
      "users": [
          {
              "login": "joeuser",
              "password": "secretpass"
          }
      ],

Personalizzare l'output di ciascun webhook

Cambiare la seguente riga di codice in xmpp-bot:

https://git.xmpp-it.net/roughnecks/xmpp-bot/src/branch/master/lib/webhook/index.js#L66

in modo che risulti invece:

  
  logger.trace(JSON.stringify(req.body))
  

Ad ogni webhook eseguito, il bot ora mostrerà il json completo dell'oggetto, dal quale estrapolare qualsiasi dato voluto per l'output nel gruppo XMPP di destinazione, da inserire nel parametro “template”: utilizzato sopra.

Questo è un esempio del json prodotto:

    { "ref": "refs/heads/main", "before": "bdc8ee6bebeaa9f4e0ffd992ec1fefe6de84624b", "after":"a472c1bf0acd88e1d6a0ea291ae3cb0e08048862","compare_url":"https: //git.xmpp-it.net/roughnecks/Configurazioni-BoT/compare/bdc8ee6bebeaa9f4e0ffd992ec1fefe6de84624b...a472c1bf0acd88 e1d6a0ea291ae3cb0e08048862","commits":[{"id":"a472c1bf0acd88e1d6a0ea291ae3cb0e08048862","message":"Incollato originale\n","url":"https: //git.xmpp-it.net/ roughnecks/Configurazioni-BoT/commit/a472c1bf0acd88e1d6a0ea291ae3cb0e08048862","author":{"name":"Simone","email":"roughnecks@xmpp-it.guest.net","username ":"roughnecks"},"committer":{"name":"Simone","email":"roughnecks@xmpp-it.guest.net","username":"roughnecks"},"verification":null,"timestamp":"2024-02-13T 18: 22: 04+01: 00","added":["lib/webhook/index.js"],"removed":[],"modified":[]}],"total_commits":1,"head_commit":{"id":"a472c1bf0acd88e1d6a0ea291ae3cb0e0804 8862","message":"Incollato originale\n","url":"https: //git.xmpp-it.net/roughnecks/Configurazioni-BoT/commit/a472c1bf0acd88e1d6a0ea291ae3cb0e08048862","au thor":{"name":"Simone","email":"roughnecks@xmpp-it.guest.net","username":"roughnecks"},"committer":{"name":"Simone","email":"roughnecks@xmpp-it.guest.net ","username":"roughnecks"},"verification":null,"timestamp":"2024-02-13T18: 22: 04+01: 00","added":["lib/webhook/index.js"],"removed":[],"modified":[]},"repo sitory":{"id":5,"owner":{"id":1,"login":"roughnecks","login_name":"","full_name":"Simone","email":"roughnecks@xmpp-it.guest.net","avatar_url":"https: //gi t.xmpp-it.net/avatar/e1c83c0ef02c32070504f0fb80eca406","language":"","is_admin":false,"last_login":"0001-01-01T00: 00: 00Z","created":"2023-11-11T23: 35: 46+ 01: 00","restricted":false,"active":false,"prohibit_login":false,"location":"Italy, Marche","website":"https: //woodpeckersnest.space/","description":"","v isibility":"public","followers_count":1,"following_count":1,"starred_repos_count":0,"username":"roughnecks"},"name":"Configurazioni-BoT","full_name":"rou ghnecks/Configurazioni-BoT","description":"","empty":false,"private":false,"fork":false,"template":false,"parent":null,"mirror":false,"size":47,"language ":"","languages_url":"https: //git.xmpp-it.net/api/v1/repos/roughnecks/Configurazioni-BoT/languages","html_url":"https://git.xmpp-it.net/roughnecks/Config urazioni-BoT","url":"https: //git.xmpp-it.net/api/v1/repos/roughnecks/Configurazioni-BoT","link":"","ssh_url":"git@git.xmpp-it.net:roughnecks/Configurazio ni-BoT.git","clone_url":"https: //git.xmpp-it.net/roughnecks/Configurazioni-BoT.git","original_url":"","website":"","stars_count":0,"forks_count":0,"watch ers_count":1,"open_issues_count":0,"open_pr_counter":0,"release_counter":0,"default_branch":"main","archived":false,"created_at":"2023-11-12T19: 02: 00+01: 00","updated_at":"2024-01-24T16: 37: 55+01: 00","archived_at":"1970-01-01T01: 00: 00+01: 00","permissions":{"admin":true,"push":true,"pull":true},"has_issues":false, "has_wiki": false, "has_pull_requests": false, "has_projects": false, "has_releases": false, "has_packages": false, "has_actions": false,"ignore_whitespace_co nflicts":false,"allow_merge_commits":false,"allow_rebase":false,"allow_rebase_explicit":false,"allow_squash_merge":false,"allow_rebase_update":false,"def ault_delete_branch_after_merge":false,"default_merge_style":"merge","default_allow_maintainer_edit":false,"avatar_url":"","internal":false,"mirror_interv al":"","mirror_updated":"0001-01-01T00: 00: 00Z","repo_transfer":null},"pusher":{"id":1,"login":"roughnecks","login_name":"","full_name":"Simone","email":" roughnecks@xmpp-it.guest.net","avatar_url":"https: //git.xmpp-it.net/avatar/e1c83c0ef02c32070504f0fb80eca406","language":"","is_admin":false,"last_login": "0001-01-01T00:00:00Z", "created": "2023-11-11T23:35:46+01:00", "restricted": false, "active": false, "prohibit_login": false, "location": "Italy, Marche","website":"https: //woodpeckersnest.space/","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":0,"username":"rou ghnecks"},"sender":{"id":1,"login":"roughnecks","login_name":"","full_name":"Simone","email":"roughnecks@xmpp-it.guest.net","avatar_url":"https: //git.xmp p-it.net/avatar/e1c83c0ef02c32070504f0fb80eca406","language":"","is_admin":false,"last_login":"0001-01-01T00: 00: 00Z","created":"2023-11-11T23: 35: 46+01: 00 ","restricted":false,"active":false,"prohibit_login":false,"location":"Italy, Marche","website":"https: //woodpeckersnest.space/","description":"","visibi lity":"public","followers_count":1,"following_count":1,"starred_repos_count":0,"username":"roughnecks"}}

Per gli amministratori di una istanza Forgejo/Gitea

  
  
      {
          "path": "/webhooks/newrepo",
          "action": "send_xmpp_template",
          "args": {
              "destination": "groupchat@example.tld",
              "type": "groupchat"
          },
          "template": "Repository ${repository.full_name} ${action}, visibilita': ${repository.owner.visibility}\r\n${repository.html_url}"
      }
  

Utile per avere notifiche su ogni nuovo repository creato nell'istanza - il webhook andrà aggiunto nelle impostazioni dell'istanza, anziché in quelle del singolo repository

xmpp-it/guide/configurazione-xmpp-bot.txt · Ultima modifica: 2024/03/29 16:14 da roughnecks