Dingtalk-Webhook-Proxy
- 将钉钉(dingtalk)webhook代理成websocket
- 企业自建应用不用创建公网的回调地址,直接本地使用websocket客户端连上这个转发地址
设计
- 使用nchan维护websocket的连接
- 将钉钉的回调消息,抽取钉钉相关的头信息,外面包一层json,使用X-Request-Id作为唯一ID,推送给对应的channel
- 客户端自己保存钉钉的密钥信息,从转发服务走的消息都是加密的。
- 客户端调用钉钉其他接口,直接走自己的网络
安全性
- 钉钉回调消息都是加密的,只能由websocket客户端自己解密,转发服务是透明的。
- 如何确保自己的channel不会被别人恶意使用?
使用nginx basic auth,nchan支持auth_request,在对应的request里面使用basic auth就能做校验
实现
- 部署一个nchan(openresty版本)
- 配置一个internal的location,给内部转发钉钉消息使用
- 配置一个location,作为钉钉webhook转发(处理消息转发逻辑)
organization
使用一个organization对当前组织下面的所有bot进行管理 这样所有的消息可以通过
org_<name>一个channel推送,这种模式下启动服务的时候可以不用提前注册所有的bot,可以动态的加入新的bot进去
- 对org_的channel增加basic auth
- hook链接转发消息兼容organization
- 新增一个支持organization的client
client = Client(bot1, bot2, org_name='org_lloyd', org_passwd='passwd')
使用
python sdk
使用装饰器可以更简洁的通过一个回调函数处理消息
pip install ca-dingtalk-websocket
from connectai.dingtalk.websocket import Client
client = Client()
@client.on_bot_message(app_id='dingxxx', app_secret='xxx', agent_id='xxx', msgtype='text')
def on_message_callback1(bot, sessionwebhook, content, **kwargs):
text = content['content']
bot.reply(sessionWebhook, DingtalkTextMessage("reply: " + text))
client.start()
Metadata
Release files for ca-dingtalk-websocket 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ca-dingtalk-websocket-0.0.4.tar.gz | 4.2 kB | Without provenance | Details for ca-dingtalk-websocket-0.0.4.tar.gz |
Release files / ca-dingtalk-websocket-0.0.4.tar.gz
| Download URL | ca-dingtalk-websocket-0.0.4.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26a3fe298f5ce6610c182d5b81487203ec9305d7f98349a3a408fbd97cc94502
|
|
BLAKE2b-256 checksum How to use checksums |
b5e732f323cfae7da6db0a57e96ec7a9a682cb77de25eefdd8869e9d7e2be5ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for ca-dingtalk-websocket 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.