Bot API · Guias
Um bot em Python em 10 minutos
Um bot aiogram 3 completo para o Orbeo: responde a /start, formata texto, mostra botões, trata cliques e repete todo o resto. Se você já escreveu um bot para o Telegram, é o mesmo código com uma linha diferente.
1. Obter um token
- Instale o Orbeo e abra Configurações → Meus bots → Criar bot.
- Escolha um identificador que termine em
bot, por exemplohello_bot. - Copie o token — ele aparece só uma vez. Se perdê-lo, gere um novo; o antigo deixa de funcionar.
2. Instalar o aiogram
pip install aiogramO aiogram 3 precisa do Python 3.9 ou mais recente.
3. O bot
import asyncio
from aiogram import Bot, Dispatcher, F
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.client.telegram import TelegramAPIServer
from aiogram.filters import CommandStart
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
TOKEN = "123:yourtoken" # Orbeo: Settings -> My bots
bot = Bot(TOKEN, session=AiohttpSession(
api=TelegramAPIServer.from_base("https://orbeo.me/botapi")))
dp = Dispatcher()
@dp.message(CommandStart())
async def start(message: Message):
kb = InlineKeyboardMarkup(inline_keyboard=[[
InlineKeyboardButton(text="👍", callback_data="like"),
InlineKeyboardButton(text="Orbeo", url="https://orbeo.me"),
]])
await message.answer("<b>Hi!</b> Send me anything.", parse_mode="HTML", reply_markup=kb)
@dp.callback_query(F.data == "like")
async def like(call: CallbackQuery):
await call.answer("Thanks!")
@dp.message()
async def echo(message: Message):
await message.copy_to(message.chat.id)
asyncio.run(dp.start_polling(bot))A única parte específica do Orbeo é a sessão TelegramAPIServer.from_base("https://orbeo.me/botapi"). Todo o resto é aiogram comum.
4. Executar
python bot.pyEncontre seu bot na busca do Orbeo pelo identificador e envie /start — chegam a saudação e dois botões. O botão 👍 mostra um aviso curto «Thanks!».
Outras bibliotecas
python-telegram-bot 21+:
app = (Application.builder().token(TOKEN)
.base_url("https://orbeo.me/botapi/bot")
.base_file_url("https://orbeo.me/botapi/file/bot").build())Telegraf (Node.js) — a barra final é obrigatória:
new Telegraf(TOKEN, { telegram: { apiRoot: 'https://orbeo.me/botapi/' } });
Próximos passos
- Publicar num canal — veja publicação automática num canal.
- Rodar sem polling — veja webhooks.
- Já tem um bot no Telegram — veja migrar um bot do Telegram.
- Todos os métodos e limites — referência da Bot API.