1. 程式人生 > >Python 使用圖靈機器人實現微信聊天功能

Python 使用圖靈機器人實現微信聊天功能

測試 自己的 class port get 圖靈 com reat arch

  首先需要去圖靈官網創建一個屬於自己的機器人然後得到apikey。

技術分享圖片

一、自動與指定好友聊天

# -*- coding: utf-8 -*-
"""
Created at 2019-3-26 11:50:49
"""

from wxpy import Bot,Tuling,embed,ensure_one
bot = Bot()
my_friend = ensure_one(bot.search(張三))  #想和機器人聊天的好友的備註
tuling = Tuling(api_key=apikey)     #這裏是圖靈機器人申請後的api
@bot.register(my_friend)  #
使用圖靈機器人自動與指定好友聊天 def reply_my_friend(msg): tuling.do_reply(msg) embed()

二、自動與指定群進行群聊。

# -*- coding: utf-8 -*-
"""
Created at 2019-3-26 11:50:49
"""

from wxpy import Bot,Tuling,embed
bot = Bot(cache_path=True)
my_group = bot.groups().search(群聊名稱)[0]  # 更改為自己的群聊名稱
tuling = Tuling(api_key=
apikey) # 圖靈機器人申請的apikey @bot.register(my_group, except_self=False) # 使用圖靈機器人自動在指定群聊天 def reply_my_friend(msg): print(tuling.do_reply(msg)) embed()

通過好友進行測試得到的結果:

技術分享圖片

Python 使用圖靈機器人實現微信聊天功能