Slack message to servicenow incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-28-2023 07:31 AM
Hi, Is it possible to get the messages replied in thread in slack message to respective incident's additional comments through API integration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-28-2023 09:46 AM
Hi @Sharath807 ,
Hope you are doing great.
To achieve this, you would need to utilize the Slack API and ServiceNow's REST API.
Here's a high-level approach to implement this integration:
Set up the Slack API integration: Create a Slack app or bot and configure it to access the necessary channels or conversations where incidents are being discussed.
Establish a webhook in ServiceNow: Create a webhook in ServiceNow to receive incoming Slack messages and process them accordingly. You can use ServiceNow's REST API to create the webhook endpoint.
Configure event subscriptions: Configure event subscriptions in Slack to capture message events in threads. This will enable your Slack app to receive notifications when new messages are posted in threads.
Handle incoming Slack messages in ServiceNow: When a message event is received from Slack, your ServiceNow webhook should parse the payload and extract the relevant information, such as the thread ID, message content, and associated incident number.
- Add the message as an additional comment to the respective incident: Using the incident number obtained from the Slack message, make an API call to ServiceNow's REST API to retrieve the corresponding incident record. Then, add the Slack message content as an additional comment to the incident using the AP
# Slack message event handler in ServiceNow
def handle_slack_message(event):
thread_id = event['thread_id']
message = event['message']
incident_number = event['incident_number']
# Retrieve the incident from ServiceNow using incident_number
incident_api_url = f"https://<your-instance>.service-now.com/api/now/table/incident/{incident_number}"
incident = requests.get(incident_api_url, headers={"Content-Type": "application/json", "Authorization": "<your-authentication>"})
# Add the Slack message as an additional comment to the incident
comments = incident['result']['comments']
comments.append({'comment': message})
incident['result']['comments'] = comments
# Update the incident record with the new comment
update_incident_api_url = f"https://<your-instance>.service-now.com/api/now/table/incident/{incident_number}"
update_incident = requests.patch(update_incident_api_url, headers={"Content-Type": "application/json", "Authorization": "<your-authentication>"}, json=incident['result'])
# Code to handle incoming Slack message events and call the handler function
ā
Please note that the above code snippet is a simplified example and may require modifications to fit your specific ServiceNow instance and Slack integration setup.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-31-2023 03:45 AM
@Riya Verma Hi, thankyou for your response.
Could you please elaborate more on 'step 3' . I tried to Configure event subscriptions , but not sure what to give in the URL field. I have tried with the instance url as well as incident url , both gave me the error -"Your URL didn't respond with the value of the challenge parameter." Please help .