WeCom Bot Callback Server Simple Framework
Project description
企业微信机器人回调服务
1. 介绍
本项目是一个基于 Flask的企业微信机器人回调功能的接口服务简单框架 。使用者只需要实现两个简单的函数,即可快速搭建一个企业微信机器人回调功能的接口服务。
实现过程参考企业微信机器人回调功能说明文档 ,以及相关文档中指引使用的加解密脚本。
2. 使用
2.1 安装
python3 -m pip install wecom_bot_svr
2.1 配置回调相关参数
在企业微信,找到机器人,点击「点击配置」,配置进去准备使用的URL,并自动产生对应的 Token 和 Key:
这里的 Token 和 AesKey 是后续会使用的参数。 此时点击保存不能生效,因为企业微信会校验服务返回是否正常。 框架已经实现了校验的逻辑,但是需要先部署服务。
为了安全起见,Token 和 AesKey 不要直接写在代码中,建议通过环境变量传入:
WX_BOT_TOKEN=xxxxx
WX_BOT_AES_KEY=xxxxx
WX_BOT_CORP_ID=xxxxx
2.2 实现回调
参考 demo.py 中的实现,主要步骤:
- 创建Server对象,如果 token, aes_key, corp_id 打算按照环境变量的方式传入,则这里直接不用填最后三个参数。
- 定义两个函数:消息处理函数、事件处理函数
- 将两个函数注册到 Server 对象中
- 启动服务
import wecom_bot_svr
token = "xxxxxxx"
aes_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
corp_id = ""
host = "0.0.0.0"
port = 5001
server = wecom_bot_svr.Server("wx_bot", host, port, token=token, aes_key=aes_key, corp_id=corp_id)
def msg_handler(user_info, msg_type, content, xml_tree):
print(user_info, msg_type, content)
return "hello"
def event_handler(user_info, event_type, xml_tree):
print(user_info, event_type)
return "hello"
server.set_message_handler(msg_handler)
server.set_event_handler(event_handler)
server.run()
3. 更多消息处理示例
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wecom_bot_svr-0.2.0.tar.gz
(127.8 kB
view details)
Built Distribution
File details
Details for the file wecom_bot_svr-0.2.0.tar.gz
.
File metadata
- Download URL: wecom_bot_svr-0.2.0.tar.gz
- Upload date:
- Size: 127.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
29218ffdab77adf79c3acb25e829285da498dfb0e10a67093e19907a43201082
|
|
MD5 |
c8481ec3f535290ed6398652c5f3eb74
|
|
BLAKE2b-256 |
fb64ea2467384ef8f3623d65cf639adb6da670133b3d02806aae9301dd48fc0b
|
File details
Details for the file wecom_bot_svr-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: wecom_bot_svr-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
02544dd769c0411b443a2249abbab45563e4b882af50ab80e95591b9b3fadefa
|
|
MD5 |
5982f5be251b069707b541bcc225de04
|
|
BLAKE2b-256 |
9bf35a880b4c1ac3b8ac1791461bfdfcb0d501dd3cf3af717a50e3ca76d505b2
|