For arlanix/notification 1.0.0
Telegram, Slack and Discord
arlanix/module-notification-telegram, arlanix/module-notification-slack and arlanix/module-notification-discord add Telegram, Slack and Discord to a subscription's Delivered by. Each is optional, and each posts over HTTPS with Guzzle, which magento/framework already requires, so the store's server must reach them:
| Protocol | Reaches |
|---|---|
| Telegram | api.telegram.org:443, or the Bot API server set |
| Slack | hooks.slack.com:443 (hooks.slack-gov.com for GovSlack) |
| Discord | discord.com:443 |
A store that cannot is told on every delivery: No answer from api.telegram.org: …, with the host and never the URL, which holds the token or the webhook.
Telegram
The store's bot is set in Stores > Configuration > Arlanix > Notifications > Telegram, default scope; making one with @BotFather is in the manual.
| Path | Admin field | Default | |
|---|---|---|---|
arlanix_notification/telegram/bot_token |
Bot token | Encrypted, and sensitive: app:config:dump leaves it out. |
|
arlanix_notification/telegram/api_url |
Bot API server | https://api.telegram.org |
A Bot API server (opens in a new tab) of your own, or a relay where Telegram is blocked. |
bin/magento config:set arlanix_notification/telegram/bot_token '123456789:AAE…'
config:set stores it encrypted, as the admin does; with --lock-env it goes into app/etc/env.php, encrypted the same way. A token written into env.php by hand must be encrypted too: the configuration decrypts it as it reads it.
- A subscription's own bot. A subscription may post as another bot: its token is the subscription's secret, in
arlanix_notification_subscription.secrets, encrypted with the store's key, never sent back to the form. Going back to the store's bot drops it on save. - Find chats calls
getUpdatesand leaves the updates unconfirmed, so whatever else reads them still does. A bot with a webhook set cannot be asked: Telegram answers Conflict, and the chat is typed instead. - Messages are
sendMessagein HTML, link previews off, cut to 4,000 characters: a digest shows the messages that fit and ends in … and N more: see the Message Log. Telegram's refusals are stored as it words them, with what to do; amigrate_to_chat_idnames the group's new id.
Slack
Nothing to set up in the configuration: each subscription has its own incoming webhook, made as the manual says.
- The webhook is the subscription's secret, in
arlanix_notification_subscription.secrets, encrypted, never sent back to the form or shown in a grid or the log. The subscription's address, which makes a topic take a webhook once, is its SHA-256 hash. - Only
https://hooks.slack.com/services/…(or GovSlack's) is taken: a workflow trigger URL takes another payload. - Messages are posted as
{"text": …}in mrkdwn, unfurling off, cut to 12,000 characters, a digest as Telegram's is. Slack answers a webhook in plain words, such asno_service, stored as it says them, with what to do.
Discord
Nothing to set up in the configuration either: each subscription has its channel's webhook, made as the manual says.
- The webhook is the subscription's secret, kept as Slack's is. The grid shows the subscription's Channel, or, with none entered, the webhook's id, the number in its URL, which is no secret: the token after it is. A Slack subscription without a channel shows its webhook's id the same way.
https://discord.com/api/webhooks/<id>/<token>is taken, ondiscordapp.comand theptb.andcanary.hosts too, with or without an API version.- Messages are posted as one embed: the subject as its title, cut to 256 characters, the body as its description, cut to 4,000, a digest as Telegram's is, and the severity as its colour.
allowed_mentionsparses nothing, so@everyonein a message pings nobody. Discord answers204; a refusal is its JSON'smessage, stored with what to do.
When one asks to wait
After a 429, the delivery waits as long as Telegram's parameters.retry_after says (Slack: the Retry-After header; Discord: that header, or its JSON's retry_after), an hour at most, a minute when it says nothing; during the first day after the message was published the attempt does not count, and after it a wait spends one, so a service that never stops asking fails the delivery in the end.
Checking them
A subscription's Send test message is the check, for any of them: it says what Telegram, Slack or Discord answered. From the command line, publish to a topic with such a subscription and run the consumer:
bin/magento arlanix:notification:publish "Store health" "Telegram check" --severity=info
bin/magento queue:consumers:start arlanix_notification_deliver --max-messages=10