Zhao Dongyu's Blog

A life which is unexamined is not worth living.

0%

Telegram bot

最近学习一些telegram bot,记录一下

Installing

安装 python-telegram-bot 库

pip install python-telegram-bot --upgrade

安装完毕 > Successfully installed h11-0.14.0 httpcore-1.0.3 httpx-0.26.0 python-telegram-bot-20.8

bot 申请

私聊BotFather,

  • /start
  • /newbot
  • Alright, a new bot. How are we going to call it? Please choose a name for your bot.
  • IngressHomogeneous
  • Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.
  • IngressHomogeneousBot
  • Done! Congratulations on your new bot. You will find it at t.me/IngressHomogeneousBot. 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.

妥善保存最后的 API Token。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
You can control me by sending these commands:

/newbot - create a new bot
/mybots - edit your bots

Edit Bots
/setname - change a bot's name
/setdescription - change bot description
/setabouttext - change bot about info
/setuserpic - change bot profile photo
/setcommands - change the list of commands
/deletebot - delete a bot

Bot Settings
/token - generate authorization token
/revoke - revoke bot access token
/setinline - toggle inline mode
/setinlinegeo - toggle inline location requests
/setinlinefeedback - change inline feedback settings
/setjoingroups - can your bot be added to groups?
/setprivacy - toggle privacy mode in groups

Web Apps
/myapps - edit your web apps
/newapp - create a new web app
/listapps - get a list of your web apps
/editapp - edit a web app
/deleteapp - delete an existing web app

Games
/mygames - edit your games
/newgame - create a new game
/listgames - get a list of your games
/editgame - edit a game
/deletegame - delete an existing game

获取我的 id

每个 tg 用户都有一串唯一标识,即为 user_id,可以私聊 @kmua 发送 /id 来获取它

跟着Your-first-Bot这个来就好了,理解的话可以参考使用Python写一个Telegram bot吧|Telegram bot教程

感觉整体比较好理解,接下来就是赋予其灵魂了~


参考文章:

python-telegram-bot.org

Your-first-Bot

使用Python写一个Telegram bot吧|Telegram bot教程

Thanks for your support.