---
title: "在 Telegram 机器人中集成广告"
description: "如何在 Telegram 机器人中请求并展示 AdsGram 广告：API 请求格式、响应字段，以及正确发送带防转发保护的消息。"
---

# 将广告集成到您的 Telegram 机器人
在您的广告模块创建并通过审核后，您就可以开始在您的 Telegram 机器人中展示广告了。

## Step 1 — API 请求
**发送 GET 请求至：**\
https://api.adsgram.ai/advbot?tgid={TELEGRAM_USER_ID}&blockid={BLOCK_ID}&language={LANGUAGE}&token={your_token}

**参数说明：**
- `tgid` — Telegram 用户 ID
- `blockid` —  广告区块 ID（后台获取）
- `language` — 广告所需语言
- `token` — 与您的账户绑定的唯一令牌，可在 AdsGram 控制台获取（可重新生成）。\
   获取token方式：进入右上角个人资料，点击按钮 <img src="../../images/icons/copy.png" alt="Copy" width="18" style="display: inline" />.

   ![Copy token](./images/copy_token.webp =300x){zoom-forbidden}

> [!IMPORTANT] 重要提示
> 仅使用 blockid 的数字部分，不要包含前缀 `bot-`。

## Step 2 — 处理 API 返回数据
示例返回：

``` JSON
{
  "text_html": "<a href='https://api.adsgram.ai/short/AwJ8ughbhDH'>Follow Velo For The Coming Big Announcement</a>\n<a>\nVelo\n\nMiss the Velo X Blackrock announcement previously?\nFollow Velo X now!\n\n<a href='https://api.adsgram.ai/short/DvvpNWxAtaG'>Click here to claim the reward after completing task!</a>\nAd. 18+</a>",
  "click_url": "https://api.adsgram.ai/short/AwJ8ughbhDH",
  "button_name": "Follow us!",
  "image_url": "https://images.adsgram.ai/3d618923-ba5f-4589-a3a8-ed97bd301435",
  "button_reward_name": "Claim reward!",
  "reward_url": "https://api.adsgram.ai/short/DvvpNWxAtaG"
}
```

## Step 3 — 发送广告
使用返回的数据来构建你的消息：
- `text_html` → 消息文本（HTML 格式）
- `image_url` → 广告图片
- `button_name` + `click_url` → 内联按钮
- `button_reward_name` + `reward_url` → 内联按钮
- `ParseMode` = HTML

> [!IMPORTANT] 重要提示：
> - `text_html` 包含 HTML 标签，请务必在你的 bot 框架中设置 **ParseMode.HTML**。
> - 通过 bot 发送的广告消息不允许被转发。\
> 你应使用 Telegram API 中的防止转发的消息类型，例如 sendPhoto 或 sendMessage，并设置参数 protect_content=True。
