Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_ExcerptVirtualAssistant
_ExcerptVirtualAssistant
nopaneltrue

...

  1. Get an API key for Vonage AI API. Ask Vonage to store this key in a custom configuration value for your account. For information about getting an API key for Vonage AI API, see Vonage AI Studio authentication.
  2. Create a virtual agent and configure the agent's conversation. Save the agent's ID and virtual number to use later. For information about creating a virtual agent, see Create a new Vonage AI Studio agent.
  3. Make a note of response parameters that your virtual agent can return. For information about response parameters, see Vonage AI Studio parameters.

The following visualization shows an interaction plan that routes interactions to a virtual agent, and collects data about the interaction:

...

To route an interaction to a virtual agent within Virtual Assistant, using the example above, create the following applets:

...

Create virtual agent session (Data Connector applet)

In the Interface list in the Interface section, click Web Service, and in the Action list in the Action section, click Call Web Service.

...

  • X-Vgai-Key. Either hardcode the API key for the Vonage AI API or get the value for this header from a custom configuration value in your account. For more information about using custom configuration values, see Using a custom configuration value in a Web Service Interface request
  • agent_id. The value for this body parameter is the ID for the virtual agent that you want to use for the session. You can get the agent's ID from Vonage AI Studio. For information about the agent's virtual number, see What are Vonage AI Studio agents?.

You can also provide optional parameters as metadata. You must define these parameters in Vonage AI. For example, to provide the customer name, define a parameter in Vonage AI with the name CALLER_NAME, and then specify the following in your data connector:

Code Block
languagexml
titleCaller Name
<Body><![CDATA[ 
{
  "agent_id": "65d9634bf3a2412eb16e7adf",
  "parameters": [
    {
    "name": "CALLER_NAME",
    "value": "$(Name)"
    }
  ] 
}
]]></Body>

Store the session_id and session_start_time from the response in SessionId and SessionStartTime data sources respectively. Subsequent applets require these values.

Code Block
languagexml
titleInteraction Definitioncollapsetrue
<ApiInteraction>
  <Request>
    <Url>https://stairway.ai.vonage.com/flow/init</Url>
    <Method>POST</Method>
    <Headers>
      <Header>
        <Key>X-Vgai-Key</Key>
        <Value>#(api_key)</Value>
      </Header>
    </Headers>
    <Body><![CDATA[
{
  "agent_id": "65d9634bf3a2412eb16e7adf"
}      
    ]]></Body>
  </Request>
  <Response>
    <Type>JSON</Type>
    <ResponseCodeDestination>CreateSessionResponseCode</ResponseCodeDestination>
    <Fields>
      <Field>
        <Locator>session_id</Locator>
        <Destination>SessionId</Destination>
        <DataType>string</DataType>
      </Field>
      <Field>
        <Locator>session_start_time</Locator>
        <Destination>SessionStartTime</Destination>
        <DataType>string</DataType>
      </Field>
    </Fields>
  </Response>
</ApiInteraction>

For information about using a Data Connector applet, see Retrieving data from and sending data to a Web Service.

...

Transfer to a virtual agent (Virtual Agent applet)

This applet transfers the interaction to a virtual agent within Virtual Assistant.

...

Set Virtual Agent Number to the number of the same agent that you used to create the session. You can get this number from Vonage AI Studio. For information about the agent's virtual number, see What are Vonage AI Studio agents?.

Set Vonage AI Session Id to the value of the SessionId data source collected by the Data Connector applet (Create virtual agent session). Example: $(SessionId)

Transfer to a virtual agent

For information about the Virtual Agent applet, see Virtual Agent applet.

...

Collect virtual agent session data (Data Connector applet)

In the Interface list in the Interface section, click Web Service, and in the Action list in the Action section, click Call Web Service.

...

Code Block
languagexml
titleInteraction Definitioncollapsetrue
<ApiInteraction>
  <Request>
    <Url>https://stairway.ai.vonage.com/insights/sessions/$(session id)?session_start_time=$(session start time)</Url>
    <Method>GET</Method>
    <Headers>
      <Header>
        <Key>X-Vgai-Key</Key>
        <Value>#(api_key)</Value>
      </Header>
    </Headers>
  </Request>
  <Response>
    <Type>JSON</Type>
    <ResponseCodeDestination>Session</ResponseCodeDestination>
		<Fields>
  		<Field>
    		<Locator>params_list</Locator>
    		<Destination>params_list</Destination>
    		<DataType>string</DataType>
  		</Field>
    </Fields>
  </Response>
</ApiInteraction>

For information about using a Data Connector applet, see Retrieving data from and sending data to a Web Service.

...

Extract specific virtual agent data (Data Connector applet)

In the Interface list in the Interface section, click Web Service, and in the Action list in the Action section, click Call Web Service.

...

Code Block
languagexml
titleInteraction Definitioncollapsetrue
<ApiInteraction>
     <Request>
       <Url>$(JavascriptEngineUrl)</Url>
       <Method>POST</Method>
       <Body><![CDATA[{"script": "function findValueWithName(p, name){ for(var i=0;i<p.length;++i){if(p[i].name==name){return p[i].value;}}return '';} var params_list=$(params_list:EscapeDoubleQuotes); result={'Drink':findValueWithName(params_list,'Drink'), 'PizzaType':findValueWithName(params_list,'PizzaType'), 'PizzaSize':findValueWithName(params_list,'PizzaSize')};"}]]></Body>
       <Headers>
        <Header>
        <Key>Content-Type</Key>
        <Value>application/json</Value>
        </Header>
      </Headers>
     </Request>
     <Response>
       <Type>JSON</Type>
       <ResponseCodeDestination>ResponseCode</ResponseCodeDestination>
       <Fields>
         <Field>
           <Locator>result.Drink</Locator>
           <Destination>DrinkValue</Destination>
           <DataType>String</DataType>
         </Field>
         <Field>
           <Locator>result.PizzaType</Locator>
           <Destination>PizzaTypeValue</Destination>
           <DataType>String</DataType>
         </Field>
         <Field>
           <Locator>result.PizzaSize</Locator>
           <Destination>PizzaSizeValue</Destination>
           <DataType>String</DataType>
         </Field>
       </Fields>
     </Response>
</ApiInteraction>

...

Code Block
languagejava
titleJSON responsecollapsetrue
"params_list": [
	{
		"name": "Drink",
		"entity": "6033d12edaef26e8a42d2b50",
		"value": "Coke",
		"value_text": "Coke",
		"collected": true,
		"alteration_source": "collected",
	},
	{
		"name": "PizzaType",
		"entity": "6033d12edaef26e8a42d2b51",
		"value": "Cheese",
		"value_text": "Cheese",
		"collected": true,
		"alteration_source": "collected",
	},
	{
		"name": "PizzaSize",
		"entity": "6033d12edaef26e8a42d2b52",
		"value": "Medium",
		"value_text": "Medium",
		"collected": true,
		"alteration_source": "collected",
	}
]

...