The CreatorCon Call for Content is officially open! Get started here.

Calling a REST Message in Virtual Agent and using using users input to give response.

Abhijeet Singh
Tera Contributor

Ask Your Questions using Virtual Agent. 

Step1: Create a new Topic in Virtual Agent Designer. 

All>Conversational Interfaces>Designer >Create 

AbhijeetSingh_0-1718627801688.png

 

 

AbhijeetSingh_1-1718627801690.png

Create a new NLU Model or if you already have one used that and create a new Intent for this particular Topic. 

AbhijeetSingh_2-1718627801691.png

 

 

Now add some Keywords 

Keywords: Words or phrases that users enter to initiate a conversation about the topic. The Virtual Agent Designer automatically adds the Name of the topic as a keyword. Resume topic flow: Toggle to allow a conversation to resume when Natural Language Understanding (NLU) is enabled. 

 

AbhijeetSingh_3-1718627801693.png

 

 

Step 2: Create Flow 

AbhijeetSingh_4-1718627801694.png

 

 

In this flow first it will ask if you want to ask something. 

If Yes: 

It will ask you what do you want to ask. 

AbhijeetSingh_5-1718627801694.png

 

AbhijeetSingh_6-1718627801697.png

 

 

Then we have used Bot Response Script. 

AbhijeetSingh_7-1718627801697.png

 

 

Here we called a Rest Message which I had created Earlier. 

Script : 

(function execute() { 

try { 

var body = JSON.stringify({ 

"contents": [{ 

"parts": [{ 

"text": vaInputs.ask_gemini.getValue()  

}] 

}] 

}); 

gs.log("Hii23"+body); 

var r = new sn_ws.RESTMessageV2('Gemini Integratiion', 'POST'); 

r.setRequestBody(body); 

 

var response = r.execute(); 

var responseBody = response.getBody(); 

        var res=JSON.parse(responseBody); 

var httpStatus = response.getStatusCode(); 

return res.candidates[0].content.parts[0].text; 

} catch (ex) { 

var message = ex.message; 

} 

})() 

 

#NOTE: To use the value of input (from Ask Gemini Node): We have used Inputs variables. 

To get the value: vaInputs.ask_gemini.getValue() 

For more details visit: Click Here. 

Here we get the response: 

AbhijeetSingh_8-1718627801699.png

 

 

 

It will ask if you want to ask further more questions or not. 

AbhijeetSingh_9-1718627801701.png

 

 

  • If No: 

It will end the conversation. 

 

AbhijeetSingh_11-1718627920963.png

 

 

 

 

 

THANKYOU 

Abhijeet Singh

ServiceNow Developer

Linked In: www.linkedin.com/in/abhijeet0610

1 REPLY 1

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

I don't really see the question you are having. What do you exactly need help with?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn