如何从用户电报机器人获取信息?
答
在telepot包:
import telepot
from telepot.loop import MessageLoop
import time
bot = telepot.Bot('my_token')
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
send1 = bot.sendMessage(chat_id,'whats your name?')
if send1:
text1 = msg['text']
print(text1)
MessageLoop(bot,handle).run_as_thread()
while 1:
time.sleep(1)
text1的变量是联想的答复对问题 “你叫什么名字?”
看看这个链接https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot –
谢谢。你在这个模块中有一个简单的例子吗?我没有使用这个模块 – samira
如果你向下滚动链接有例子 –