AI Agent SDK Telegram plugin allows users to connect the agent to their Telegram bot with just a few lines of code.
This guide demonstrates how to build a Telegram bot that interacts with the Cronos network. The bot enables users to query blockchain information and execute transactions smoothly.
A video demo is available in .
Prerequisites
Python installed (version >= 3.12)
Get a Telegram Bot Token
Open Telegram and search for @BotFather.
Type /start and /newbot, then follow the prompts to name your bot (must end in bot, e.g., CryptoHelper).
After creation, @BotFather will give you a TOKEN (e.g., 7008008900:AAEKe6vIwM0gokw..), which should be safely kept.
Telegram Plugin
We need to add Telegram plugin when initializing the Agent:
import os
from crypto_com_agent_client import Agent
from dotenv import load_dotenv
load_dotenv()
# Initialize the agent with LLM and blockchain configurations
# Current chainID refers to Cronos zkEVM Testnet, optionally change it to other Cronos networks
agent = Agent.init(
llm_config={
"provider": "OpenAI",
"model": "gpt-4o-mini",
"provider-api-key": os.getenv("OPENAI_API_KEY"),
"temperature": "float-controlling-output-randomness",
},
blockchain_config={
"chainId": "240",
"explorer-api-key": os.getenv("EXPLORER_API_KEY"),
"private-key": os.getenv("PRIVATE_KEY"),
"sso-wallet-url": "your-sso-wallet-url",
},
plugins={
"instructions": "You are a humorous assistant that always includes a joke in your responses.",
"telegram": {"bot_token": os.getenv("TELEGRAM_BOT_TOKEN")},
},
)
agent.start_telegram()
import os
from crypto_com_agent_client import Agent
from dotenv import load_dotenv
load_dotenv()
# Initialize the agent with LLM and blockchain configurations
# Current chainID refers to Cronos zkEVM Testnet, optionally change it to other Cronos networks
agent = Agent.init(
llm_config={
"provider": "GoogleGenAI",
"model": "gemini-2.0-flash",
"provider-api-key": os.getenv("GEMINI_API_KEY"),
"temperature": "float-controlling-output-randomness",
},
blockchain_config={
"chainId": "240",
"explorer-api-key": os.getenv("EXPLORER_API_KEY"),
"private-key": os.getenv("PRIVATE_KEY"),
"sso-wallet-url": "your-sso-wallet-url",
},
plugins={
"instructions": "You are a humorous assistant that always includes a joke in your responses.",
"telegram": {"bot_token": os.getenv("TELEGRAM_BOT_TOKEN")},
},
)
agent.start_telegram()
Run everything
As shown in the example code, we start the Telegram bot by invoking the Agent's built-in function:
agent.start_telegram()
Once the bot is running, test it to ensure it’s working as expected:
Open Telegram and search for your bot using the bot name you set up with @BotFather.
Send a sample command or message, such as /start, to see if the bot responds.
Troubleshooting
If you encounter issues during setup or execution, follow these tips:
Check your API keys to ensure they are correctly set in the environment variables.
Review Telegram Bot API limitations to ensure compliance with rate limits and usage guidelines.
installed.
API Key for or
API Keys of AI provider, refer to the to see which providers are supported by the AI Agent SDK.