Telegram Bot API
api.telegram.org · Communication
Build Telegram bots — send messages, photos, documents, polls, and keyboards. Handle user interactions, manage groups, and build inline experiences. Free, no cost per message.
Authentication
API Key
Free bot token from @BotFather on Telegram. Token is included in the URL: api.telegram.org/bot{TOKEN}/method.
Sample Requests
GET
Get bot info
Verify your token and get bot info.
https://api.telegram.org/botYOUR_TOKEN/getMe
Hover any highlighted part to learn what it does
curl -X GET "https://api.telegram.org/botYOUR_TOKEN/getMe"
import requests
response = requests.get(
"https://api.telegram.org/botYOUR_TOKEN/getMe",
)
print(response.json())const url = 'https://api.telegram.org/botYOUR_TOKEN/getMe'; const response = await fetch(url); const data = await response.json(); console.log(data);
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
targetURL := "https://api.telegram.org/botYOUR_TOKEN/getMe"
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.telegram.org/botYOUR_TOKEN/getMe")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.telegram.org/botYOUR_TOKEN/getMe";
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
POST
Send a message
Send a message to a chat.
https://api.telegram.org/botYOUR_TOKEN/sendMessage
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Content-Type | application/json |
Request Body — data you're sending
{
"text": "Hello from the Telegram Bot API!",
"chat_id": "CHAT_ID"
}
curl -X POST "https://api.telegram.org/botYOUR_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-H "Content-Type: application/json" \
-d '{"text":"Hello from the Telegram Bot API!","chat_id":"CHAT_ID"}'import requests
headers = {
"Content-Type": "application/json"
}
data = {
"text": "Hello from the Telegram Bot API!",
"chat_id": "CHAT_ID"
}
response = requests.post(
"https://api.telegram.org/botYOUR_TOKEN/sendMessage",
headers=headers,
json=data,
)
print(response.json())const url = 'https://api.telegram.org/botYOUR_TOKEN/sendMessage';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"text": "Hello from the Telegram Bot API!",
"chat_id": "CHAT_ID"
}),
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"bytes"
"encoding/json"
)
func main() {
targetURL := "https://api.telegram.org/botYOUR_TOKEN/sendMessage"
jsonData, _ := json.Marshal({"text":"Hello from the Telegram Bot API!","chat_id":"CHAT_ID"})
req, _ := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.telegram.org/botYOUR_TOKEN/sendMessage")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Content-Type"] = "application/json"
req.body = "{\"text\":\"Hello from the Telegram Bot API!\",\"chat_id\":\"CHAT_ID\"}"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.telegram.org/botYOUR_TOKEN/sendMessage";
$opts = ["http" => [
"method" => "POST",
"header" => implode("\r\n", [
"Content-Type: application/json",
"Content-Type: application/json"
]),
"content" => json_encode({"text":"Hello from the Telegram Bot API!","chat_id":"CHAT_ID"}),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Open Telegram and message @BotFather
- Send /newbot and follow prompts to get your token
- Token is embedded in the URL: /botYOUR_TOKEN/method
- Get your chat ID: message your bot, then GET /getUpdates to see the chat_id
- Webhook or polling (getUpdates) for receiving messages