Bước 1: cần có 1 con bot trên telegram, cách tạo bot các bạn chat với @botfather và làm theo hướng dẫn. Sau khi thực hiện, sẽ có token trả về, sử dụng để authen đối với các request tới bot
token có dạng đại loại như:
481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA
Bước 2: tạo 1 room chat với con bot chúng ta vừa tạo, cứ tạo cuộc trò chuyện mới sau đó add con bot mới vào.
Bước 3: Lấy chat ID của cuộc trò chuyện vừa tạo
sử dụng URL có định dạng:
https://api.telegram.org/bot<token của bot>/getUpdates
VD: https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/getUpdates
call lên url mới có với header: “Content-Type: application/json”
1 |
curl -H "Content-Type: application/json" https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/getUpdates |
chúng ta sẽ nhận được chuỗi json trả về, với chatID tương ứng
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
{ "ok": true, "result": [ { "update_id": 911858273, "message": { "message_id": 15396, "from": { "id": 432109061, "is_bot": false, "first_name": "some name", "last_name": "ハンサム", "username": "some username", "language_code": "en" }, "chat": { "id": -359110891, "title": "GmsABD", "type": "group", "all_members_are_administrators": true }, "date": 1566359213, "new_chat_participant": { "id": 471543210, "is_bot": true, "first_name": "SexyBot", "username": "damducbot" }, "new_chat_member": { "id": 471543210, "is_bot": true, "first_name": "SexyBot", "username": "damducbot" }, "new_chat_members": [ { "id": 471543210, "is_bot": true, "first_name": "SexyBot", "username": "damducbot" } ] } }, { "update_id": 911858274, "message": { "message_id": 15397, "from": { "id": 432109061, "is_bot": false, "first_name": "some name", "last_name": "ハンサム", "username": "some username", "language_code": "en" }, "chat": { "id": -359110891, "title": "GmsABD", "type": "group", "all_members_are_administrators": true }, "date": 1566359341, "new_chat_photo": [ { "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2EAAz3VAQABFgQ", "file_size": 5297, "width": 160, "height": 160 }, { "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2IAAz7VAQABFgQ", "file_size": 11196, "width": 320, "height": 320 }, { "file_id": "AgADBQADsqcxG5SuihmFyQGf595pCVSo-TIABAEAAwIAA2MAAz_VAQABFgQ", "file_size": 25020, "width": 640, "height": 640 } ] } }, { "update_id": 911858275, "message": { "message_id": 15398, "from": { "id": 442710299, "is_bot": false, "first_name": "Mr Dam", "username": "Damnnvn" }, "chat": { "id": -359110891, "title": "GmsABD", "type": "group", "all_members_are_administrators": true }, "date": 1566359505, "new_chat_participant": { "id": 867065125, "is_bot": false, "first_name": "Mr du", "username": "mrdu" }, "new_chat_member": { "id": 867065125, "is_bot": false, "first_name": "Mr du", "username": "mrdu" }, "new_chat_members": [ { "id": 867065125, "is_bot": false, "first_name": "Mr du", "username": "mrdu" } ] } } ] } |
Theo như ở trên, chúng ta có nhóm
1 2 3 4 5 6 |
"chat": { "id": -359110891, "title": "GmsABD", "type": "group", "all_members_are_administrators": true }, |
Đã có chat ID
Bước 4:
Điền thông tin vào PRTG, truy cập PTRG, setup –> notify template
Sửa or add 1 template
Phần Execute HTTP Action
URL dạng: https://api.telegram.org/bot481775980:NAGtU-UYFQfYhufthedUAwMB2XWzRc8F6AA/sendMessage
HTTP Method: POST
Payload:
1 2 3 4 5 6 7 |
chat_id= số chat ID lấy được ở bước trên&text= [%sensor](%linksensor) *Last Value* %lastvalue *Last Message* %lastmessage *Down since* %since *Device* %device *Group* %group&parse_mode=Markdown |
Ví dụ hoàn chỉnh
1 2 3 4 5 6 7 |
chat_id=-359110891&text= [%sensor](%linksensor) *Last Value* %lastvalue *Last Message* %lastmessage *Down since* %since *Device* %device *Group* %group&parse_mode=Markdown |
Lưu tất cả lại.
Sau đó khi add trigger notifycation, chọn template này là OK