Documentation Index
Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
Use this file to discover all available pages before exploring further.
Build a Telegram bot with tools, memory, and voice note transcription.
Create the bot
Open Telegram and message @BotFather:
- Send
/newbot
- Choose a name and username
- Copy the bot token
Create the agent
import asyncio
import os
from definable.agent import Agent
from definable.agent.interface import TelegramInterface
from definable.memory import Memory, SQLiteStore
from definable.tool.decorator import tool
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"Sunny, 24C in {city}"
agent = Agent(
model="gpt-4o",
instructions="You are a helpful Telegram assistant with weather tools.",
tools=[get_weather],
memory=Memory(store=SQLiteStore("./telegram_memory.db")),
audio_transcriber=True, # Transcribe voice notes via Whisper
)
interface = TelegramInterface(
agent=agent,
bot_token=os.environ["TELEGRAM_BOT_TOKEN"],
)
asyncio.run(interface.serve_forever())
Set environment variables
export TELEGRAM_BOT_TOKEN="123456:ABC-DEF..."
export OPENAI_API_KEY="sk-..."
Run
Open Telegram, find your bot, and start chatting. The bot:
- Calls the weather tool when asked about weather
- Remembers conversations across messages
- Transcribes voice notes to text automatically
Production Deployment
For production, switch to webhook mode:
interface = TelegramInterface(
agent=agent,
bot_token=os.environ["TELEGRAM_BOT_TOKEN"],
mode="webhook",
webhook_url="https://your-domain.com/webhook/telegram",
webhook_secret=os.environ.get("WEBHOOK_SECRET"),
max_concurrent_requests=20,
)
See Telegram reference for all configuration options.