diff --git a/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/README.md b/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/README.md new file mode 100644 index 0000000000..1b2b1a4f3f --- /dev/null +++ b/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/README.md @@ -0,0 +1,4 @@ +When a VIP user creates an incident, notify a Slack channel (or send via webhook) with a custom JSON message. +Note : You’d need to set up a Slack Incoming Webhook for this. + +This business rule triggers on incident creation and checks if the `caller` has the `vips` flag set to `true`. If so, it constructs a JSON payload with incident details and sends a POST request to a predefined Slack webhook URL using `sn_ws.RESTMessageV2`. The purpose is to notify support teams in real time when a VIP user logs an incident. diff --git a/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/code.js b/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/code.js new file mode 100644 index 0000000000..a252c9f4e4 --- /dev/null +++ b/Server-Side Components/Business Rules/Send Custom Slack Message When VIP Logs an Incident/code.js @@ -0,0 +1,15 @@ +(function executeRule(current, gSNC, gUser, gSNCSession) { + if (current.caller.vips && current.caller.vips == true) { + var request = new sn_ws.RESTMessageV2(); + request.setEndpoint('https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX'); + request.setHttpMethod('POST'); + + var payload = { + "text": " *VIP Incident Created!* \nCaller: " + current.caller.name + "\nNumber: " + current.number + "\nDescription: " + current.short_description + }; + + request.setRequestHeader("Content-Type", "application/json"); + request.setRequestBody(JSON.stringify(payload)); + var response = request.execute(); + } +})(current, gSNC, gUser, gSNCSession);