Giter Club home page Giter Club logo

webhookserver's Introduction

使用Gradle和Kotlin重写一下之前 钉钉通知服务器 顺便再熟悉下服务端基本编写操作

博客: 打通gitlab与钉钉之间的联系

1. 配置 config.properties 文件参数

clone项目后,请在项目根目录下创建 src/main/webapp/config.properties 并设置如下属性值,以便获取钉钉相关参数

# 必填,企业在钉钉中的标识,每个企业拥有一个唯一的CorpID
corpid=dingaa******c2f4657eb6378f
# 必填,企业每个应用的凭证密钥
corpsecret=Bp1_HoQej2s******LE7aRWaJm_lYpSMYvVQi-_Q
# 必填,钉钉微应用id
agentId=123456

# 可选,gitlab默认通知审核的人员或者gira默认通知的bug归属人的真实名字,用于匹配钉钉通讯录获取userId
# 同时也是蒲公英上传应用后回调通知的默认用户
defaultNoticeUserName="张三"
# 可选,jira 详情面板网址前缀(带斜杠),其后添加jira bugId接口拼接成完整地址,若无请放空
jira_borwse_url=http://jira.soundbus.tech/browse/
# gitlab合并的目标分支是该分支时, 此hook请求才需要发送钉钉消息,不填的话,默认master
gitlab_push_merge_branch=master

#---IM-Telegram 配置---
# 用于接收消息的默认bot token
tg_bot_token=9749123470:abced
# 默认接收消息的tg用户username
tg_user_name=helobotxxx

2. 通讯录规则

在通讯录root部门中添加所有人,以便发送消息到特定用户时可以从root部门中查询得到用户id; 根据gitlab项目路径配置各项目部门,比如:

  • gitlab项目地址为: https://gitlab.lynxz.org/demo-android/detail-android 则表示项目名称(name) 为: detail-android ,项目所在空间(namespace)为: demo-android
  • 在钉钉后台通讯录中需要先创建部门: demo_android ,然后创建其子部门 detail_android 注意: 由于钉钉部门名称不允许使用 -,因此创建时改为 _ 替代
  • 目前只支持两级部门结构,若有多个部门符合上述规则gitlab merge通过时会通知所有匹配的部门成员; 钉钉通讯录

3. 功能url

  1. {serverHost}/action/refreshToken 重新刷新access_token,并重新获取通讯录
  2. {serverHost}/action/updateDepartmentInfo 请求该url会立即重新获取钉钉通讯录信息,用于用户更新了钉钉通讯录后主动触发服务器刷新数据
  3. {serverHost}/action/save_data?**=** 可以将 query 数据保存到文件中 如: 1.1.1.1:8080/server-V0.1.4/action/updateDepartmentInfo
  4. {serverHost}/action/send_msg post 请求,发送消息给钉钉指定的人员或者部门
curl -d "{\"name\":\"\",\"mobile\":\"\",\"content\":\"消息内容\",\"departmentName\":\"部门名称\"}" {serverHost}/action/send_msg
  1. {serverHost}/action/send_msg post 请求,发送消息给钉tg指定用户
curl -d "{\"name\":\"目标用户userName\",\"imType\":\"Telegram\",\"content\":\"消息内容\",\"tgBotToken\":\"tg bot token\"}" {serverHost}/action/send_msg

name: 发送钉钉消息时可空,钉钉用户姓名或者备注名, 发送tg消息时必填,为用户昵称或者userName content: 必填,要发送的消息 mobile: 可空, 钉钉用户手机号,优先匹配 imType: 可空,用于发送的IM类型,目前支持两种: Telegram 和 DingDing, 默认为 DingDing departmentName: 发送钉钉消息时必填,为用户所在部门名称 tgBotToken: 用于接收消息的tg机器人token,默认值为 config.propertiestg_bot_token

服务端会查询 departmentName 部门下的 手机号和名称相符的用户, 若查得到,则发消息给他 否则,发送消息给该部门所有人

4. telegram bot使用

  1. 在tg中,@BotFather - /newbot - 输入任意名称说明 - 输入以 _bot 结尾的名称 - 成功,得到token
  2. 将上述得到的botToken信息填入 src/main/webapp/config.properties 中的 tg_bot_token 字段
  3. 将你的tg userName填入 src/main/webapp/config.properties 中的 tg_user_name 字段,用于默认接收消息用户
  4. 任意发送一条消息给上面创建的bot

4. 效果介绍

1. gitlab相关

gitlab有merge代码审核请求 gitlab有merge请求被关闭时,会通知提交人 gitlab有merge请求被reopen时,会通知审核人 gitlab merge 请求被通过时,会通知相关项目部门所有成员更新代码

2. jira相关

jira上有新的 issue 被创建时,会通知issue归属用户 jira上有新的 issue 有更新时,会通知issue归属用户

3. 蒲公英

蒲公英上有新版本的app上传成功时,会通知指定用户

webhookserver's People

Contributors

lucid-lynxz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.