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.0.2.tar.gz
(127.5 kB
view details)
Built Distribution
File details
Details for the file wecom_bot_svr-0.0.2.tar.gz
.
File metadata
- Download URL: wecom_bot_svr-0.0.2.tar.gz
- Upload date:
- Size: 127.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
93bfd63b866e10dedb47fae2e5e750dcb26a5990df458b249eac25429508a3a9
|
|
MD5 |
0b890db095a361b2827dac610145fb21
|
|
BLAKE2b-256 |
9faa0025295087ffc10340a24b4f7f494c767cb359058b852fc540d4ccdd7c4f
|
File details
Details for the file wecom_bot_svr-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: wecom_bot_svr-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
310ff3db2b5f6dce071a0b25480e84b0a6d2422ea99f10ee20ea83b56f6d078b
|
|
MD5 |
30f7f7ae19b19942552255c54af5b424
|
|
BLAKE2b-256 |
ae520a63a8b0a185b1e87436f7f7249ddead8a71c190582803d3639d272b0215
|