# Telegram API Key Walkthrough

## Step 1: Create Your Telegram Bot

* Open Telegram and start a chat with **BotFather**.
* Type the command `/newbot` to create a new bot.
* Follow the prompts to:
  * Set a name for your bot.
  * Set a unique username (must end in `bot`).
* Once done, you’ll receive a **bot token** (e.g., `123456789:ABCdefGhIjKlmNoPQRstuVWXyz`).

More detailed tutorial here - [core.telegram.org/bots/tutorial](https://core.telegram.org/bots/tutorial)

Keep this token secure. You’ll use it later on aigent.run.

<figure><img src="/files/LOfbCKMRWry2gevtbkUv" alt=""><figcaption></figcaption></figure>

## Step 2: Add Bot Token to aigent.run

* Visit [aigent.run](https://aigent.run) and go to the **Configuration** tab.
* Paste your **bot token** into the **Bot Token** field.
* Click **Save**.
* Use the **Test Credentials** button to check that the bot is connected correctly.

<figure><img src="/files/YuZ7v4QFnpG4NG18Uv5U" alt=""><figcaption></figcaption></figure>

## Step 3: Add the Bot to a Telegram Group

* Create a new Telegram group or use one where you're already an admin.
* Add your newly created bot to the group.
* Once added, tap the group name → **Manage Group** → **Administrators**.
* Promote your bot to **Administrator** status.

<figure><img src="/files/FDJhGOhXmWB5zHiGvEK0" alt=""><figcaption></figcaption></figure>

## Step 4: Get the Group Chat ID

To get the chat ID you have to follow these steps:

* Add @myidbot to the group you want to enable the agent in, and make it an Admin.
* Contact the [@myidbot](https://t.me/myidbot) bot and send the `/getid` command to get your personal chat ID, or invite it into a group and use the `/getgroupid` command to get the group chat ID.
* To get the Thread ID, the easiest way is this: Post a message to that topic, then right-click on it and select `Copy Message Link`. Paste it on a notepad and notice that it has the following structure `https://t.me/c/XXXXXXXXXX/YY/ZZ`. The Thread ID is `YY` (integer).

<figure><img src="/files/vntUDHCYwjYEG3i9izAm" alt=""><figcaption></figcaption></figure>

## Step 5: Add the Chat ID to aigent.run

1. Go back to the **Configuration** tab on aigent.run.
2. Paste the **Chat ID** into the appropriate field.
3. Click **Send Test Message**.

If everything is set up correctly, you’ll receive a message in your Telegram group saying:

"This is a test message from your AIgent."

<figure><img src="/files/0mO1oTHnfWzHdv6enptG" alt=""><figcaption></figcaption></figure>

That’s it! Your Telegram bot is now ready to send messages through aigent.run.


---

# 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://docs.aigent.run/ai-agent-terminal/social-agents/telegram-api-key-walkthrough.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.
