繁体   English   中英

如何从用户电报机器人获取信息?

[英]How can I get information from the user telegram bot?

例如,机器人发送“给我你的名字”,“给我你的姓氏”并将这些数据保存在两个变量中。我的语言是 python,我使用 Telepot 包来制作机器人

看看这个链接。 向下滚动查看示例。 希望这有帮助!

在 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 变量是问题“你叫什么名字?”的回复助理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM