turt2live / matrix-appservice-webhooks Goto Github PK
View Code? Open in Web Editor NEWSlack-compatible webhooks for matrix
License: GNU General Public License v3.0
Slack-compatible webhooks for matrix
License: GNU General Public License v3.0
Blocked by #13
Only do transforms on slack endpoint.
<https://alert-system.com/alerts/1234|Click here>
becomes <a href='https://alert-system.com/alerts/1234'>Click here</a>
<@user:matrix.org:Bob>
becomes <a href='https://matrix.to/#/user/@user:matrix.org'>Bob</a>
<#room:matrix.org|Room>
becomes <a href="https://matrix.to/#/#room:matrix.org">Room</a>
Because spam
https://github.com/turt2live/matrix-appservice-webhooks/blob/master/config/sample.yaml#L27 still mentions :4501 - should be :9000 now.
Tried to use with CircleCI, getting Error: Hook failed.
on CircleCI side.
Logs says Invalid message: missing text or attachments
.
By using tcpdump I see the json as: {"attachments":[{"fallback":"Hello from CircleCI","text":"Hello from CircleCI","color":"#AAAAAA"}],"text":"","channel":""}
Shouldn't that already be covered by #17 or #32 ?
Running latest turt2live/matrix-appservice-webhooks:latest
docker image.
Slack does client-side date transformation. No matrix client supports similar behaviour, so the initial version of this will be to just dump a date in the message.
https://api.slack.com/docs/message-formatting#formatting_dates
ref: https://api.slack.com/docs/message-attachments
The fallback
should be treated as plain text (no formatting) and is used when the client (matrix) doesn't support the message.
color
: good
, warning
, danger
, or any hex code like #439FE0
Attachments are otherwise rendered with a grey line. It's unfortunate that matrix doesn't support the line wrapping (pre-text) thing, but this will work for now.
This would be pretext<br>
<font color='#d9534f'>▌</font> danger is #d9534f<br>
<font color='#f0ad4e'>▌</font> warning is #f0ad4e<br>
<font color='#5cb85c'>▌</font> good is #5cb85c<br>
<font color='#439fe0'>▌</font> custom is #439fe0
Pretext is pretext
Use #f7f7f7 for default.
author_name
, author_link
, author_icon
<img src='mxc://t2bot.io/hcSELkhLCNMRxLLTXKffPPSn' width='16' height='16'> <a href='https://matrix.to/#/user/@voyager:t2bot.io'>Matrix Traveler</a>
Although the image may need cropping ahead of time.
Basically an h3 as an anchor
fields
is an array of {title, value, short}
. short
is optional.
footer
and footer_icon
(text & image). Treat much like the authors
ts
(timestamp) - seconds since epoch
I think? Tried to add a new webhook in a room, but it kept doing nothing
The _webhook user was already created when I started the bridge so it just got stuck at the M_USER_IN_USE error. I tried deactivating the _webhook account using the Admin API but I still get the same error:
Loading config file /app/config/config.yaml
May-19-2018 07:09:59.743 +00:00 info [index] Preparing database...
May-19-2018 07:09:59.744 +00:00 info [WebhookStore] Running migrations
[INFO] No migrations to run
[INFO] Done
Sat, 19 May 2018 07:09:59 GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at ../node_modules/sequelize/lib/sequelize.js:242:13
May-19-2018 07:09:59.876 +00:00 info [index] Preparing bridge...
May-19-2018 07:09:59.876 +00:00 info [WebhookBridge] Constructing bridge
May-19-2018 07:09:59.877 +00:00 info [WebhookBridge] Starting bridge
May-19-2018 07:10:00.208 +00:00 info [WebhookBridge] Updating appearance of bridge bot
May-19-2018 07:10:00.226 +00:00 warn [index] No provisioning API token is set - the provisioning API will not work for this bridge
May-19-2018 07:10:00.228 +00:00 info [WebService] API now listening on 0.0.0.0:4501
May-19-2018 07:10:00.336 +00:00 error [matrix-appservice-bridge] [-] POST https://nerdsin.space/_matrix/client/r0/register (AS) HTTP 400 Error: {"errcode":"M_USER_IN_USE","error":"User ID already taken."}
Something like /api/v1/matrix/slack/hook/:hookId
to allow for payload={"text":"This is a line of text.\nAnd this is another one."}
We should just use the existing appservice port.
It is actually authed, despite bugs.
For services where you want to put the webhook URL in, but can't reasonably treat the whole URL as a secret
<#matrix:matrix.org|Matrix Chat>
Using the same webhook display name, using two different rooms (webhook links) causes very strange results in the second room.
Just sent something stupid by mistake
{
"username": "whatever",
}
And it returns 400 Bad request
but with html. Maybe catch and return JSON instead?
If icon_emoji
exists, use it if avatarUrl
is missing.
Can be a URL or :shark:
(for example)
When following your instructions from README.MD
and starting the server with node index.js -p 9000 -c config/config.yaml
I get the following error output:
Nov-15-2017 11:57:05.964 +01:00 verbose [matrix-appservice-bridge] [-] GET http://localhost:8008/_matrix/client/r0/joined_rooms (AS) Body:
Nov-15-2017 11:57:05.971 +01:00 info [WebService] API now listening on 0.0.0.0:4501
Nov-15-2017 11:57:05.995 +01:00 verbose [WebhookStore [SQL]] Executing (default): SELECT `id`, `objectId`, `key`, `value` FROM `account_data` AS `account_data` WHERE `account_data`.`objectId` = 'bridge';
Nov-15-2017 11:57:06.007 +01:00 verbose [matrix-appservice-bridge] [-] GET http://localhost:8008/_matrix/client/r0/joined_rooms (AS) HTTP 200 {"joined_rooms":[]}
Nov-15-2017 11:57:06.013 +01:00 verbose [utils] Downloading image from http://i.imgur.com/IDOBtEJ.png
Nov-15-2017 11:57:06.016 +01:00 verbose [matrix-appservice-bridge] [-] POST http://localhost:8008/_matrix/client/r0/register (AS) Body: {"auth":{},"username":"_webhook"}
Nov-15-2017 11:57:06.033 +01:00 error [matrix-appservice-bridge] [-] POST http://localhost:8008/_matrix/client/r0/register (AS) HTTP 400 Error: {"errcode":"M_USER_IN_USE","error":"User ID already taken."}
Nov-15-2017 11:57:06.036 +01:00 verbose [matrix-appservice-bridge] [-] GET http://localhost:8008/_matrix/client/r0/profile/%40_webhook%3Alocalhost/displayname (@_webhook:localhost) Body:
Nov-15-2017 11:57:06.070 +01:00 verbose [matrix-appservice-bridge] [-] POST http://localhost:8008/_matrix/media/v1/upload (@_webhook:localhost) Body: {"type":"Buffer","data":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,132
Nov-15-2017 11:57:06.104 +01:00 error [matrix-appservice-bridge] [-] POST http://localhost:8008/_matrix/media/v1/upload (@_webhook:localhost) HTTP 403 Error: "{\"errcode\":\"M_FORBIDDEN\",\"error\":\"Application service has not registered this user\"}"
I've tried out the webhooks with a couple of services I have and it seems that they use a bunch of different formats. Since you've been looking into Slack maybe you can explain?
Sonarr for example works OOTB.
Grafana sends something like this:
{
"attachments": [
{
"color": "#D63232",
"fallback": "[Alerting] Test notification",
"fields": [
{
"short": true,
"title": "High value",
"value": 100
},
{
"short": true,
"title": "Higher Value",
"value": 200
},
{
"short": false,
"title": "Error message",
"value": "This is only a test"
}
],
"footer": "Grafana v4.4.1",
"footer_icon": "https://grafana.com/assets/img/fav32.png",
"image_url": "http://grafana.org/assets/img/blog/mixed_styles.png",
"text": " Someone is testing the alert notification within grafana.",
"title": "[Alerting] Test notification",
"title_link": "https://example.com/",
"ts": 1505222577
}
],
"parse": "full",
"web_request": {
"attachments": [
],
"parse": "full"
}
}
sentry.io gives me this:
{
"payload": "{\"username\":\"Sentry\",\"icon_url\":\"http://myovchev.github.io/sentry-slack/images/logo32.png\",\"attachments\":[{\"color\":\"#f43f20\",\"fields\":[{\"short\":false,\"value\":\"raven.scripts.runner in main\",\"title\":\"Culprit\"},{\"short\":true,\"value\":\"My project\",\"title\":\"Project\"}],\"fallback\":\"[My project] This is an example Python exception\",\"title_link\":\"https://sentry.io/company/project/issues/123456789/?referrer=slack\",\"title\":\"This is an example Python exception\"}]}"
}
At 10:24 (+1) the bridge changed it's own avatar for no particular reason it seems. It crashed a few minutes earlier for seemingly unrelated reasons.
This is what Slack wants
{
"text": "*bold* `code` _italic_ ~strike~",
"username": "markdownbot",
"mrkdwn": true
}
This will use the mrkdwn
property if it exists, but otherwise assume format
as the default, ie:
{
"text": "*bold* `code` _italic_ ~strike~",
"username": "markdownbot",
"format": "markdown"
}
<@travis:t2l.io|TravisR>
Convert things like :smile:
to 😄 using Riot/Slack semantics.
Add a direction
to everything (or similar)
Webhook IDs are disappearing every time I restart the service.
Log displays the warning Using unknown data type INTEGER during database migration.
Loading config file /data/config.yaml
info [index] Preparing database...,
info [WebhookStore] Running migrations,
[INFO] Processed migration 20170708201820-create-bot-account-data-table,
[INFO] Processed migration 20170708235052-create-webhooks-table,
[WARN] Using unknown data type INTEGER,
[INFO] Processed migration 20170709024537-create-account-data-table,
[INFO] Processed migration 20170709024544-drop-bot-account-data,
[INFO] Done,
room-store.db and user-store.db files are created but empty (0kb).
20170709024537-create-account-data-table.js on line 19 I changed:
type: 'integer'
to
type: 'int'
(see https://github.com/db-migrate/shared/blob/8710b084b2b437a0bac3448eccd9d24ab08f08e1/data_type.js)
This removed the integer warning. *.db files are still empty and webhooks are lost after restart.
Would it be possible to use an existing user (i.e. a "bot" user) as the bridge?
My use case is that I have a user (say @Superbot:example.com) with several backends connected, like go-neb and hubby, and I'd like to have webhooks as well without adding another user to the room.
Actually it would be nice to have a fallback for non-Slack messages too! Because sometimes stripping tags generates a weird message :)
Hi,
I was able to install the appservice for my HS successfully. But I have some problems with notification from GitLab (Slack notifications).
I receive the notification but there are no usable links inside but in the source of the message in Riot side I see some weird stuff...
I wonder if you could help me.
Here the string I captured with tcpdump:
payload=%7B%22username%22%3A%22Gitlab%22%2C%22attachments%22%3A%5B%5D%2C%22fallback%22%3Anull%2C%22text%22%3A%22Jakab+Gipsz+%28jgipsz%29+closed+%5Cu003chttps%3A%2F%2Fexample.com%2Fadmin%2Fgitlab%2FProject1%2Fansible%2Fmerge_requests%2F179%7C%21179+*Test+webhook*%5Cu003e+in+%5Cu003chttps%3A%2F%2Fexample.com%2Fadmin%2Fgitlab%2FProject1%2Fansible%7CProject1%2Fansible%5Cu003e%3A+*Test+webhook*%22%7D
After urldecode:
payload={ "username":"Gitlab", "attachments":[], "fallback":null, "text":"Jakab Gipsz (jgipsz) closed \u003chttps://example.com/admin/gitlab/Project1/ansible/merge_requests/179|!179 *Test webhook*\u003e in \u003chttps://example.com/admin/gitlab/Project1/ansible|Project1/ansible\u003e: *Test webhook*"}
And the msg source from Riot:
{ "origin_server_ts": 1527690275010, "sender": "@_webhook__MzjJH38dhjksWeeScb_example_com_Gitlab:example.com", "event_id": "$1525678268297yHRBu:example.com", "unsigned": { "age": 216 }, "content": { "body": "", "msgtype": "m.text", "formatted_body": "Jakab Gipsz (jgipsz) closed <https: example.com=\"\" admin=\"\" gitlab=\"\" project1=\"\" ansible=\"\" merge_requests=\"\" 179|!179=\"\" *test=\"\" webhook*=\"\"> in <https: example.com=\"\" admin=\"\" gitlab=\"\" project1=\"\" ansible|project1=\"\" ansible=\"\">: *Test webhook*</https:></https:>", "format": "org.matrix.custom.html" }, "type": "m.room.message", "room_id": "!MzjJH38dhjksWeeScb:example.com" }
And all I can see in Riot client:
Jakab Gipsz (jgipsz) closed in: *Test webhook*
Without any useful links... :-o
I have a room where I got a webhook by posting "!webhook" after inviting the bridge. Works like a charm.
When a room admin later also writes "!webhook", he'll see a message:
I've sent you a private message with your hook information
In the private message there is a new URL anytime "!webhook" is written. The initial URL is still working (which is correct), but I'm wondering why a new URL is created every time. If a room has a webhook, the bridge should send the already existing webhook all the time instead of creating a new URL.
BTW: I did not test if the bridge answers the "!webhook" message to non-moderators or admins of the room. Normal members should not get any links where they can send messages via webhook IMHO.
Previously there was an assumption that the profile could be set async to the join so long as both completed before the message was sent. Changes in how the synapse workers actually work changes this assumption to no longer be accurate - we need to block on profile changes before sending a join.
whatever that happens to be: https://api.slack.com/messaging/attachments-to-blocks
The docker image will not start, mentioning the missing "appservice-registration-webhooks.yaml" file. There is no sample file in the github repository which I can modify, hence I'm stuck with that missing file.
Can this be uploaded in the repo, please?
Should somehow treat this as a different hook, possibly by using the raw name and not the converted name
Bot generate part of ulocalpart via display name..
But it will lead to some problem if display name container some non-English character some thing like
github 通知
=> github___
github 大小
=> github___
!webhook
It would be great (if it's possible) to be able to optionally label a webhook, at least when using the provisioning API, so that existing hooks can be easily managed/deleted when there are more than one for a given room.
E.g.:
PUT /api/v1/provision/{roomId}/hook?userId={userId}&label=buildsystem
PUT /api/v1/provision/{roomId}/hook?userId={userId}&label=systemhealth
GET /api/v1/provision/{roomId}/hooks?userId={userId}
=>
{
"success": true,
"results": [
{
"id": "some_long_string",
"url": "https://webhook.t2bot.io/api/v1/matrix/hook/some_long_string",
"userId": "@someuser:someserver.org",
"roomId": "!cURbafjkfsMDVwdRDQ:matrix.org",
"type": "incoming",
"label": "buildsystem"
},
{
"id": "another_long_string",
"url": "https://webhook.t2bot.io/api/v1/matrix/hook/another_long_string",
"userId": "@someuser:someserver.org",
"roomId": "!cURbafjkfsMDVwdRDQ:matrix.org",
"type": "incoming",
"label": "systemhealth"
}
]
}
With the above it would then be possible to manage/delete webhooks created for a given purpose without needing to record the "id" field elsewhere at creation time.
E.g. combinedHtml += "<blockquote data-mx-border-color='" + color + "'>";
Should be combinedHtml += "<blockquote data-mx-border-color=\"" + color + "\">";
This causes postprocess/upload_images.js to write content to matrix.event.formatted_body with nothing contained in any of the HTML tags, resulting in blank messages.
Replacing all '
with \"
in from_slack_attachments.js fixes.
Im trying to dockerize this project but I'm a bit at loss at how to deal with registration file generation. Right now my best bet is to do it in the image and have the user mount a dir to access it. Feels wrong but generating it outside of the container means depending on node which kinda defeats the purpose..
You got any ideas?
<!channel>
becomes @channel
<!channel|World>
becomes @channel
with display text World
Other commands:
!group
- alias for !channel
!here
!everyone
The bridge works nicely in rooms without encryption. But when I enable encryption in a room, I cannot start the webhooks bridge.
It would be nice to be able to send notices as well
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.