Integracao completa com Telegram Bot API. Setup com BotFather, mensagens, webhooks, inline keyboards, grupos, canais. Boilerplates Node.js e Python.
When to Use This Skill
When the user mentions "telegram" or related topics
When the user mentions "bot telegram" or related topics
When the user mentions "telegram bot" or related topics
When the user mentions "api telegram" or related topics
When the user mentions "chatbot telegram" or related topics
When the user mentions "mensagem telegram" or related topics
Do Not Use This Skill When
The task is unrelated to telegram
A simpler, more specific tool can handle the request
The user needs general-purpose assistance without domain expertise
How It Works
Skill para implementar bots profissionais no Telegram usando a Bot API oficial. Suporta Node.js/TypeScript e Python.
Overview
A Telegram Bot API permite criar bots que interagem com usuarios via mensagens, comandos, inline keyboards, pagamentos e muito mais. Bots sao criados pelo @BotFather e autenticados via token unico.
Base URL:https://api.telegram.org/bot<TOKEN>/METHOD_NAMEMetodos HTTP: GET e POST
Formatos de parametros: query string, application/x-www-form-urlencoded, application/json, multipart/form-data (uploads)
Limite de arquivos: 50MB download, 20MB upload (via multipart), 50MB via URL
Portas suportadas para webhooks: 443, 80, 88, 8443
Pre-requisitos:
Conta no Telegram
Bot criado via @BotFather (fornece o token)
Token no formato: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
Se o usuario nao tem um bot criado, oriente a conversar com @BotFather no Telegram e enviar /newbot.
Decision Tree
O usuario precisa criar um bot?
├── SIM → Secao "Setup com BotFather" abaixo
└── NAO → Qual linguagem?
├── Node.js/TypeScript
└── Python
→ O que quer fazer?
├── Enviar mensagens → Secao "Tipos de Mensagem"
├── Receber mensagens → Secao "Receber Updates"
├── Teclados interativos → Secao "Keyboards"
├── Gerenciar grupos/canais → references/chat-management.md
├── Webhook setup → references/webhook-setup.md
├── Inline mode → references/advanced-features.md
├── Pagamentos → references/advanced-features.md
├── Bot de atendimento com IA → Secao "Automacao com IA"
└── Referencia completa da API → references/api-reference.md
Para iniciar um projeto do zero com boilerplate pronto:
// Instalar: npm install node-telegram-bot-api dotenv// Para TypeScript: npm install -D @types/node-telegram-bot-api typescriptimportTelegramBotfrom'node-telegram-bot-api';
import dotenv from'dotenv';
dotenv.config();
const bot = newTelegramBot(process.env.TELEGRAM_BOT_TOKEN!, { polling: true });
bot.onText(/\/start/, (msg) => {
bot.sendMessage(msg.chat.id, 'Ola! Eu sou seu bot. Como posso ajudar?');
});
bot.on('message', (msg) => {
if (msg.text && !msg.text.startsWith('/')) {
bot.sendMessage(msg.chat.id, `Voce disse: ${msg.text}`);
}
});
Python
## Instalar: Pip Install Python-Telegram-Bot Python-Dotenvimport os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
load_dotenv()
asyncdefstart(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text('Ola! Eu sou seu bot. Como posso ajudar?')
asyncdefecho(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(f'Voce disse: {update.message.text}')
app = Application.builder().token(os.getenv('TELEGRAM_BOT_TOKEN')).build()
app.add_handler(CommandHandler('start', start))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
app.run_polling()
Sem Biblioteca (Http Puro)
import requests
TOKEN = "SEU_TOKEN"
BASE = f"https://api.telegram.org/bot{TOKEN}"## Verificar Bot
r = requests.get(f"{BASE}/getMe")
print(r.json())
## Enviar Mensagem
r = requests.post(f"{BASE}/sendMessage", json={
"chat_id": "CHAT_ID",
"text": "Hello from pure HTTP!",
"parse_mode": "HTML"
})
print(r.json())
Tipos De Mensagem
O Telegram suporta diversos tipos de conteudo. Todos os metodos aceitam chat_id, reply_parameters (para responder), reply_markup (para keyboards), disable_notification e protect_content.