Skip to main content

Dingtalk-Webhook-Proxy

  1. 将钉钉(dingtalk)webhook代理成websocket
  2. 企业自建应用不用创建公网的回调地址,直接本地使用websocket客户端连上这个转发地址

设计

  1. 使用nchan维护websocket的连接
  2. 将钉钉的回调消息,抽取钉钉相关的头信息,外面包一层json,使用X-Request-Id作为唯一ID,推送给对应的channel
  3. 客户端自己保存钉钉的密钥信息,从转发服务走的消息都是加密的。
  4. 客户端调用钉钉其他接口,直接走自己的网络

安全性

  1. 钉钉回调消息都是加密的,只能由websocket客户端自己解密,转发服务是透明的。
  2. 如何确保自己的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)

Source distribution for ca-dingtalk-websocket 0.0.4
File Size Uploaded
ca-dingtalk-websocket-0.0.4.tar.gz 4.2 kB Details

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

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page