随着人工智能技术的突破性进展,AI智能回复系统成为了科技界的新宠。智能回复可以帮助企业提高客户满意度,快速回答常见问题,并在需要时将问题转接给人工客服,同时也能不断丰富企业知识库推动企业发展。

可以先提前查看这位小伙伴文章:
https://www.yingdao.com/community/detaildiscuss?id=4dd35b73-9d15-477a-9e49-2224d9a20dfc


1)进入工作台--飞书机器人助手

2)随便选择一个指令模板

3)叉掉原流程,按这个配置,箭头这个就是你要复制到公众号平台的回调接口了

4.1 安装所需要的python模块(pycryptodome、requests)



4.2 关键点:配置流程
(1)新建模块,并粘贴代码

# 使用提醒:
# 1. xbot包提供软件自动化、数据表格、Excel、日志、AI等功能
# 2. package包提供访问当前应用数据的功能,如获取元素、访问全局变量、获取资源文件等功能
# 3. 当此模块作为流程独立运行时执行main函数
# 4. 可视化流程中可以通过"调用模块"的指令使用此模块
import xbot
from xbot import print, sleep
from .import package
from .package import variables as glv
import base64
import xml.etree.cElementTree as ET
import json
import hashlib
from Crypto.Cipher import AES
import os
import requests
appid = "111"
token = "111"
encodingAESKey = "111"
class PKCS7Encoder:
@staticmethod
def decode(text):
pad = text[-1]
if pad < 1 or pad > 32:
pad = 0
return text[:-pad]
@staticmethod
def encode(text):
block_size = 32
text_length = len(text)
amount_to_pad = block_size - (text_length % block_size)
pad = chr(amount_to_pad).encode()
return text + pad * amount_to_pad
class WXBizMsgCrypt:
def __init__(self, token, encoding_aes_key, id):
if not token or not encoding_aes_key or not id:
raise ValueError('please check arguments')
self.token = token
self.id = id
aes_key = base64.b64decode(encoding_aes_key + '=')
if len(aes_key) != 32:
raise ValueError('encoding_aes_key invalid')
self.key = aes_key
self.iv = aes_key[:16]
def get_signature(self, timestamp, nonce, encrypt):
arr = [self.token, timestamp, nonce, encrypt]
arr.sort()
sha1 = hashlib.sha1()
sha1.update(''.join(arr).encode())
return sha1.hexdigest()
def decrypt(self, text):
text = base64.b64decode(text)
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
decrypted = cipher.decrypt(text)
decrypted = PKCS7Encoder.decode(decrypted)
content = decrypted[16:]
length = int.from_bytes(content[:4], byteorder='big')
message = content[4:length + 4].decode()
id = content[length + 4:].decode()
return {
'message': message,
'id': id
}
def encrypt(self, text):
random_string = os.urandom(16)
msg = text.encode()
msg_length = len(msg).to_bytes(4, byteorder='big')
id = self.id.encode()
buf_msg = random_string + msg_length + msg + id
encoded = PKCS7Encoder.encode(buf_msg)
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
ciphered_msg = cipher.encrypt(encoded)
return base64.b64encode(ciphered_msg).decode()
def xml_to_dict(element):
if len(element) == 0: # 判断是否是叶子节点
return element.text
return {child.tag: xml_to_dict(child) for child in element}
def jiexi_message(encrypted):
#解密方法
crypt = WXBizMsgCrypt(token, encodingAESKey, appid)
decrypted = crypt.decrypt(encrypted)
# 使用xml_to_dict函数转换整个XML
root = ET.fromstring(decrypted["message"])
xml_dict = xml_to_dict(root)
json_str = json.dumps(xml_dict, ensure_ascii=False)
'''
json_str: {"userid": "omPAtxEaWG0i1taDJnV0YHsE_h54", "appid": "wx907dbe0def879a40", "content": {"msg": "你有收到我的消息吗", "msgtype": "text"}, "from": "0", "status": "0", "kfstate": "0", "channel": "0", "assessment": null, "createtime": "1715696977682", "msgtype": "text"}
'''
return json_str
def jiami_message(appid_s,userid,send_message):
#加密方法
data = '''<xml>
<appid><![CDATA[{}]]></appid>
<openid><![CDATA[{}]]></openid>
<msg><![CDATA[{}]]></msg>
<channel>0</channel>
</xml>'''.format(appid_s,userid,send_message)
crypt = WXBizMsgCrypt(token, encodingAESKey, appid)
encrypted = crypt.encrypt(data)
return encrypted
def send_message(encrypted):
#发送信息
url = "https://chatbot.weixin.qq.com/openapi/sendmsg/{}".format(token)
data = json.dumps({
"encrypt": encrypted
})
headers = {
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=data)
return response.text
def main(args):
pass
(2)将appid、token、encodingAESKey 修改为公众号平台的内容

(3)创建流程参数,传入第一个调用模块内容

(4)传入第二个调用模块内容

(5)传入第三个调用模块内容

参考教程: https://www.yingdao.com/community/detaildiscuss?id=4dd35b73-9d15-477a-9e49-2224d9a20dfc
并按照这个基本流程配置,并填写Webhook触发参数:{"encrypted":"3VEC9Qc6xImx2Z/CnTouWyi4JT7bnZ8x3wT3lHi3qiag4vB5xW/khDh3rS68nCouS7GrvPk/7ltFqJrzznkEOQ2nYpVs1k4JkcUmvoBiakOm3r37V3XSEB3vbkWXDsfk6Dg2770Ih3dvXwfThxiT62JQ4PysALDAFp0WZnexl03D4kbizkDSBoKJ8mwxdMpx4xn0zy/BO6UNmSHDa5Sf5mxFIkOvHk3VBn3WKYXVeTpqxenlqnpa7FqdQ5I2a597GbXq4M5qVftPVEFlsrH8Ask+tYKnuD3T33nNqIT48Ua1ZlgLZKHgfJ81VLdE2pKZpLKsYpYwMO2q4gIyuKscOLSPNenlctEcvAANjty+iaW94jWFW0NbguwrcSjmLA+H+IIzqWwPs1Z5gFv28UGUJfNpn09QiKuwap0/LK/t8lZpCSSydS7Ed0gWiJcz16xm1puvJbqUibgHnffpF6hstqQhGBnih2GM1NbPlSC3RF4p4XyahloVHfGjwn+7Os66MF4kwLvbtvsDkmBsL6DEQ0TQA+iydSd198mEVmxviKE="}

配置中有任何问题欢迎评论喔!