For arlanix/notification 1.1.0
Telegram, Slack, Discord and Teams
The modules arlanix/module-notification-telegram, arlanix/module-notification-slack, arlanix/module-notification-discord and arlanix/module-notification-teams add Telegram, Slack, Discord and Microsoft Teams to a subscription's Delivered by field. Each module is optional. WhatsApp has its own page.
Each module posts over HTTPS with Guzzle, which magento/framework already requires. The store's server must be able to reach the following hosts:
| Protocol | Host |
|---|---|
| Telegram | api.telegram.org:443, or the Bot API server you set |
| Slack | hooks.slack.com:443 (hooks.slack-gov.com for GovSlack) |
| Discord | discord.com:443 |
| Microsoft Teams | The workflow host on port 443: *.environment.api.powerplatform.com (current) or *.logic.azure.com (older flows) |
If the store cannot reach a host, every delivery fails with a message such as No answer from api.telegram.org: …. The message names the host, but never the full URL, because the URL contains the token or the webhook.
Telegram
You set the store's bot in Stores > Configuration > Arlanix > Notifications > Telegram, in the default scope. To create a bot with @BotFather, see the manual.
The group has the following settings:
| Path | Admin field | Default | Notes |
|---|---|---|---|
arlanix_notification/telegram/bot_token |
Bot token | Stored encrypted. Marked as sensitive, so app:config:dump does not export it. |
|
arlanix_notification/telegram/api_url |
Bot API server | https://api.telegram.org |
Your own Bot API server (opens in a new tab), or a relay where Telegram is blocked. |
To set the token from the command line, run the following command:
bin/magento config:set arlanix_notification/telegram/bot_token '123456789:AAE…'
config:set stores the token encrypted, as the admin does. With --lock-env, it writes the token to app/etc/env.php, also encrypted. If you write the token into env.php by hand, encrypt it too, because the configuration decrypts the value when it reads it.
The Telegram module works as follows:
- A subscription's own bot. A subscription can post as a different bot. That bot's token is a secret of the subscription. It is stored in
arlanix_notification_subscription.secrets, encrypted with the store's key, and it is never sent back to the form. If you switch the subscription back to the store's bot, the token is deleted when you save. - Find chats. This button calls
getUpdatesand does not confirm the updates. So any other tool that reads the bot's updates still gets them. If the bot has a webhook set, Telegram answers Conflict. In that case, type the chat id by hand. - Messages. The module sends each message with
sendMessagein HTML, with link previews turned off. A message is cut to 4,000 characters. A digest that is too long shows the messages that fit and ends with … and N more: see the Message Log. When Telegram refuses a message, the delivery stores Telegram's own words and what to do. If Telegram returnsmigrate_to_chat_id, the message gives the group's new chat id.
Slack
Slack needs no setup in the configuration. Each subscription has its own incoming webhook. To create one, see the manual.
The Slack module works as follows:
- The webhook is a secret of the subscription. It is stored encrypted in
arlanix_notification_subscription.secrets. It is never sent back to the form, and it is never shown in a grid or the log. The subscription's address is the SHA-256 hash of the webhook. A topic accepts one subscription per address, so the same webhook cannot be added to a topic twice. - Only webhooks that start with
https://hooks.slack.com/services/(or the GovSlack equivalent) are accepted. A workflow trigger URL expects a different payload, so it is not accepted. - Messages. The module posts
{"text": …}in Slack's mrkdwn format, with link unfurling turned off. A message is cut to 12,000 characters. A long digest is cut in the same way as in Telegram. Slack answers a webhook in plain words, such asno_service. The delivery stores this answer as it is, together with what to do.
Discord
Discord also needs no setup in the configuration. Each subscription has its channel's webhook. To create one, see the manual.
The Discord module works as follows:
- The webhook is a secret of the subscription and is stored in the same way as a Slack webhook.
- The grid shows the subscription's Channel. If no channel is entered, the grid shows the webhook's id. The id is the number in the webhook URL. The id is not secret, but the token after it is. A Slack subscription without a channel also shows its webhook's id.
- The module accepts webhooks in the form
https://discord.com/api/webhooks/<id>/<token>. It also acceptsdiscordapp.com, theptb.andcanary.hosts, and URLs with or without an API version. - Messages. The module posts each message as one embed. The subject is the embed's title, cut to 256 characters. The body is its description, cut to 4,000 characters. A long digest is cut in the same way as in Telegram. The severity sets the embed's colour.
allowed_mentionsis empty, so@everyonein a message does not notify anyone. - Discord answers
204on success. When Discord refuses a message, the delivery stores themessagefield of Discord's JSON answer, together with what to do.
Microsoft Teams
Microsoft Teams needs no setup in the configuration. Each subscription has its workflow URL. To make a workflow, see the manual.
The Teams module works as follows:
- The workflow URL is a secret of the subscription, stored in the same way as a Slack webhook. Its secret path is
endpoint/teams_workflow_url, and the subscription's address is its SHA-256 hash. - The grid and the Message Log show Channel (
endpoint/teams_channel), or Microsoft Teams workflow when it is blank. They never show the workflow URL. - The URL must use HTTPS, a host ending in
.environment.api.powerplatform.com(current Workflows) or.logic.azure.com(older flows), and a path containing/workflows/. A username or password in the URL is refused. Office 365 connector webhooks are retired; use the link from a workflow made from the Workflows template Send webhook alerts to a channel. - Messages. Each delivery posts one Adaptive Card 1.4 inside a
messageenvelope'sattachments. The subject is cut to 256 characters, bold and coloured by severity:attention(red) for error,warning(amber) for warning,defaultfor info. The subject and body useRichTextBlockwithTextRun. The body is plain text: links and markdown in event data appear as text, never as links. The formatter's text budget is 12,000 characters, including the subject. A digest holds up to 25 different messages; a long digest ends with … and N more: see the Message Log. - Teams normally answers
202when the workflow accepts the request. This confirms acceptance by the workflow; check the channel for the card. The protocol accepts any successful HTTP status. For failures, it stores Teams' JSONerror.message, with tags stripped, whitespace collapsed and echoed URL secrets redacted, cut to 200 characters. HTTP 401, 403 and 404 instead show the instruction to copy the workflow URL again. See When Teams refuses.
When a service asks to wait
Telegram, Slack, Discord and Teams can answer 429 when too many messages are sent at once. The delivery then waits for the time the service asks for:
- Telegram:
parameters.retry_afterin the answer. - Slack: the
Retry-Afterheader. - Discord and Microsoft Teams: the
Retry-Afterheader, orretry_afterin the JSON answer.
The wait is at most one hour. If the service does not say how long to wait, the delivery waits one minute.
During the first day after the message was published, a wait does not use up one of the delivery's attempts. After the first day, each wait uses up one attempt. So if a service keeps asking to wait, the delivery fails in the end.
Check them
To check any of the four, use Send test message on a subscription. It shows what Telegram, Slack, Discord or Microsoft Teams answered.
To check from the command line, publish to a topic that has 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