Telegram获取token 和chat_id简明教程 作者: Hogwarts 发布于: 2022-09-22 更新于: 2022-09-22 分类: 默认分类 想开一台吃灰机器,没有IP故无法开机,使用脚本刷机,并推送到Telegrame。其实刷机就可以了,推不推送也没多大关系。但脚本需要填写这些参数,不会修改就照抄了。 #一、加入 BotFather 机器人 点击网址`https://t.me/BotFather` ,打开与它的聊天界面。 #二、创建 bot 并获取 token ##2.1 创建机器人 输入 `/newbot` 回车 显示:Alright, a new bot. How are we going to call it? Please choose a name for your bot. ##2.2 输入机器人的名称 比如输入 winamp bot 回车 显示:Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot. ##2.3 输入唯一的机器人用户名 格式为` winamp_bot` 或 `winampbot` **必须以bot结尾。** 失败后显示:Sorry, xxxxxxxxxx 成功后显示: Done! Congratulations on your new bot. You will find it at t.me/winamp_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: `5538174337:AAHCLfyReMOfeLnp_znYWsICjTd1e3ApRGg` Keep your token secure and store it safely, it can be used by anyone to control your bot. ##2.4 提取token 2.3中HTTP API 下面一行就是需要的token。 #三、获取chat_id ##3.1先测试一下 浏览器中输入:`https://api.telegram.org/bot{token}/getUpdates` 回车 其中:{token}为2.4中获取的token,**包括大括号**。 显示:{ "ok": true, "result": [] } 如果显示error,说明有错误。 ##3.2 获取chat_id **3.2.1** 在你生成的机器人中(本例为winamp bot的机器人)随意输入一个词语,比如“Hello World”。 **3.2.2** 重新在浏览器中输入`https://api.telegram.org/bot{token}/getUpdates` 其中:{token}为2.4中获取的token,**包括大括号**。 **3.2.3** 在显示的ok页中找到"chat": {"id": 123456789,"first_name".......其中**id后的数字**即为需要的chat_id。 ##3.3 curl 测试一下获取到的taken和chat_id 在vps中输入命令 curl -s -X POST https://api.telegram.org/bot{token}/sendMessage -d chat_id={chatId} -d text="Hello World" 其中:{token}、{chatId}分别为获取的token和chatid,包括大括号。 ##3.4 成功与否 Telegrame客户端中的winamp bot收到"Hello World",就成功了! #四、参考 [Telegram 创建 bot 获取 token 和 chatId 以及发送消息简明教程](https://hellodk.cn/post/743 "Telegram 创建 bot 获取 token 和 chatId 以及发送消息简明教程") 标签: telegrame, token, bot