Skip to main content

Overview

Telegram tool allows you to send messages, photos, and documents via Telegram bots.

Installation

pip install "praisonai[tools]"

Environment Variables

export TELEGRAM_BOT_TOKEN=your_bot_token
export TELEGRAM_CHAT_ID=your_chat_id  # Optional default chat
Get your bot token from @BotFather.

Quick Start

from praisonai_tools import TelegramTool

# Initialize
telegram = TelegramTool()

# Send message
telegram.send_message("123456789", "Hello from PraisonAI!")

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import TelegramTool

agent = Agent(
    name="TelegramBot",
    instructions="You send notifications via Telegram.",
    tools=[TelegramTool()]
)

response = agent.chat("Send a message to chat 123456789 saying hello")
print(response)

Available Methods

send_message(chat_id, text)

Send a text message.
from praisonai_tools import TelegramTool

telegram = TelegramTool()
telegram.send_message("123456789", "Hello!")

send_photo(chat_id, photo_url, caption=None)

Send a photo.
telegram.send_photo("123456789", "https://example.com/image.jpg", "Check this out!")

Common Errors

ErrorCauseSolution
TELEGRAM_BOT_TOKEN not configuredMissing tokenSet environment variable
chat not foundInvalid chat IDCheck chat ID
bot was blockedUser blocked botUser must unblock