1. Home
  2. Kore.ai Conversational Platform
  3. Bot Builder Tool
  4. Develop
  5. Dialog Task
  6. Working with the Service Node

Working with the Service Node

The Service node is a component type in a dialog task that you can use to add an API service to make REST or SOAP requests to third-party web services. You can use this node when you have collected the parameters needed for the API request using Entity or other nodes to capture the user input. You can define the Service Type for this node as one of:

  • Custom Service – Define an API request to a third-party web service. This is the default setting.
  • HTML to Image – Define HTML to render as an image using JavaScript. For example, you want to compose HTML or the value of a key in a web service response contains HTML markup as a string that you want to convert to an image.
  • URL to Image – Define a web page URL to load to render an image.
  • Alert Subscription Service – Define contextually relevant alerts to be sent proactively to the user as a part of the dialog journey.

To create a Service node

  1. Click the Plus icondiydialogtaskplusicon where you want to add a new Service node,
  2. Select Service, and then click New Service Node.
  3. A new default Service node is added, and the Component Properties panel is displayed.
  4. In General Settings, enter the name of your Service node in the Name field, for example, FetchWeather.
  5. In the Service Type field, select one of:
    • Custom Service – Define an API request to a third-party web service. This is the default setting.
    • HTML to Image – Define HTML to render as an image using JavaScript. For example, you want to compose HTML or the value of a key in a web service response contains HTML markup as a string that you want to convert to an image.
    • URL to Image – Define a web page URL to load to render an image.
    • Custom Authentication Service – Define a URL to a third-party application that provides the authentication services necessary for the task flow. Learn more.
    • Alert Subscription Service – Define contextually relevant alerts to be sent proactively to the user as a part of the dialog journey.
  6. In the Request Definition section, click Define Request. The Define Request for < ServiceXXXX > dialog is displayed. Depending on the Service Type selected, see one of the following sections in this topic:
    Note: In the case of Custom Authentication Service, the Request Definition section doesn’t apply and you can see a Response section instead. Learn more. 

Defining a Custom Service

  1. When Custom Service is selected for Service Type, then in the Sub-Type field, select one of:
    • REST – The API web service is using REST services.
    • SOAP – The API web service is using SOAP services.
  2. In Request Definition section, click Define Request to specify the settings for the web service type. The Define Request for < Service Node Name > dialog is displayed as shown in the following illustration.
  3. In the Request URL field, in the first field, select the HTTP method used for the request. One of:
      • POST – Used to send data to the server, for example, customer information, file upload, and so forth using HTML forms.
      • PUT – Replaces the content of the target resource with the content sent.
      • PATCH – Appends the content of an existing target resource with the content sent.
      • DELETE – Deletes the content of an existing target resource.
      • GET – Returns the content of an existing target resource.

    NOTE: For SOAP services, you can pass the XML payload in the ‘body’ by using the POST method

  4. In the second field of the Request URL, specify the URL for the Dialog task response to process at Kore.ai, for example, http://koremessenger.com/postURL. Add query or path parameters as part of the URL, if required. To use Entity node values as parameters, use the following syntax for accessing the Context object: https://myDomain.com/{{context.entities.topic}} for the context.entities.topic. You must use the double brackets {{ context.object }}. For more information, see the Context Object.
  5. Optionally, click Show Advanced, and then select Yes in the Access Using A Connector field if access for Kore.ai Bots are using the Kore.ai Connector agent. For more information, see Using the Kore.ai Connector.
  6. On the Auth tab, select the type of authorization needed for this Service node call, or define a new authorization type if needed. For more information, see Setting Up Authentication for Action Tasks.
  7. On the Headers tab, specify the headers as key/value pairs if  required to access the specified Request URL.  Authentication headers are auto-generated based on the authorization type specified on the Auth tab. You need to define any other standard headers, for example, Content-type, Accept, etc. or any custom headers. Headers defined here are only applicable to this Service node.
  8. On the Body tab, select the body content type. One of:
    • application/x-www-form-urlencoded – Also known as Multipart/Form-data, which is an encoding type that allows files to be sent through an HTTP POST request method, if you want to allow a user to upload a file from a form. You can add key/value pairs which are encoded by the Bots platform.
    • application/json – Use JSON to transmit data between the Kore.ai servers and your Bot web application. Any JSON is sent with the request without any processing.
    • application/xml – For SOAP services, pass XML payload using POST methods. You can pass Entity node values as part of the XML, using the following syntax for accessing the Context object: https://myDomain.com/{{context.entities.topic}} for the context.entities.topic. You must use the double brackets {{ context.object }}. For more information, see the Context Object.
  9. On the Test Request tab, click Test to optionally send your API Request URL, using the specify Auth type, HTTP headers and body parameters, if defined. The response is displayed in the text area. Click Save as Sample Response to save the test response as the sample response for this node.
  10. In the Service Properties section, in the Sample Response section, optionally click Add Sample Response to display the Add Sample Response dialog that you can use to manually enter or paste a sample response.
  11. Optionally, in the Add Sample Response drop-down list, select one of:
    • JSON – A list of JSON key/value pairs available in the Request URL response that can be used in other nodes as variables.
    • RAW – A list of key/value pairs that can be used in other nodes as variables.
  12. Click Save to save the request for the Service node and close the Define Request for < Service Node Name > dialog.
  13. In the Component Properties section, under Advanced Controls, you can configure the Timeout for terminating the service call. By default, it is set for 20 seconds, you can choose a value anywhere between 5 to 20 seconds.
  14. In the Instance Connections section, specify one or more Connection Rules to transition from the Service node to the next node. For more information, see the Defining Instance Connections later in this topic.

Defining a URL to Convert to Image

  1. When URL to Image is selected for Service Type, the Type setting is read-only.
  2. In the Request Definition section, click Define Request to specify the settings when URL to Image is selected for Service Type. The Define Request for < Service Node Name > dialog is displayed as shown in the following illustration.
  3. In the URL to Convert field, enter the URL for the image. The syntax when using a Context object key in a URL is to enclose the object name in double brackets, for example, https://myURLimage.com/{{context.entities.imageName}}.
  4. In the Render Sizes section, specify a name for the image size, for example iPhone or tablet, enter the Width and Height in pixels, and then click +Add to add additional sizes, or click Add to save and close the dialog.
  5. Click Save to save the request for the Service node and close the Define Request for < Service Node Name > dialog.
  6. In the Instance Connections section, specify one or more Connection Rules to transition from the Service node to the next node. For more information, see the Defining Instance Connections later in this topic.

Defining HTML to Convert to Image

  1. When HTML to Image is selected for Service Type, the Type setting is read-only.
  2. In Request Definition section, click Define Request to specify the settings when HTML to Image is selected for Service Type. The Define Request for < Service Node Name > dialog is displayed as shown in the following illustration.
  3. In the HTML to Convert field, enter the HTML for the image.
  4. In the Render Sizes section, specify a name for the image size, for example, iPhone or tablet, enter the Width and Height in pixels, and then click +Add to add additional sizes, or click Add to save and close the dialog.
  5. In the Instance Connections section, specify one or more Connection Rules to transition from the Service node to the next node. For more information, see the Defining Instance Connections later in this topic.

Example HTML Definition

The following is an example for converting HTML to an image:

<head>
<link href="../assets/styles.min.css" rel="stylesheet"/>
<title>HTML: Print Wide HTML Tables</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
  .style1 {
     border-collapse: collapse;
     }
  .style1 th {
     background-color: #DDDDDD;
     white-space: nowrap;
     }
  .style1 .d {
     white-space: nowrap;
     }
  .style1 .n {
     padding-left: 20px;
     text-align: right;
     }
</style>
</head>
<body>
<table id="table1" class="style1" border="1" cellpadding="4" cellspacing="0">
  ///TODO Add Table Rows here.
</table>
<input type="button" id="print-button" value="Make this table printable contact@ {{context.session.UserContext.emailId}}"/>
<script>
/*
 * HTML: Print Wide HTML Tables
 * http://salman-w.blogspot.com/2013/04/printing-wide-html-tables.html
*/
$(function() {
$("#print-button").on("click", function() {
   var table = $("#table1"),
       tableWidth = table.outerWidth(),
       pageWidth = 600,
       pageCount = Math.ceil(tableWidth / pageWidth),
       printWrap = $("<div></div>").insertAfter(table),
       i,
       printPage;
   for (i = 0; i < pageCount; i++) {
      printPage = $("<div></div>").css({
          "overflow": "hidden",
          "width": pageWidth,
          "page-break-before": i === 0 ? "auto" : "always"
        }).appendTo(printWrap);
   table.clone().removeAttr("id").appendTo(printPage).css({
      "position": "relative",
      "left": -i * pageWidth
     });
   }
 table.hide();
 $(this).prop("disabled", true);
});
});
</script>
</body>
</html>

The preceding HTML example, when table rows are added into the example, can render the following image to an end-user.

HTML Image Example

Defining Alert Subscription Service

You can now automatically subscribe your bot users to send contextually relevant alerts as part of the dialog journey. For example, a person booking a flight ticket for a specific date can be auto-subscribed to get regular updates on the weather forecast for the destination city.

To set up an Alert Subscription service

  1. Open the Properties panel of the Service Node to which you want to associate the alert.
  2. In the Service Type drop-down list, select Auto Subscription Service.
  3. Click Define Request. It opens the Smart/Automatic Alerts dialog.
    Note: To create an Alert Subscription service, you must base it on an existing alert task. Users will be auto-subscribed to the alert task on reaching the associated service node in the dialog.
  4. From the Choose Alert drop-down list, select an alert task. The list consists of only the published alert tasks related to your bot.
  5. Enter the necessary information as explained below.

Alert Subscription (Smart Alert) Configurations

In a typical alert setup, the alert parameters, filters, and other necessary details are entered by the bot users. Since this is an auto-subscription for alerts, you need to configure those details as a developer.

ALERT PARAMETERS

These vary according to the alert you select. Provide the default parameter values to be used for the Alert Subscription service.

In this example, the parameters to be defined for the alert are Topic name and News Region. Since the idea is to send weather forecast to the user for the destination city, you could set the parameter values are Weather Forecast and context.entity.destinationcity respectively.

FILTERS

These vary according to the alert you select. Provide the filter criteria to be used for the Alert Subscription service.

ALERT FREQUENCY

Provide the frequency for sending alert notifications. You need to select a Scheme, Frequency and a Time Frame.

  • From the Select Scheme drop-down, select daily, weekday, or weekend, depending on when you want to send the alert.
  • From the Select Frequency drop-down, select Every if you want to send the multiple alerts at regular intervals of time in a day or select at to send one alert a specific time of the day.
  • From the Select Time drop-down, select an interval time value or a time of the day, depending on the frequency value chosen above.

In our example, we have selected Daily At 6 a.m. which means an alert is sent to the user every day at 6 a.m.

SMART ALERT EXPIRY

Configure when to expire sending alerts to the users from one of the following options:

  • Duration: Stops sending notification after the entered number of days from the date of subscription.
  • Number of Notifications: Stops sending alerts after an entered number of notifications are sent.

ALERT UPGRADES

Define the expected behavior of this alert if an upgraded version of the underlying alert task (the published alert that you have selected at the beginning) is published.

  • Remove Existing Instances
    All existing subscriptions of this smart alert will be removed and users will no longer receive notifications. Users will be auto-subscribed to the upgraded alert task only when they execute the dialog and reach the service node in the dialog journey.
  • Allow Users To Manually Upgrade Subscription
    Users will receive an Upgrade notification on the selected channel which a link that guides them through to upgrade their auto-subscription. If the upgrade is successful, the user will receive a success notification.

Defining Instance Connections

Instance connections help define the conditions for the transition between nodes and control the flow of conversation. Developers can opt to define the conditions based on:

  • Simple If-then-else condition
  • Write a rule-based expression

You must define a fallback condition for every node. A node can be marked to be the last node for dialog task completion.

Properties Panel

Specify the following properties for each Service node.

Connections

  • Connection Rules

Component Properties

  • General Settings
    • Name
    • Service Type
    • Type
  • Request Definition
  • Sample Response (Customer Service Only)

Articles

Was this article helpful to you? Yes No 2