Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes |
matrix [2019/06/05 10:36] – [Quaternion] simon | matrix [2019/06/05 10:38] – simon |
---|
===== Bots ===== | ===== Bots ===== |
==== Webhook et Matrix ==== | ==== Webhook et Matrix ==== |
Je cherchais à envoyer des notifications sur mon compte Matrix via un webhook. J'ai trouvé une [[https://github.com/42wim/matterbridge/issues/553#issuecomment-435947716|issue Github]] qui en parle et qui propose d'utiliser [[https://t2bot.io/webhooks/|t2bot.io]] : | Je cherchais à envoyer des notifications sur mon compte Matrix via un webhook. J'ai trouvé une [[https://github.com/42wim/matterbridge/issues/553#issuecomment-435947716|issue Github]] qui en parle et qui propose d'utiliser [[https://t2bot.io/webhooks/|t2bot.io]]. |
| |
| On invite le bot "@_webhook:t2bot.io" : |
| |
{{ :20190506-matrix-webhook-bot.png?400 |}} | {{ :20190506-matrix-webhook-bot.png?400 |}} |
| |
{{ :20190506-matrix-webhook.png?400 |}} | |
| |
{{ :capture_du_2019-06-05_12-26-31-webhook-matrix.png?400 |}} | {{ :capture_du_2019-06-05_12-26-31-webhook-matrix.png?400 |}} |
| |
| Quand on envoie "!webhook" au bot, il répond : |
| <code> |
| Here's your webhook url for !igamGYevYexvuPZNhX:duniter.be: https://webhooks.t2bot.io/api/v1/matrix/hook/hjyErSrz7NxvRM71U5PGfojarGNLZcNQmO5Tj2NM9yszoRd9trk7TQObfhUgMARD |
| To send a message, POST the following JSON to that URL: |
| { |
| "text": "Hello world!", |
| "format": "plain", |
| "displayName": "My Cool Webhook", |
| "avatarUrl": "http://i.imgur.com/IDOBtEJ.png" |
| } |
| </code> |
| |
| On peut utiliser [[curl]] pour envoyer un texte sur l'adresse donnée : |
| |
| <code bash> |
| $ curl -d '{"text": "Webhook in Matrix from Terminal", "format": "plain", "displayName": "Bot", "avatarUrl": "http://i.imgur.com/IDOBtEJ.png"}' -H "Content-Type: application/json" -X POST https://webhooks.t2bot.io/api/v1/matrix/hook/hjyErSrz7NxvRM71U5PGfojarGNLZcNQmO5Tj2NM9yszoRd9trk7TQObfhUgMARD |
| {"success":true,"queued":true} |
| </code> |
| |
| Résultat : |
| |
{{ :capture_du_2019-06-05_12-29-27-webhook-matrix.png?400 |}} | {{ :capture_du_2019-06-05_12-29-27-webhook-matrix.png?400 |}} |