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

问题描述:

例如,机器人发出“给我你的名字”,“给我你的名字”,并保存这些数据有两种variables.my语言是Python,我用telepot包使机器人如何从用户电报机器人获取信息?

+1

看看这个链接https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot –

+1

谢谢。你在这个模块中有一个简单的例子吗?我没有使用这个模块 – samira

+1

如果你向下滚动链接有例子 –

退房this链接。向下滚动查看示例。希望这可以帮助!

在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的变量是联想的答复对问题 “你叫什么名字?”