Connect chat - How to inject CLICKABLE links trough connect action?

viniciusoliveir
Kilo Expert

Hi,

i ´ve been trying for a few days to inject a link on the connect chat by using a connect action that i have created. The goal is to send the chat survey link on the chat once it is closed.

1st i have tried generating a simple html string, and successfully injected the link on the chat, but the link was not clickable, it was just a normal text. Below is the snippet of my attempt:

var gcm = new GlideCollaborationManager();

gcm.sendSystemMessage(sys_id, surveyLink)

The ONLY way that i have found to do this, after researching a lot, is by using the "SNC.LiveFeedApi()". I am able to inject the clickable link in the chat this way, BUT, once you click the link, it is rendered inside ServiceNow backend UI, instead of service portal. I don ´t have any control over the generated link, it seems to be generating correctly but once you click the link, it adds   "nav_to.do?uri=/" to the url, causing the link to be rendered inside SN backend UI.

*NOTE: as per Hi support, GlideCollaborationManager() and SNC.LiveFeedAPI() are not public, so there is no documentation available.

Below is the complete code inside my connect action:

/* Get chat Survey Link for the customer */

// The survey is only triggered when the chat is completed

gs.sleep(2000);     // timer for the survey generation

// Pulling the survey record, to get it ´s link

var gcm = new GlideCollaborationManager();

var grSurveyInstance = new GlideRecord("asmt_assessment_instance");

var surveyLink = "";

var hrPortalURL = "hrportal?id=take_survey&instance_id=";

var message = "Help us improve by taking our short satisfaction survey related to your recent chat request!";

grSurveyInstance.addQuery("task_id", conversation.queueEntry.sys_id);

grSurveyInstance.query();

// Setting up the user ´s survey instance URL

if(grSurveyInstance.next()){

  surveyLink =gs.getProperty('glide.servlet.uri') + hrPortalURL + grSurveyInstance.sys_id;

   

  var id = conversation.document.group;

  new SNC.LiveFeedApi().addMessage(message + "\n\n\n" + surveyLink, id);

}

Do anyone know how can i make the link render correctly in any other way?

13 REPLIES 13

hrng
Giga Expert

Tried with LiveFeedMessage? There's a business rule or script include I stumbled across but can't find now... luckily I grabbed the code in my text editor.



var data = {


  message: msg,


  group_id: groupID,


  from_profile: profileID


};


//add link if we have a valid one


if (linkUrl && isUrl(linkUrl)) {


  data.links = [


  {short_description: linkName, url: linkUrl}


  ];


}


return new LiveFeedMessage().postMessage(data); // LiveFeedMessage is not available in V1


Got this working on our dev instance. This is an on insert business rule that injects a clickable link to the "fromID" on the chat_queue_entry record, but could be adapted to your needs:



var inc = current.from_id.getRefRecord();


var groupID = current.getValue('group');


var profileID = '';


var linkUrl = "/incident.do?sys_id="+inc.sys_id;


var linkName = inc.number+': '+inc.short_description;


var msg = "@L["+linkUrl+"|"+linkName+"]";




var grProfile = new GlideRecord('live_profile');


      grProfile.addQuery('name', 'Support');


      grProfile.addQuery('document', current.sys_id);


      grProfile.query();


if (grProfile.next()) {


        profileID = grProfile.getUniqueValue();


}




var data = {  


        message: msg,  


        group_id: groupID,  


        from_profile: profileID  


};  


//add link if we have a valid one  


if (linkUrl) {  


        data.links = [  


                  {short_description: linkName, url: linkUrl}  


        ];  


}


var output = JSON.stringify(data, null, 4);


gs.log(output);


return new LiveFeedMessage().postMessage(data);


Hi   Dave,


Can you please explain whats the usage of above BR and how to use it. I am in process of achieving the below using the connect action;


1.   display the name of the person who is requesting for chat.


2.   Show the incident number embedded with URL once created through chat window.


3.   agent won;t be able to close the chat if no ticket is created through particular chat window.



Can you please help me on the above.


The business rule runs after inserting an incident through the 'Create Incident' Connect Action. It runs when an incident is inserted with certain flags that I set during the incident creation via the connect action.



It solves #2 on your list, not sure about the others. I don't think #3 will be possible, and I'm not sure what you mean by #1. The user is already listed in the chat window, no?