# Telegram Plugin

### Introduction

The Crypto.com 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.&#x20;

A video demo is available in the [Crypto.com AI Agent SDK X post](https://x.com/cryptocom_agent/status/1901907004140192067).

### Prerequisites

* [Crypto.com AI Agent SDK](https://pypi.org/project/crypto-com-ai-agent-client/) installed.
* Python installed (version >= 3.12).
* API Key for Crypto.com Developer Platform, [click here to learn how to obtain your Crypto.com Developer Platform API key](/crypto.com-developer-platform/developer-platform-dashboard.md).
* API Keys of AI provider, refer to the [Dynamic AI Model Manager ](/crypto.com-ai-agent-sdk/core-concepts-overview/dynamic-ai-model-manager.md)to see which providers are supported by the AI Agent SDK.
* Required account: [Telegram Bot Token](https://core.telegram.org/bots#how-do-i-create-a-bot).&#x20;

### 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:&#x20;

{% tabs %}
{% tab title="OpenAI as Provider" %}

```python
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",
       "transfer-limit": -1,  # -1 means no limit (unlimited), 0 disables transfers completely, any positive number (e.g. 5) allows exactly that transfer amount
   },
   blockchain_config={
       "api-key": os.getenv("DEVELOPER_PLATFORM_API_KEY"),
       "private-key": os.getenv("PRIVATE_KEY"),
       "sso-wallet-url": "your-sso-wallet-url",
       "timeout": "timeout-in-seconds-for-API-calls-default-20s")
   },
   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()
```

{% endtab %}

{% tab title="Gemini as Provider" %}

```python
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={
      "api-key": os.getenv("DEVELOPER_PLATFORM_API_KEY"),
      "private-key": os.getenv("PRIVATE_KEY"),
      "sso-wallet-url": "your-sso-wallet-url",
      "timeout": "timeout-in-seconds-for-API-calls-default-20s")
  },
  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()

```

{% endtab %}
{% endtabs %}

### 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ai-agent-sdk-docs.crypto.com/crypto.com-ai-agent-sdk/core-concepts-overview/plugins/messaging-platform-plugins/telegram-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
