I thought that I had already answered this question on my website, but on checking again, I see that I haven't.
So let us understand the question:
When you work with API.AI you notice that it follows the "user types something -> agent replies with an answer" sequence. Suppose you wish to get the agent to say something before the user types anything, how do you do it?
In my CourseBot, I initiate the conversation by using the same ideas described on this page - except that I use Dialogflow API v2 while this article talks about v1.
What is an Event in API.AI?
In API.AI, the Event has a very specific meaning: you can "call" an event to trigger a specific, corresponding intent.
From the API.AI docs:
Events is a feature that allows you to invoke intents by an event name instead of a user query.
First, you define event names in intents. Then, you can trigger these intents by sending a /query request containing an
For example, in all the agents you create, you will see the DEFAULT Welcome Intent.
On clicking into the intent, you see the following:
The word WELCOME, under the Event section, can be used as a "trigger" to get the Default Welcome Intent to fire without the user typing any message. You can change the word to any other string you like, but you must call the same string to invoke the event later.
So you might be thinking: that's great, but if the user doesn't type anything, then how can we call the event?
This is where you need to use the REST API interface exposed by API.AI.
The Client Access Token
For each agent you create, under the Settings, you will see something called the Client Access Token. Copy it into a file/clipboard for later access.
Send a HTTP Request to call the Event
Now you are ready to issue a command to your API.AI agent to invoke the default welcome intent.
You need to send a request to API.AI. If you were to use cURL (a command line utility for sending HTTP requests) it will look like this (note: it is a single line. I added line breaks for clarity)
curl -H "Authorization: Bearer YOUR_CLIENT_ACCESS_TOKEN"
This is the value of the client access token you copied
Use WELCOME as the event_name
Use an appropriate identifier as a session ID. The session here means a single conversation with a user and is used to manage the state of the conversation (don't worry about it if you don't understand this at this point)
The version 'v' is the date of the API version you wish to use. Say there are three versions of the API released on the following three dates:
1 Jan 2017
25 Feb 2017
15 Mar 2017
v = 20170101 will correspond to the API.AI version which was released on 1 Jan 2017
v = 20170225 will correspond to the API.AI version which was released on 25 Feb 2017
v = 20170318 will correspond to the API.AI version which was released on 15 Mar 2017
and so on. Notice that it doesn't have to match the exact date. It will just use the version which was most recent when compared to the date you send through.
How to send the request from code
You will incorporate something similar to the request you saw above into your code. I will write more about this in a future article, but all programming languages will usually have helper libraries which will help you construct these HTTP requests.