jkhsjdhjs / maubot-webhook

A maubot plugin to send messages using webhooks.
GNU Affero General Public License v3.0
14 stars 6 forks source link

Feature Request: Custom Bot Settings #9

Open tonytonyistony opened 5 months ago

tonytonyistony commented 5 months ago

Ill start off by saying Im no webhook expert. From what Ive been reading is every app has its webhook API developed in a specific way. If you want to interface with it you have to structure the json payload a very specific way. Which is exactly why webhook bots have uniquely designed functions for Github, JIRA, Gitlab, ect.

For example

{"content":"Hello, World!"} // discord payload
//---
{"text": "Hello, World!"} // matrix payload

To send messages to Discord your message payload must be content not message or text. I think it would be unique if you could make a bot that allows a capable user to change these settings on the back end through the Maubot gui. This would allow you to take advantage of any systems webhook design no matter which API they use to send API calls to.

This question may be stupid, or even short sighted. Im very curious to hear your feedback on this type functionality, or if your bot already has it and I just dont know how to configure it.

jkhsjdhjs commented 5 months ago

So if I understand you correctly, you want to send messages via outgoing webhooks, i.e. have a plugin call a webhook of a different service to send a message or do some other stuff. That's unfortunately not what this plugin is for, this plugin is only for inbound webhooks, i.e. send a matrix message whenever a webhook created by this plugin is called.

tonytonyistony commented 5 months ago

you want to send messages via outgoing webhooks,

TLDR I want to be able to configure your bot to receive incoming webhook messages designed for other webhook api, like Discord.

I want to be able to change the payload variables so, if a developer made a webhook sender specifically for Discord, I could modify your bot on the fly to support and receive Discord formatted webhook calls.

I have a python website whom the developer made a webhook function that I use in Discord. He designed it specifically around Discord's webhook API format. It would pretty unique if your Maubot plugin could "mimic" other services webhook API and make it customization by the end user, rather than you having to code in every since webhook api imaginable.

Does that make sense?

Again, this could be way out of scope or an programming undertaking so large its just not feasible. Im only asking the questions to get gauge, since you know how to design a webhook endpoint.

jkhsjdhjs commented 5 months ago

Ah, I see. Yeah, that should already be possible with this plugin. Assuming that the discord payload simply contains the text message as the content property of a JSON object, you could create a webhook with the following message template

message: {{ json.content }}
tonytonyistony commented 5 months ago

Ah, I see. Yeah, that should already be possible with this plugin. Assuming that the discord payload simply contains the text message as the content property of a JSON object, you could create a webhook with the following message template

message: {{ json.content }}

Interesting. Let me play around with that. So can you make variable changes like that for every item in webhook template?

tonytonyistony commented 5 months ago

Also while I have your attention, Im having a little trouble with a couple defintions. your.maubot.instance = matrix.exmaple.com ? <InstanceID> = !RAtrTpuJHOONswjVav:example.com ? https://matrix.exmaple.com/_matrix/maubot/plugin/!RAtrTpuJHOONswjVav:example.com/send ?

jkhsjdhjs commented 5 months ago

your.maubot.instance = matrix.exmaple.com ?

Nope, that's the public URL of your maubot instance. Not sure if you're aware, but this isn't a standalone thing, but a plugin for maubot: https://github.com/maubot/maubot

<InstanceID> = !RAtrTpuJHOONswjVav:example.com ?

This will be your maubot plugin instance id. Should make sense once you have installed maubot.

So can you make variable changes like that for every item in webhook template?

You can extract all JSON properties, variable contained within the request path, query parameters and the entire request body.

tonytonyistony commented 5 months ago

image

jkhsjdhjs commented 5 months ago

InstanceID is correct, but the maubot instance URL is the URL you see in the address bar of your browser when accessing the maubot web ui. If that's matrix.example.com in your case, then I'm sorry for doubting you. It's just that I have my maubot instance running on a domain different from my matrix server.

tonytonyistony commented 5 months ago

image

jkhsjdhjs commented 5 months ago

The URL of you webhook is also logged when you start the instance, so just click View logs and retrieve it from there.

tonytonyistony commented 5 months ago

The URL of you webhook is also logged when you start the instance, so just click View logs and retrieve it from there.

Im currently still trying to fix that issue. My logs arent working. lol

jkhsjdhjs commented 5 months ago

Ah, maybe because of your reverse proxy. The logs are accessed via a websocket, and most reverse proxies such as nginx require you to set that up separately. Anyway, the URL should be https://matrix.example.com/_matrix/maubot/plugin/webhook/send in your case.

tonytonyistony commented 5 months ago

Ah, maybe because of your reverse proxy. The logs are accessed via a websocket, and most reverse proxies such as nginx require you to set that up separately. Anyway, the URL should be https://matrix.example.com/_matrix/maubot/plugin/webhook/send in your case.

        location /_matrix/maubot/v1/logs {
                proxy_pass http://10.133.3.225:81;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header X-Forwarded-For $remote_addr;
        }

This is what I have set in my proxy config

jkhsjdhjs commented 5 months ago

Hmm, that's the same I also have. I additionally added

proxy_read_timeout 86400s;
proxy_send_timeout 86400s;

so the maubot frontend doesn't have to create a new websocket connection every minute, but otherwise it's the same. You can check the network tab of the web developer tools your browser comes with so see if there's something going wrong when accessing the logs. It's also possible that you only enabled displaying errors, in which case your logs might as well be empty.

tonytonyistony commented 5 months ago

Im going to create a new ticket. Getting an error running your example test.