Notifications via Telegram allow you to send clients information about crediting a payment, opening a service, answering a request, etc. Read more in Notification types.
This article describes how to connect and configure BILLmanager client notifications via a Telegram bot.
Configuration on Telegram side
Create a Telegram bot. To do this:
- Follow the link https://t.me/BotFather or use the search in Telegram to find @BotFather.
- Start the bot with the /start command.
- Create your own bot with the /newbot command. Create the name for the bot and its user.
- Save the bot name and token from the last message.
Configuration on BILLmanager side
Message gateway
- Enter Integration → Mail gateways → Add button.
- Select Telegram.
- Select the Provider to which Telegram notifications will be linked.
- Enable the Activate after creation option.
- Enter the Bot name in Telegram.
- Specify the Token you saved when creating the bot.
- Enter an address of the form
{BILLmanagerURL}/mancgi/telegram_webhook
in the Link for Webhook field to receive confirmations from Telegram. Telegram will send webhooks to this address indicating that the client and the bot are connected. You can leave the field blank. In this case, the address of the server with BILLmanager will be used. - Select message Layout from the Telegram bot:
- HTML;
- Markdown;
- MarkdownV2.
- Press Finish.
Message templates
Set up message templates for Telegram notifications:
- Enter Settings → Message templates → Messages for messengers.
- Fill in the required templates using the markup you selected in the settings. By default, the templates are not filled in. You can use the same variables to create messages as you do to create email notifications.
Example of a payment receipt notice
<% function EscapeForMarkdown(data) { %>
<% if (!data || data == '') { return; }%>
<% return data.replace(/[_*[\]()~'>#+\-=|{}.!\\]/g, "\\$&") %>
<% } %>
*Your payment has been credited*
Hello, *_<%= EscapeForMarkdown(user.realname) %>_*\!
This is to inform you that payment has been credited to account No *<%= payment.number %>* in the amount of *<%= EscapeForMarkdown(payment.paymethodamount) %> <%= payment.currency.iso %>*\.
Your current account balance is *<%= EscapeForMarkdown(subaccount.balance) %> <%= currency.iso %>*\.
Logging
Log of interaction between Telegram and the billing platform is recorded in file /usr/local/mgr5/var/gwtelegram.log.
Connecting Telegram notifications on the client side
The client can choose one or more notification channels in the client area. To receive notifications via Telegram, the client needs to take the following actions:
- In the Client area, go to the Profile settings → Notifications settings menu.
- Enable the required notifications in the messenger column.
- In the Telegram field, enter his/her Telegram username without @.
- Press Save.
- Go to Telegram and write to the bot. After that, BILLmanager connects the bot and the user, and the client can receive all the necessary notifications in the messenger.