diff --git a/README.md b/README.md index e9db3b0..3840267 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ - [ ] 企业微信 - [x] [Telegram](https://github.com/zhayujie/bot-on-anything#6telegram) - [x] [QQ](https://github.com/zhayujie/bot-on-anything#5qq) - - [x] 钉钉 + - [x] [钉钉](https://github.com/zhayujie/bot-on-anything#10%E9%92%89%E9%92%89) - [ ] 飞书 - [x] [Gmail](https://github.com/zhayujie/bot-on-anything#7gmail) - [x] [Slack](https://github.com/zhayujie/bot-on-anything#8slack) @@ -499,6 +499,10 @@ pip3 install PyJWT flask flask_socketio ### 10.钉钉 +**需要:** + +- 企业内部开发机器人 + **依赖** ```bash @@ -518,14 +522,16 @@ pip3 install requests flask } } ``` -钉钉开放平台说明: https://open.dingtalk.com/document/robots/customize-robot-security-settin.dingtalk.com/robot/send?access_token=906dadcbc7750fef5ff60d3445b66d5bbca32804f40fbdb59039a29b20b9a3f0gs +**参考文档**: -https://open.dingtalk.com/document/orgapp/custom-robot-access +- [钉钉内部机器人教程](https://open.dingtalk.com/document/tutorial/create-a-robot#title-ufs-4gh-poh) +- [自定义机器人接入文档](https://open.dingtalk.com/document/tutorial/create-a-robot#title-ufs-4gh-poh) +- [企业内部开发机器人教程文档](https://open.dingtalk.com/document/robots/enterprise-created-chatbot) **生成机器人** 地址: https://open-dev.dingtalk.com/fe/app#/corp/robot -添加机器人,在开发管理中设置服务器出口ip(在部署机执行curl ifconfig.me就可以得到)和消息接收地址(配置中的对外地址如 https://xx.xx.com:8081) +添加机器人,在开发管理中设置服务器出口 ip (在部署机执行`curl ifconfig.me`就可以得到)和消息接收地址(配置中的对外地址如 https://xx.xx.com:8081) ### 通用配置 diff --git a/channel/dingtalk/dingtalk_channel.py b/channel/dingtalk/dingtalk_channel.py index 47c5d7f..d85ac31 100644 --- a/channel/dingtalk/dingtalk_channel.py +++ b/channel/dingtalk/dingtalk_channel.py @@ -85,7 +85,7 @@ http_app = Flask(__name__,) @http_app.route("/", methods=['POST']) def chat(): - # log.info("[DingTalk] chat_headers={}".format(str(request.headers))) + log.info("[DingTalk] chat_headers={}".format(str(request.headers))) log.info("[DingTalk] chat={}".format(str(request.data))) token = request.headers.get('token') if dd.dingtalk_post_token and token != dd.dingtalk_post_token: @@ -95,7 +95,9 @@ def chat(): content = data['text']['content'] if not content: return - reply_text = dd.handle(data=data) + reply_text = "您好,有什么我可以帮助您解答的问题吗?" + if str(content) != 0 and content.strip(): + reply_text = dd.handle(data=data) dd.notify_dingtalk(reply_text) return {'ret': 200} return {'ret': 201} diff --git a/scripts/shutdown.sh b/scripts/shutdown.sh new file mode 100755 index 0000000..6afde41 --- /dev/null +++ b/scripts/shutdown.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +#关闭服务 +cd `dirname $0`/.. +export BASE_DIR=`pwd` +pid=`ps ax | grep -i app.py | grep "${BASE_DIR}" | grep python3 | grep -v grep | awk '{print $1}'` +if [ -z "$pid" ] ; then + echo "No bot-on-anaything running." + exit -1; +fi + +echo "The bot-on-anaything(${pid}) is running..." + +kill ${pid} + +echo "Send shutdown request to bot-on-anaything(${pid}) OK" + + + diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 0000000..610a95a --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,18 @@ +#!/bin/bash +#后台运行bot-on-anaything执行脚本 + +cd `dirname $0`/.. +export BASE_DIR=`pwd` +echo $BASE_DIR + +# check the nohup.out log output file +if [ ! -f "${BASE_DIR}/logs/log_info.log" ]; then + mkdir "${BASE_DIR}/logs" + touch "${BASE_DIR}/logs/log_info.log" +echo "${BASE_DIR}/logs/log_info.log" +fi + +nohup python3 "${BASE_DIR}/app.py" >> ${BASE_DIR}/logs/log_info.log & tail -f "${BASE_DIR}/logs/log_info.log" + +echo "bot-on-anaything is starting,you can check the ${BASE_DIR}/logs/log_info.log" +