Luvv Aggarwal2
Tera Contributor

Create a telegram bot which would provide 3 options to users: - 

1 Create a Incident  
2 Search for ticket  
3 Search Knowledge Base 

and using ServiceNow REST Service it will send output 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 Create a Scripted REST API 

Once u have the bot setup, we will create a webhook for this bot on ServiceNow to receive user messages but before that we need to create a Scripted REST Service. 

- Create a table to record telegram conversation to provide context for the next message. 

E.g., If the user selects the 1st option, then ask for incident details. 

 find_real_file.png

- Script Include to send messages. (XML Attached) 

find_real_file.png

 
- We created a scripted REST service. 

 find_real_file.png

Add a new resource with POST method and define a URL for the same 

find_real_file.png  

  • Take a note of the URL of the resource. This URL we will use in the next step. 
  • We have used a Telegram - Send Message. This is an outbound REST message, details are available in the next step  
  • We are calling our script include to send messages in this resource. 
  1. Set the URL in Telegram Webhook Setup.
    Send a GET request with the URL that is created in the above step.

https://api.telegram.org/bot<bot_token>/setWebhook?url=<instance>/api/543178/telegram_bot/createIncident 

This would set the webhook URL on telegram which will send the user’s message to ServiceNow.  

  1. Create an outbound message

We will create a REST Message to send the details back to the user.  find_real_file.png

Send Message - we have used this in script include of step 2.  

find_real_file.png

We can get the Script by clicking on ‘Preview Script Usage’ found below the Related Links 

Working of Bot 

  • Create a Incident 

find_real_file.png

  • Search for ticket  find_real_file.png

 

  • Search Knowledge Base  find_real_file.png

 

  

Resources 

Special thanks to Telegram Bot and ServiceNow Article by Rad in helping me develop this use case. 

Hope this will help in understanding Telegram Bot API and ServiceNow REST integration. 

Comments
Tejas Chaudhar2
Tera Contributor

How to get a chat id from telegram? How do you execute the process?

 

 

Version history
Last update:
‎05-03-2022 01:01 AM
Updated by: