Notifications
Telegram
Sending Telegram messages on the Stubber platform.
Telegram provides a powerful notification option for Stubber users in the form of a Telegram Bot.
Telegram has some key features and advantages over other notification platforms in Stubber, namely:
- Unlimited number of bots can be set up
- Bots can initiate conversations and send messages to users
- Bots are discoverable by Telegram users via search
- Ability to participate in and manage group chats
- Support for rich media formats (photos, videos, documents, etc.)
- Interactive elements like buttons and inline keyboards
How does a Telegram Bot work?
A Telegram Bot acts as a contact point between users and your Stubber templates.
You can have an unlimited number of bots set up and each bot can connect to a template on your Stubber profile. You can also have multiple bots connect to a single template should your use case require it.
For detailed instructions on how to get your first bot set up, take a look at this tutorial.
Inner workings
Telegram bots work through the Telegram Bot API. When a message is sent to a bot, it is routed through the Stubber platform, which processes the message and sends appropriate responses back through the bot.
Stubber has a default Telegram bot that will be used if you have not set up your own Telegram bot in Stubber Manage yet. To set up your own Telegram bot with your own branding, you can create a new bot using BotFather in Telegram and then register it in Stubber Manage.
Unlike some other messaging platforms, Telegram does not require template messages to initiate conversations. Your bot can send any message to users who have previously initiated a conversation with the bot.
Routing incoming Telegram messages
When messages are sent to a Telegram bot that has been configured on your Stubber profile, they need to be routed in some way. Stubber offers different mechanisms to route these incoming messages, providing a wide range of functionality.
Incoming messages are integrated into Stubber using a feedback action called _update_from_telegram
. This feedback action is triggered when a message is sent to a Telegram bot that is correctly configured on your Stubber profile.
See the Update From Telegram Feedback Action for more information on how to receive Telegram messages on the Stubber platform.
Stubsession
The most basic mechanism is the stubsession
. When you send a message to a Telegram bot, you can create a
stubsession
for that bot interaction. The stubsession
contains the user's chat_id
, and the Stub that the original message was sent from.
When that bot receives a message (incoming message), Stubber routes that message back to the Stub of the stubsession
via the feedback action, _update_from_telegram
.
See the stubsession concept for more information.
Incoming stubsession
messages will emit the following Heimdall event:
- mechanism:
evt
- path:
stubber.systems.notifications.telegram.incoming.{{bot_name}}.stubsession.{{stubsession_stubref}}
Next reply
In some scenarios, you want to obtain/steal a single reply from a user, without potentially overwriting their active
stubsession
. The nextreply
mechanism can be used for this.
Incoming nextreply
messages will emit the following Heimdall event:
- mechanism:
evt
- path:
stubber.systems.notifications.telegram.incoming.{{bot_name}}.nextreply.{{nextreply_stubref}}
See the parameters and Examples.
Specific reply
The specificreplyuuid
is another useful mechanism that can be used to route incoming messages. When the user specifically
replies to a message (using Telegram's reply functionality), Stubber will check if a
specificreplyuuid
was set on the outgoing message, and then emit on Heimdall
accordingly. This is useful for outgoing
messages where the user is likely to specifically reply.
Incoming specificreplyuuid
messages will emit the following Heimdall events:
General:
- mechanism:
cbh
- path:
stubber.systems.notifications.telegram.incoming.{{bot_name}}.specificreplyuuid.{{specificreplyuuid}}
Specific:
- mechanism:
cbh
- path:
stubber.systems.notifications.telegram.incoming.{{bot_name}}.from.{{from_chat_id}}.specificreplyuuid.{{specificreplyuuid}}
User Initiated Messages
A conversation can be initiated by the user instead of by Stubber (an org). For these cases, no stubsession
can exist yet, so these messages cannot be posted on stubs
via the _update_from_telegram
feedback action.
These incoming messages will emit the following Heimdall event:
- mechanism:
cbh
- path:
stubber.systems.notifications.telegram.incoming.{{bot_name}}.from.{{from_chat_id}}
Basic Usage
- Setup a notification in an action as seen below
Parameters
Everything inside platforms.telegram
should be considered parameters for this notification. There are top level
parameters that describe the message type and other general message behaviors, as well as message-type specific parameters.
This page focuses on the top level parameters, the nested parameters can be found in the message type specific pages below.
required string
message_type Indicates the type of message that is going to be sent. This also will determine what additional parameters should be included.
Available message types are:
- text - Simple text messages
- media - Photos, voice messages, videos, documents, etc.
- location - Geographic location
- contact - Contact cards
Default: null
required for text messages string
text The text content of the message when message_type is "text". Can include formatting using markdown.
Default: null
optional string
parse_mode Defines the formatting style of the text. Can be one of:
- "HTML" - Use HTML tags for formatting
- "MarkdownV2" - Use Telegram's MarkdownV2 syntax
- "Markdown" - Use Telegram's original Markdown syntax (deprecated)
Default: MarkdownV2
required for media messages object
media Contains the media files to be sent and associated options. Used when message_type is "media".
Show child attributes
required array
files An array of file objects or file UUIDs to send.
optional string
caption Text caption to accompany the media.
Example:
optional boolean
enable_lids This parameter can be set to true
to enable the lids feature for the outgoing Telegram message.
optional string
bot_name If you have multiple Telegram bots set up on your org, you can use this parameter to specify the bot to use for the outgoing message.
optional object
stubsession Contains the properties that relate to the handling of client's stubsession
. The stubsession
is what is used to
determine where a client's incoming Telegram message should go. If you set the stubsession
on an outgoing Telegram message,
all incoming replies for the duration of the stubsession
will be returned to the stub
the outgoing message was sent
from.
Default: null
optional integer
stubsession.set_new_with_timeout_hours Length in hours for the Telegram stubsession
to remain open.
Default: null
optional boolean
stubsession.cancel_current_existing_stubsession This can be set to true
to cancel the current stubsession
for a specific chat_id (client).
Default: false
optional integer
stubsession.set_nextreply_with_timeout_minutes This can be used to "steal" the stubsession
for a specific chat_id (client), but only for their next reply. After their
next reply, their stubsession
will return to what it was.
Default: false
optional string
stubsession.specificreply_uuid If this parameter is supplied, incoming replies from the client will not be posted to the stub
in their stubsession
.
This parameter makes it easy to run actions on any stub
in your org
for incoming messages, as opposed to specifically
on the stub
the message was sent from.
Incoming replies will emit on heimdall
on a specific path, determined by the specificreply_uuid
. You can then register
on this path to run a specific action on any stub
in your org
.
Default: null
optional string
stubsession.set_stubsession_stubref This parameter can be used to set the stubsession
to a specific stub
in your org
. This is useful when you want to route the next incoming messages to a specific stub
in your org
.
Setting this parameter will override the default behavior of the stubsession
being set to the stub
the message was sent from.
Default: null