從零開始搭建Telegram機器人(一)—— 注冊機器人賬號


Telegram(非正式簡稱TG電報)是跨平台的即時通信軟件,其客戶端是自由及開放源代碼軟件,但服務器端是專有軟件。用戶可以相互交換加密與自毀消息(類似於“閱后即焚”),發送照片、影片等所有類型文件。官方提供手機版(AndroidiOSWindows Phone)、桌面版(WindowsmacOSLinux)和網頁版 [1]  等多種平台客戶端;同時官方開放應用程序接口(API),因此擁有許多第三方的客戶端可供選擇 [2]  ,其中多款內置中文。(轉載自百度百科)

准備工作

  • 一台外網服務器(可選,如果不需要保持24小時在線那么就不要)
  • 可以訪問telegram的網絡環境

注冊機器人賬號

  1. 打開telegram搜索“BotFather”
  2. 輸入消息窗口敲入以下命令
  3. /newbot
  4. 應該會顯示:Al­right, a new bot. How are we go­ing to call it?Please choose a name for your bot.
  5. 發送機器人ID,可以隨便填,但最好和你的用途有關
  6. 然后會提示Good. Now let's choose a user­name for your bot. It must end in bot. Like this, for ex­am­ple: Tetris­Bot or tetris_bot.
  7. 這時發送你給機器人設置的ID(和微信號類似),但必須以_bot結尾
  8. 如果顯示:Sorry, this username is invalid.就需要更改
  9. 直到顯示:Done! Congratulations on your new bot. You will find it at t.me/xxxxx_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.
  10. Use this to­ken to ac­cess the HTTP API: 【這里是API TOKEN,很重要,保存好且不要泄露】
  11. Keep your to­ken se­cure and store it safely, it can be used by any­one to con­trol your bot.
  12. For a de­scrip­tion of the Bot API, see this page: https://core.telegram.org/bots/api

編輯機器人信息(可選)

  1. 和上面一樣,發送指令
  2. /mybots
  3. 之后會顯示創建的所有機器人賬號ID,選擇剛才創建的那一個
  4. 會顯示六個選項:API To­ken:顯示 api 密鑰 Edit Bot:編輯機器人 Bot Set­tings:機器人設置 Pay­ments:支付 Delete Bot:刪除機器人(銷毀機器人賬號) Back...ots List:返回上一級列表
  5. 按照需求編輯即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM