logo

NJP

Telegram Bot For Servicenow

Import · May 03, 2022 · article

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.

image

- Script Include to send messages. (XML Attached)

image

- We created a scripted REST service.

image

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

image

  • 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.
  • 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/setWebhook?url=/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. image

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

image

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

Working of Bot

image

  • Search for ticket image
  • Search Knowledge Base image

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.

image

View original source

https://www.servicenow.com/community/now-platform-articles/telegram-bot-for-servicenow/ta-p/2313636