// This module is included in these assemblies:
// as_connecting-to-telegram.adoc

[id='add-telegram-connection-middle-finish_{context}']
= Adding a Telegram connection to send a message to a Telegram chat

In an integration, you can send a message to a Telegram chat in the 
middle of a flow or to finish a simple integration. To do this, add 
a Telegram connection to the middle of a flow or as a simple 
integration's finish connection. 

.Prerequisites

* You created a Telegram connection. 
* You are creating or editing a flow and {prodname} is prompting you
to add to the integration. Or, {prodname} is prompting you to choose a finish connection. 

.Procedure
. On the *Add to Integration* page, click the plus sign where you 
want to add the connection. Skip this step if {prodname} is
prompting you to choose the finish connection. 
. Click the Telegram connection that you want to add to the flow. 
. Select the *Send a Text Message* action. 
. In the *Chat Id* field, enter the ID for the Telegram chat that you are sending
a message to. 
+
If you leave this field blank, and if there is an earlier 
Telegram connection that receives messages, then {prodname} uses the
chat ID that is in an incoming message. 
+
To obtain the ID for a chat:  

.. In Telegram, add a bot to the chat that you want to send a message to. 
The BotFather response includes a bot access token.
.. Copy the access token to the clipboard.
.. In Telegram, send a message directly to that chat. 
Do not use the bot to send the message.  
.. Read messages that are sent to that chat by invoking a `curl` command 
in the following format. Replace `_bot-access-token_` with the access 
token in the clipboard. 
+
`curl \https://api.telegram.org/_bot-access-token_/getUpdates\?offset\=0`
+
The response is in JSON format. The JSON `chat` object contains the chat ID. 

. Click *Next* to add the connection to the flow. 
