申請TelegramBot教學

申請TelegramBot教學

Step1:前置作業:需安裝及申請Telegram帳號。(網路上有許多教學)
Step2:用搜尋方式找到申請Bot的帳號:【BotFather】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
申請對話流程如下:

申請人: /newBot

BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.

申請人: 輸入欲設定的bot name

BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.

申請人: 輸入欲設定的bot的username (結尾一定要有bot,這也是未來被搜尋的name)

BotFather:
Response1 - Sorry, this username is already taken. Please try something different. (username與他人重覆)
Response2 - Done! Congratulations on your new bot. You will find it at telegram.me/xxxbot.
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:
【這邊會顯示Token】

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

Step3:建立一個Telegram群組,將設定好的bot加入群組(並設置為admin)。
Step4:打開瀏覽器使用 https://api.telegram.org/bot{token}/getUpdates ,在回傳的訊息中,就可以看到chatid。
Step5:透過Telegram api : sendmessage,測試傳遞訊息,https://api.telegram.org/bot{token}/sendMessage?chat_id={chatid}&text={訊息}。