webex integration
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2024 02:25 AM
Integrate Webex custom chat with PDI.
We are able to send requests from the Rest API Explorer when we use scripted rest api, and the message is sent to Webex. However, when we try to send requests from Webex, we are unable to receive them in ServiceNow, and we would like to use them in Virtual Agent.
Regards
Scripted REST Resource for post :
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var requestBody = request.body.data;
gs.info("Request Body: " + JSON.stringify(requestBody));
var incidentNumber = requestBody.incidentNumber;
var roomId = "roomid";
if (!incidentNumber || !roomId) {
response.setStatus(400); // Bad Request
response.setBody({
error: "Incident number or room ID not provided in the request."
});
return;
}
// Fetch incident details
var bot = new webex_bot();
var incidentDetails = bot.getIncDetails(incidentNumber);
var textMessage = "Incident details for " + incidentDetails;
var result = sendMessageToWebex(roomId, textMessage);
response.setStatus(200); // OK
response.setBody({
result: incidentDetails
});
} catch (ex) {
gs.error("Error processing request: " + ex.message);
response.setStatus(500); // Internal Server Error
response.setBody({
error: "Error processing request: " + ex.message
});
}
// Function to send message to Webex
function sendMessageToWebex(roomId, text) {
try {
var r = new sn_ws.RESTMessageV2('webex ', 'webexpostmsg');
r.setStringParameterNoEscape('roomId', roomId);
r.setStringParameterNoEscape('text', text);
// Log the request being sent
gs.info("Sending Webex message with roomId: " + roomId + " and text: " + text);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Webex response status: " + httpStatus);
gs.info("Webex response body: " + responseBody);
return responseBody;
} catch (ex) {
gs.error("Error sending message to Webex: " + ex.message);
throw ex;
}
}
// implement resource here
})(request, response);
0 REPLIES 0