Skip to content
English
  • There are no suggestions because the search field is empty.

Telegram API Integration Guide

Overview

Telegram API integration allows the system to send messages and supported media such as reports and notification to a Telegram user through a Telegram Bot.

The integration requires two mandatory values:

  • BOT HTTP Token – Required from the sender/bot.
  • Chat ID – Required from the receiver.

Inputs required from the sender :

BOT Http Token. (Mandatory)

How to acquire BOT Http Token?

- Download and Install Telegram App on your phone.

- Now set up username and profile info.

- Go to the Search Bar and search for ‘@BotFather’.

- Select the first option with verification blue tick.

- Click on ‘Start’ to initiate the conversation. As soon as you click on start,

Telegram will provide you many options regarding the creation of your bot.

- Send /newbot in this chat

- Set up a name for the newly created bot and voila off you go. A Sender Bot is created.

- As soon as you create a new Bot, Telegram will provide you with a http token that is to be used in the API.

Inputs required from receiver :

chatId. (Mandatory)

How to acquire chatId?

- Download and install the Telegram App on your phone.

- Setup user Profile

- Go to the search bar and search for ‘@RawDataBot’.

- Select the first option and click on Start.

- As soon as you click on Start, Telegram will send you a message in which you will find your chatId.

Note:
- Until and unless the receiver finds the sender Bot account and starts
the conversation (just by clicking on Start button) with the sender bot
account chat. Sender will not be able to send any message.
- One to One messaging will be done. No group/channel or broadcast
message is possible here.

Curl request to send a simple message :

curl --location --request GET 'https://api.telegram.org/bot5618630536:AAFL6k-
yBxmp27NqWH1NQ96bew9m7Y6h1nQ/sendMessage?chat_id=1210024099&text=hello'

Curl request to send a document :

curl --location --request POST 'https://api.telegram.org/bot5618630536:AAFL6k-
yBxmp27NqWH1NQ96bew9m7Y6h1nQ/sendDocument?chat_id=5726722042&caption=Travel Summary' \
--header 'Content-Type: multipart/form-data' \
--form 'document=@"/home/uffizio/Downloads/VEHICLES RUNNING WITHOUT TOKEN (FREE OF COST).xlsx"'

Curl Request to send a photo :

curl --location --request POST 'https://api.telegram.org/bot5618630536:AAFL6k-
yBxmp27NqWH1NQ96bew9m7Y6h1nQ/sendPhoto?chat_id=5726722042' \
--header 'Content-Type: multipart/form-data' \
--form 'document=@"/home/uffizio/Downloads/image.png"'

Sample Java Code to call to develop API using JAVA and okHttpClient :

OkHttpClient client = new OkHttpClient().newBuilder()

.build();

MediaType mediaType = MediaType.parse("multipart/form-data");

RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)

.addFormDataPart("document","VEHICLES RUNNING WITHOUT TOKEN (FREE OF COST).xlsx",

RequestBody.create(MediaType.parse("application/octet-stream"),

new File("/home/uffizio/Downloads/VEHICLES RUNNING WITHOUT TOKEN (FREE OF COST).xlsx")))

.build();

Request request = new Request.Builder()

.url("https://api.telegram.org/bot5618630536:AAFL6k-

yBxmp27NqWH1NQ96bew9m7Y6h1nQ/sendDocument?chat_id=5726722042")

.method("POST", body)

.addHeader("Content-Type", "multipart/form-data")

.build();

Response response = client.newCall(request).execute();