In this How-To, we will explore a scenario in a Virtual Assistant, say a Travel Planning Assistant, where the user needs to be provided with weather updates daily for a preferred location. We will be using an Alert task to achieve this. We will also see how auto subscription can be enabled on this Alert task, making it smart.
For details on what an Alert task is and how it is implemented in the Kore.ai XO Platform, refer here.
Problem Statement
A registered user of a Virtual Assistant needs to be sent a weather update in the form of an alert, at a pre-specified time of the day and/or at a specified interval of time.
In this document, we will show you how an Alert Task can be used to cater to such situations and take appropriate action.
Prerequisites
- A working assistant, we are using a Travel Planning Assistant.
- Access to a web service that provides weather updates. We are using a REST service hosted at: http://api.openweathermap.org. If you want to use this service, you need to register to their free alert service as we will be using the API key to access their APIs.
Implementation
Set Up an Alert Task
Alert tasks can be used to deliver timely, relevant, and personalized information from enterprise systems to customers and employees by polling the relevant service in real-time or according to a user-defined schedule.
- From Build > Conversational Skills add an Alert Task.
- On the task details page:
- Enter a Task Name, say Get Daily Weather
- Choose the Connection Type, we will go with Webservice
- Choose the Connection Mode, we will be using REST
- Click Create & Proceed.
- You will be directed to the Alert Settings page
- Review and modify the General Settings if needed. For our use case, we do not need to modify any settings here.
Configure the API Request
- Select the API Request tab
- Ensure that the Content Type is set to JSON
- We do not need to set the Authorization Provider for our use case. Configure it if the API you are using has any authorization requirements.
- Set Parameter to gather the preferred City from the User. Ensure that it is set as a Mandatory field. This is the API requirement.
- We will not need any Initializer requirements for our use case. Use this in case any JavaScript needs to be executed before the request is sent.
- Under Request click Add API to add the service API that needs to be invoked. We are using a GET method from the following API:
http://api.openweathermap.org/data/2.5/weather?q={cityname}&APPID=<your-app-id>
- The APPID in the above url is assigned to you by OpenWeather when you sign up. You can find it from the API keys section after you login to your account.
- Notice that the Parameters list is populated automatically with the parameters entered earlier.
- Save the API.
- Test the API to ensure that the configuration is proper. Enter a sample city name, when prompted and ensure you get a success message and a proper Response.
- Save your settings.