Telegram Bot and ServiceNow
Create a telegram bot which would take an Incident number as input and using ServiceNow REST Service it will output the details of the incident back to Telegram Chat Bot
1. Create a Telegram Bot -
To create a telegram bot follow the steps mentioned here
An access token would be generated once we create a telegram bot. This access token is used while making API calls to telegram from ServiceNow
2. Once u have the bot setup, we will create a webhook for this bot on ServiceNow.
- We created a scripted REST service.
- add a new resource with POST method and define a URL for the same
- take a note of the URL of the resource. This URL we will use in the next step.
- we have used a RestMessage - Send Details. This is an outbound REST message, details are available in the next step
- getIncDetails functions in script include - Utils, will get the incident details in the required format. The script is as follows
getIncDetails: function(number){
var inc = "";
var gr = new GlideRecord("incident");
gr.addQuery("number", number);
gr.query();
if (gr.next()) {
inc = "Number:" + number + "\n" + "Short Description:" + gr.short_description;
}
return inc;
},
3. Set the URL in Telegram WebHook Setup.
Send a GET request with the url that is created in the above step. For ex
https://api.telegram.org/bot<bot_token>/setWebhook?url=<instance>/api/237151/telegram_incidents/13579
This would set the webhook url on telegram.
4. Create an outbound message to send the details back to the requester
We will create a REST Message.
Send Details - we have used this in step 2 script section.
- You can get the Script by clicking on ‘Preview Script Usage’ found below the Related Links
Once, this is done, the telegram chatbot would look like the following
Resources
Hope this helps!!
https://www.servicenow.com/community/developer-articles/telegram-bot-and-servicenow/ta-p/2325258