Coder Social home page Coder Social logo

[Feature] Gitea Webhooks about xmpp-bot HOT 17 CLOSED

roughnecks avatar roughnecks commented on July 4, 2024
[Feature] Gitea Webhooks

from xmpp-bot.

Comments (17)

roughnecks avatar roughnecks commented on July 4, 2024 1

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}"

👍

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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?

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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": "[email protected]",
                "type": "groupchat"
            },
            "template": "${title}\r\n${message}\r\n${evalMatches[].metric}: ${evalMatches[].value}\r\n${imageUrl}"
        }
    ],
    // ...

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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 [email protected]...t.space (group:groupchat) following message :

:

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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.

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

I don't have time right now to investigate.

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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": "[email protected]",
                "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

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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.

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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

image

So I just left the $msg one.

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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}"

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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

from xmpp-bot.

nioc avatar nioc commented on July 4, 2024

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))

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

Thanks, will do!

from xmpp-bot.

roughnecks avatar roughnecks commented on July 4, 2024

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":"[email protected]","username
":"roughnecks"},"committer":{"name":"Simone","email":"[email protected]","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

from xmpp-bot.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.