Inteygrate

Salesforce Telegram Integration - Code

Introduction

Muralidhar

Muralidhar

At inteygrate.com, I am trying out ways to integrate Salesforce to various other technologies.


salesforce-telegram telegram bot

Salesforce Telegram Integration - Code

Posted by Muralidhar on .
Featured

salesforce-telegram telegram bot

Salesforce Telegram Integration - Code

Posted by Muralidhar on .

In the previous article we saw a demo video of the 2-way integration between Salesforce and Telegram and a simple use case. In this article I will quickly show the configurations and Apex code to send messages from Salesforce to Telegram. In the next article we will discuss 2 different ways of achieving the other way round i.e processing messages from Telegram to Salesforce. So lets start!


Bot Creation in Telegram

  1. Open the Telegram App and Search for BotFather
  2. Enter command /start and /newbot
  3. After a series of straightforward question and answers you should be able a create a Bot and generate an access token. One such conversation is shown below:

Telegram Bot creation with BotFather for Salesforce Integration

Send Message to Telegram

Once the access token is generated, sending message from Salesforce is a simple Apex callout as shown below:

HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Type','application/x-www-form-urlencoded');
            payload = 'text=' + message +'&chat_id='+receiver_chatid;
req.setEndpoint('https://api.telegram.org/bot'+*access_token*+'/sendMessage');
  • message is the text you want to send to the Telegram Contact
  • receiver_chatid is numeric id (usually 7 digits) of the contact. In the use case we saw in the previous article we get this id when a Telegram user sends message to the Bot

Make sure you create a Remote Site Setting for the URL https://api.telegram.org

Muralidhar

Muralidhar

https://inteygrate.com

At inteygrate.com, I am trying out ways to integrate Salesforce to various other technologies.

View Comments...