如何对接Telegram



1. 创建Telegram机器人


1)打开temegram app

2)跳转到BotFather的对话框 (@BotFather)

3)在对话框用命令创建机器人  (/newbot)

4)按照提示和要求分别输入机器人名称和用户名

5)机器人创建成功,会返回一个当前机器人调用API的token,例如:2107284538:AAGCbec0DRtkmM3aJPWLbmnbze9wZkSkUWI,如下示例,创建了一个叫做jkbAlertDev的机器人:




output.png



2. 创建聊天组并获取组的chat_Id


1)创建一个聊天组


output.png


output.png


output.png


2)将机器人加入聊天组


output.png


output.png


output.png


output (1).png


3)获取chat_id

在浏览器中输入地址“https://api.telegram.org/bot{token}/getUpdates”  其中{token}需要替换成机器人的token,然后回车,得到类似如下结果:


{"ok":true,"result":[{"update_id":573747498,
"my_chat_member":{"chat":{"id":-616677960,"title":"\u5c0f\u5352","type":"group","all_members_are_administrators":true},"from":{"id":5875111787,"is_bot":false,"first_name":"c","last_name":"z","language_code":"zh-hans"},"date":1678786275,"old_chat_member":{"user":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"status":"left"},"new_chat_member":{"user":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"status":"member"}}},{"update_id":573747499,
"message":{"message_id":6,"from":{"id":5875111787,"is_bot":false,"first_name":"c","last_name":"z","language_code":"zh-hans"},"chat":{"id":-616677960,"title":"\u5c0f\u5352","type":"group","all_members_are_administrators":true},"date":1678786275,"new_chat_participant":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"new_chat_member":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"new_chat_members":[{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"}]}},{"update_id":573747500,
"my_chat_member":{"chat":{"id":-829402618,"title":"jkbFun3","type":"group","all_members_are_administrators":false},"from":{"id":5875111787,"is_bot":false,"first_name":"c","last_name":"z","language_code":"zh-hans"},"date":1678786487,"old_chat_member":{"user":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"status":"member"},"new_chat_member":{"user":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"status":"left"}}},{"update_id":573747501,
"message":{"message_id":8,"from":{"id":5875111787,"is_bot":false,"first_name":"c","last_name":"z","language_code":"zh-hans"},"chat":{"id":-829402618,"title":"jkbFun3","type":"group","all_members_are_administrators":true},"date":1678786487,"left_chat_participant":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"},"left_chat_member":{"id":6147667780,"is_bot":true,"first_name":"jkbAlertDev","username":"jkbAlertDev_bot"}}}]}

其中“chat”对象中的“id”的值就是chat_id


3. 进入监控宝平台,添加WebHook相关信息


进入<产品设置/WebHooks设置>页面,单击<添加WebHooks>,选择Telegram类型,填写获取的token和chant_id即可。




如何对接Slack



1. 创建app


创建app,可理解为创建一个应用,此应用包含六项扩展功能,和消息推送相关的两个功能就是webhooks(web钩子)和Bot(机器人),其中webhooks只能给channel发送消息,而Bot可以和channel内部进行交互,此处需要的是webhooks。 



需要跳转到浏览器进行创建,地址为:https://api.slack.com/apps。创建好app,指定到workspace,以及channel后,会拿到相关api以及curl实例。以下截图简单说明了app创建过程:


a7cda3b3-fefd-4d7b-8498-f7c3706a5d50.png


6399ddc1-08b5-4f9b-8836-c804e764ed96.png


d6ade056-98b5-463b-884a-04740f0abea9.png


e6876407-b8f7-40af-82ac-ad36637d344a.png


12faad89-6c5f-4fa7-9668-3e6e4bda1cc4.png


bde41895-b428-4720-907b-8ff4bb2f7afe.png


9ce105bf-bf06-40e9-93dc-34c8a5f56b28.png

77bed595-d45e-424c-b1cd-64fae42d2b3d.png


03803556-f77e-4171-a7c6-a1fc724e1349.png


2. 进入监控宝平台,添加WebHook相关信息


进入<产品设置/WebHooks设置>页面,单击<添加WebHooks>,选择Slack类型,填写获取Webhook URL即可。