图灵机器人

Posted wanglinjie

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图灵机器人相关的知识,希望对你有一定的参考价值。

 

利用微信官方提供的开放API itchat库制作的微信聊天机器人

安装itchat,request模块,利用图灵接口

 1 # -*- coding: utf-8 -*-
 2 import itchat,time,re,requests
 3 from threading  import Timer
 4 from itchat.content import *
 5 def get_tl_res(msg):
 6     url = "http://www.tuling123.com/openapi/api"
 7     data = {
 8         "key": "e549********************",# 自己注册图灵,获取KEY
 9         "info": msg,
10         "userid": "pth-robot"
11     }
12     res = requests.post(url, data=data).json()
13     return res.get("text")
14 @itchat.msg_register([TEXT],isGroupChat=True)
15 def text_reply(msg):
16     if msg[isAt]:
17         res = get_tl_res(msg["Text"])
18         itchat.send((res), msg["FromUserName"])
19 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING],isGroupChat=True)
20 def other_reply(msg):
21     if  msg[isAt]:
22         res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
23         itchat.send((res),msg["FromUserName"])
24 
25 itchat.auto_login(hotReload=True)
26 #itchat.auto_login(enableCmdQR=2, hotReload=True) 
27 itchat.run()

 

 

 1 # -*- coding: utf-8 -*-
 2 import itchat,time,re,requests
 3 from threading  import Timer
 4 from itchat.content import *
 5 def get_tl_res(msg):
 6     url = "http://www.tuling123.com/openapi/api"
 7     data = {
 8         "key": "e549********************",# 自己注册图灵,获取KEY
 9         "info": msg,
10         "userid": "pth-robot"
11     }
12     res = requests.post(url, data=data).json()
13     return res.get("text")
14 @itchat.msg_register([TEXT],isGroupChat=True)
15 def text_reply(msg):
16     #if msg[‘isAt‘]:
17     res = get_tl_res(msg["Text"])
18     itchat.send((res), msg["FromUserName"])
19 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING],isGroupChat=True)
20 def other_reply(msg):
21     #if  msg[‘isAt‘]:
22     res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
23     itchat.send((res),msg["FromUserName"])
24 
25 # 注册文本消息,绑定到text_reply处理函数
26 # text_reply msg_files可以处理好友之间的聊天回复
27 @itchat.msg_register([TEXT,MAP,CARD,NOTE,SHARING])
28 def text1_reply(msg):
29     res = get_tl_res(msg["Text"])
30     itchat.send((res), msg["FromUserName"])
31 @itchat.msg_register([PICTURE,RECORDING,VIDEO,SHARING])
32 def other_reply1(msg):
33     #res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
34     res = get_tl_res(msg[PICTURE,RECORDING,VIDEO,SHARING])
35     itchat.send((res),msg["FromUserName"])
36 
37 
38 
39 itchat.auto_login(hotReload=True)
40 #itchat.auto_login(enableCmdQR=2, hotReload=True) 
41 itchat.run()

 

以上是关于图灵机器人的主要内容,如果未能解决你的问题,请参考以下文章

Android开发之图灵机器人

Python 004- 利用图灵小机器人来搭建微信聊天自动回复机器人

apikey创建接入图灵机器人

微信公众号接入图灵机器人实现自动回复消息

图灵机器人API,适用于微信微博QQ群智能硬件等

个人微信接入图灵机器人(python版)