[半弃坑] Telegram Bot 的一点问题(1) -- 为什么搭了梯子没反应、查询 ID 和老黄历
发现没啥功能想继续实现的。也没有实际用途,弃坑了。
操作
在 Telegram 联系 @BotFather 来获取一个 bot。得到它的 API token 来操作。
这里使用了基于 Python 的 pyTelegramBotAPI。
https://github.com/eternnoir/pyTelegramBotAPI
先写一个 /start 对应的命令,于是咱参考了「Writing Ur first bot」中的部分,于是内容是
1 | import telebot |
问题
首先遇到的问题是打开全局代理之后报错,关闭之后连不上。
这里使用了 Proxifier 来给 Python 走代理。
#127.0.0.1:[端口]
接下来遇到的问题就是类似于下文的状况:
requests.exceptions.SSLError: HTTPSConnectionPool(host=‘api.telegram.org’, port=4*3): Max retries exceeded with url: /bot[number]:[TOKEN]/getUpdates?offset=1&timeout=20 (Caused by SSLError(SSLEOFError(8, ’EOF occurred in violation of protocol (_ssl.c:1129)’)
https://stackoverflow.com/questions/68965686/requests-exceptions-connecttimeout-httpsconnectionpoolhost-api-telegram-org
上文的代码就是解决这个问题的方法。
1 | from telebot import apihelper |
这个时候出现了 「Missing dependencies for SOCKS support.」 的情况。Python 不支持走 socks5 代理,于是在命令行
1 | pip install pysocks |
https://stackoverflow.com/questions/38794015/pythons-requests-missing-dependencies-for-socks-support-when-using-socks5-fro
问题解决。
利用 bot.send_[format] 来回复
API 文档当中写的是
1 | tb = telebot.Telebot<TOKEN> |
用法:
1 |
|
chat_id = message.chat.id
message.chat.id 得到的是一个数。可以对它进行运算。