# Connect Telegram or Discord

Enable your agent to interact on messaging platforms.

## Overview

Your agent can:

* Respond to direct messages
* Participate in group chats
* Send notifications
* Execute commands

## Telegram Setup

### Step 1: Create Bot with BotFather

1. Open Telegram and message [@BotFather](https://t.me/botfather)
2. Send `/newbot` command
3. BotFather will ask for a **name**:
   * This is the display name (can have spaces)
   * Example: `My AGOS Agent`
4. Then choose a **username**:
   * Must be unique and end in `bot`
   * Example: `myagosagent_bot`
5. ✅ **Done!** BotFather will reply with your token:

   ```
   123456789:ABCdefGHIjklMNOpqrSTUvwxyz
   ```

**⚠️ Important:** Copy and save this token immediately. You won't see it again!

If you lose it, message BotFather `/mybots` → Select your bot → **API Token** to regenerate.

### Step 2: Add Token to AGOS Cloud

**Option A: During Agent Creation**

* Paste your Telegram token in the "Telegram Bot Token" field

**Option B: After Deployment**

1. Open your agent's Dashboard
2. Go to **Channels** tab
3. Click **"Add Telegram"**
4. Paste your bot token
5. Click **"Save"**

Your agent will connect to Telegram within seconds.

### Step 3: Start Conversation

1. Search for your bot on Telegram (by the username you created, e.g., `@myagosagent_bot`)
2. Click **"Start"** button or send `/start`
3. Your agent will respond with a greeting!

**Test it:** Send a message like "Hello" or "What can you do?"

### Step 4: Add to Groups (Optional)

1. Open your Telegram group
2. Click group name → **"Add Member"**
3. Search for your bot's username
4. Click **"Add"**
5. (Optional) Make bot an **admin** for full functionality:
   * Group Settings → Administrators → Add Admin
   * Select your bot
   * Enable permissions: Delete messages, Pin messages, etc.
6. Mention bot with `@botname` to interact in the group

## Discord Setup

### Step 1: Create Discord Application

1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Click **"New Application"** (top right)
3. Enter a **name** for your bot
4. Click **"Create"**

### Step 2: Get Bot Token

1. In the left sidebar, click **"Bot"**
2. Click **"Add Bot"** → **"Yes, do it!"**
3. Under **TOKEN**, click **"Reset Token"** (or **"Copy"** if already exists)
4. ✅ **Copy the token** - looks like:

   ```
   MTk4NjIyNDgzNDc3MDk4MzA4.GH1JkX.xxxxxx
   ```

**⚠️ Important:** This token is only shown once. Save it securely!

If lost: Go to Bot section → **Reset Token** to generate a new one.

### Step 3: Generate Invite URL

1. In Developer Portal, click **"OAuth2"** in left sidebar
2. Click **"URL Generator"**
3. Under **SCOPES**, select:
   * ☑️ `bot`
   * ☑️ `applications.commands` (for slash commands)
4. Under **BOT PERMISSIONS**, select:
   * ☑️ **Send Messages**
   * ☑️ **Read Message History**
   * ☑️ **Add Reactions**
   * ☑️ **Embed Links**
   * ☑️ **Attach Files** (optional)
   * ☑️ **Use External Emojis** (optional)
5. Copy the generated URL at the bottom

### Step 4: Invite Bot to Server

1. Paste the OAuth URL in your browser
2. Select your Discord server from the dropdown
3. Click **"Authorize"**
4. Complete the CAPTCHA if prompted
5. ✅ Bot will appear in your server's member list

### Step 5: Add Token to AGOS Cloud

**Option A: During Agent Creation**

* Paste the Discord token in the "Discord Bot Token" field

**Option B: After Deployment**

1. Open your agent's Dashboard
2. Go to **Channels** tab
3. Click **"Add Discord"**
4. Paste your bot token
5. Click **"Save"**

Your agent will connect to Discord within seconds.

## Testing Your Connection

### Telegram

```
Send: /start
Expected: Agent responds with greeting
```

### Discord

```
Type: @botname hello
Expected: Agent responds in channel
```

## Multiple Platforms

Your agent can connect to **both** simultaneously:

* Telegram for mobile/chat
* Discord for communities/servers

Configure each separately in Channels settings.

## Troubleshooting

### Bot Not Responding

* Verify token is correct
* Check agent is running
* Look at agent logs for errors
* Ensure bot has necessary permissions

### Token Errors

* Don't include "Bot " prefix (just the token)
* Tokens are case-sensitive
* Generate new token if leaked

### Rate Limits

* Don't send too many messages quickly
* Respect platform rate limits
* Check agent logs for 429 errors

## Security Notes

⚠️ **Keep tokens secret** - Anyone with token can control your bot

⚠️ **Rotate if leaked** - Generate new token in BotFather/Dev Portal

⚠️ **Minimal permissions** - Only grant necessary permissions

## Next Steps

→ [Access Agent Dashboard](/agos/agos-cloud/quickstart/access-dashboard.md) to start interacting


---

# 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://agos.gitbook.io/agos/agos-cloud/quickstart/connect-messaging.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.
