nioc / xmpp-bot

XMPP Bot is a tiny little bot making the link between XMPP conversations and webhooks.
GNU Affero General Public License v3.0
22 stars 3 forks source link

[Feature] Gitea Webhooks #21

Closed roughnecks closed 7 months ago

roughnecks commented 7 months ago

Is your feature request related to a problem? Please describe. In the gitea webhook settings I cannot set a destination as body

Describe the solution you'd like Maybe it would be possible to add a second (or more) incoming webhook(s) with a fixed destination

Additional context The hook is working, but I get this in console: [2024-01-22T17:11:26.262] [ERROR] default - Destination not found

nioc commented 7 months ago

Hello, you can add as many send template as requested in config.json. I'm not sure to understand your problem, can you provide an web hook example?

roughnecks commented 7 months ago

what I was trying to say is that I need to specify a destination in bot's config file, because I have no way to pass one from the gitea webhook (or even git).

https://i.imgur.com/vTvEwFM.jpeg

The POST body is added automatically in gitea, so how do I tell it to send the message to my JID/MUC?

Instead in IFTTT recipes I can specify the destination, like this:

https://i.imgur.com/Pb8QRCj.jpeg

nioc commented 7 months ago

Can you post a HTTP request example? I think you can achieve your goal with something like this in config.json:

    // ...
    "incomingWebhooks": [
        {
            "path": "/webhooks/gitea",
            "action": "send_xmpp_template",
            "args": {
                "destination": "grafana@conference.domain-xmpp.ltd",
                "type": "groupchat"
            },
            "template": "${title}\r\n${message}\r\n${evalMatches[].metric}: ${evalMatches[].value}\r\n${imageUrl}"
        }
    ],
    // ...
roughnecks commented 7 months ago

Hi, thanks. I'm not at my pc currently, will check as soon as I can.

Il 24 gennaio 2024 12:05:59 CET, Nicolas @.***> ha scritto:

Can you post a HTTP request example? I think you can achieve your goal with something like this in config.json:

   "incomingWebhooks": [
       {
           "path": "/webhooks/gitea",
           "action": "send_xmpp_template",
           "args": {
               "destination": ***@***.***",
               "type": "groupchat"
           },
           "template": "${title}\r\n${message}\r\n${evalMatches[].metric}: ${evalMatches[].value}\r\n${imageUrl}"
       }
   ],

-- Reply to this email directly or view it on GitHub: https://github.com/nioc/xmpp-bot/issues/21#issuecomment-1907908003 You are receiving this because you authored the thread.

Message ID: @.***>

roughnecks commented 7 months ago

Hi again, I think the template has something wrong. The webhook worked but my bot only sent a "colon":

[2024-01-24T16:37:57.195] [TRACE] default - Send to muc@chat.woodp...t.space (group:groupchat) following message :

:

nioc commented 7 months ago

That doesn't surprise me, template was an example for grafana alerting request like this:

HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "dashboardId": 1,
  "dashboardUId": "ABcdEFghij"
  "dashboardSlug": "sensors",
  "panelId": 1,
  "name": "fire place sensor",
  "state": "alerting",
  "message": "Someone is trying to break in through the fire place",
  "newStateDate": "2018-05-14T05:55:20+02:00",
  "evalDate": "0001-01-01T00:00:00Z",
  "evalData": "evalMatches": [
    {
      "metric": "movement",
      "tags": {
        "name": "fireplace_chimney"
      },
      "value": 98.765
    }
  ],
  "executionError": "",
  "url": "http://grafana.com/dashboard/db/sensors"
}

using the previous template, it should output:


Someone is trying to break in through the fire place
movement: 98.765

You have to change the template attribute with Gitea JSON attribute you want. For testing your template construction, you can see how jmespath.js works: https://jmespath.org/tutorial.html and test with local json response.

nioc commented 7 months ago

@roughnecks did you find a way to configure ingoing webhook from gitea? Can you I close the issue?

roughnecks commented 7 months ago

I don't have time right now to investigate.

roughnecks commented 7 months ago

I'm trying right now from "uptime-kuma" to send a webhook and I'm getting this:

[2024-02-12T16:24:50.288] [INFO] default - Incoming webhook from roughnecks      
[2024-02-12T16:24:50.289] [DEBUG] default - Webhook received: /webhooks/kuma, sta
rt action: send_xmpp_message                                                     
[2024-02-12T16:24:50.289] [TRACE] default - { heartbeat: null, monitor: null, msg
: 'Notifica Webhook (1) Testing' }                                               
[2024-02-12T16:24:50.289] [ERROR] default - Destination not found                            

This is my configuration:

        {                                                           
            "path": "/webhooks/kuma",                               
            "action": "send_xmpp_message",                          
            "args": {                                               
                "destination": "room@chat.woodpeckersnest.space",
                "type": "groupchat"                                 
            }                                                       
        },                                                          

I have removed the template part, still don't know why it says "destination not found"; bot is inside the room.

https://i.imgur.com/lHGKlQj.jpeg

Thanks

roughnecks commented 7 months ago

I got it working with a template, like this:

"template": "${heartbeat}\r\n${monitor}\r\n${msg}"

For some reason "send_xmpp_message" won't work.

roughnecks commented 7 months ago

Actually the first 2 vars are not working correctly, as I'm getting this:

image

So I just left the $msg one.

nioc commented 7 months ago

Hello, for your last message, both variables heartbeat and monitor seems to be object, if you can have their structure (I found this article), you should be able to set something like this:

"template": "${heartbeat.time}\r\n${monitor.name}\r\n${msg}"
roughnecks commented 7 months ago

Thanks, it worked! Do you know a way to get the objects? Here and maybe on other services?

nioc commented 7 months ago

You can set logger level to trace (data is traced here) If it is not working, replace it by:

logger.trace(JSON.stringify(req.body))
roughnecks commented 7 months ago

Thanks, will do!

roughnecks commented 7 months ago

A little help again needed. I have this output:

"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":[]}]

And I tried with ${commits.message} but it came out empty.. maybe I need some [0] or something, 'cause that looks like an array.

Can you help me getting the message, username and timestamp? Thanks

roughnecks commented 7 months ago

Nevermind, everything is working now:

`"template": "Commit from: ${commits[0].committer.username} - Date: ${commits[0].timestamp} - Repository: ${repository.name} - Message: ${commits[0].message}\r\n${compare_url}"

👍