def handle(msg):
global look_obj
content_type, chat_type, chat_id = telepot.glance(msg)
print(content_type, chat_type, chat_id)
#if content_type == 'text':
#bot.sendMessage(chat_id, msg['text'])
msg_txt=msg['text']
words=msg_txt.split(' ')
#print(words[-1])
ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)
request = ai.text_request()
request.query = msg_txt
response = request.getresponse()
reply = response.read()
reply = reply.decode("utf-8")
parsed_json = json.loads(reply)
action = parsed_json['result']['action']
parameters = parsed_json['result']['parameters']
response = parsed_json['result']['fulfillment']['speech']
#return parameters, action, response
print(action)
print(parameters['object'])
if action=='go_to':
look_obj=str(parameters['object'])
print(look_obj)
bot.sendMessage(chat_id, ("I'll look for a " + str(parameters['object']) + "!") )
#TOKEN = sys.argv[1] # get token from command-line
obj_recogn_chatbot.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录