How to extend async calls that Servicenow sends to a third-party chat endpoint.

Alex G_
Tera Contributor

The situation is as follows: we have integrated Virtual Agent Chat with a third-party chat. Everything works.

But now we need to add our own additional value in JSON-Response which will change depending on the dialog state.

 

For integration we use System Web Services > REST Message > VA Bot to Bot. So it is the Endpoint that is specified in the Endpoint field that should receive this extended JSON message.

 

Now the third-party Chat receives a JSON-message like:

 

 

 

{
    "agentChat": true,
    "body": [
        {
            "actionType": "StartSpinner",
            "message": "Sie werden an einen Servicemitarbeiter weitergeleitet...",
            "spinnerType": "wait_time",
            "uiType": "ActionMsg",
            "waitTime": "1 Minute"
        }
    ],
    "score": 1,
    "userId": "637a68f8781a4a02800ec0de99d26201"
}

 

 

 or like this:

 

 

{
    "agentChat": true,
    "body": [
        {
            "actionType": "System",
            "message": "Max Mustermann has joined.",
            "uiType": "ActionMsg"
        }
    ],
    "score": 1,
    "userId": "637a68f8781a4a02800ec0de99d26201"
}

 

 

 

We would like to add our own tag to the JSON depending on the "actionType".

 

For example like that with a new element "type":

 

 

{
    "agentChat": true,
    "body": [
        {
            "actionType": "System",
            "message": "Max Mustermann has joined.",
           "uiType": "ActionMsg",
            "type": "add_to_chat"
        }
    ],
    "score": 1,
    "userId": "637a68f8781a4a02800ec0de99d26201"
}

 

 

is this possible ?

 

Thank you for you time !

2 REPLIES 2

dgarad
Giga Sage

Hi @Alex G_ 

Please take a look at the script below.

var data ={
    "agentChat": true,
    "body": [
        {
            "actionType": "System",
            "message": "Max Mustermann has joined.",
            "uiType": "ActionMsg"
        }
    ],
    "score": 1,
    "userId": "637a68f8781a4a02800ec0de99d26201"
};
gs.print(JSON.stringify(data));
data.body[0].actionType= 'new test tag';
gs.print(JSON.stringify(data));

 

dgarad_0-1718348047986.png

 

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Alex G_
Tera Contributor

Hello dgarad ,

 

Thanks for your reply, but it's not what I need. The JSON I provided above is generated von ServiceNow (Live Chat) and sent asynchronously to the third party chat-vendor. We are looking for a way to extend it, or perhaps a ServiceNow Script that could be rewritten/extended