WeWorkBot
1.0.0
The robot built for enterprise WeChat self-built applications can realize passive reply and active sending of various types of messages.
Now supported:
text ), image ( image ), voice ( voice ), video ( video ), location ( location ) and link ( link );text , image , voice , video , and news ;text , image , voice , video , markdown , graphic text ( mpnews ), graphic text ( news ), text card ( textcard ), file ( file ) and other message types; There are not many libraries that depend on, please refer to requirements.txt .
Currently supports Python >= 3.9 , the rest of the versions are not tested.
The Python library is now released and can be installed via pip install wwbot .
The following sample code shows the simple use of WeWorkBot . This example shows how to reply to a message of a text type ( text ):
from flask import Flask
from wwbot import WWBot
from wwbot . msg import Message , TextMessage
# 注册一个文本消息的事件监听
@ WWBot . on ( WWBot . TEXT )
def text_handler ( msg : TextMessage ) -> Message :
'''
msg参数代表接收到的消息被解析后的实例
'''
# 从消息中提取消息内容字段
# 关于接收到的消息格式具体定义,参考 https://developer.work.weixin.qq.com/document/path/90239
msg_content : str = msg . content
# 作为示例,直接使用接收到的消息作为回复,相当于一个 echo bot
return TextMessage ( msg . from_username , msg . to_username , msg . agent_id , msg_content )
# WeWorkBot运行在Flask框架之上
app : Flask = Flask ( 'WWBot' )
# 企业ID
corp_id : str = 'corp_id'
# 企业自建应用的secret 可以创建自建应用后在应用详情页面查看
corp_secret : str = 'corp_secret'
# 自建应用启用API接收消息时,配置的“Token”参数
token : str = 'token'
# 自建应用启用API接收消息时,配置的“EncodingAESKey”参数
aes_key : bytes = base64 . b64decode ( 'aes_key' )
# 接收消息回调时的url path部分
callback_path : str = '/wwbot'
# 配置机器人
WWBot . config ( app , corp_id , corp_secret , token , aes_key , callback_path = callback_path )
if __name__ == '__main__' :
app . run ( '0.0.0.0' , 31221 ) For more complete examples, please refer to exampls/echo_bot.py .
The code is updated as you like, mainly depends on whether there is any space or not. It will usually be updated frequently on weekends.