What is Dialogflow?
Dialogflow is a natural language understanding platform used to design and integrate a conversational user interface into mobile apps, web applications, devices, bots, interactive voice response systems, and related uses.
Why choose Dialogflow?
- Natural Language Processing(NLP)
- Compared to some platforms which works on predefined questions like Chatfuel, Dialogflow can offer better user experience with NLP. DialogFlow Agents are pretty good at NLP.
- Multi-channel easy integration
- Dialogflow provides one-click integrations to most popular messaging Apps like Facebook Messenger, Slack, Twitter, Kik, Line, Skype, Telegram, Twilio and Viber. Even to some voice assistants like Google Assistant, Amazon Alexa and Microsoft Cortana.
Under the Hood, how does it work?
- A user sends a text/voice message to a device or an App which is then passed on to Dialogflow
- The message is categorized and matched to a corresponding intent (Intents are defined manually by developers in Dialogflow)
- When a certain intent is found by Dialogflow, the webhook will use external APIs to find a response in external data bases.
- Intent generates actionable data acoording to different channels.
- The actionable data go to output Apps/Devices
What are intents?
An intent categorizes an end-user’s intention for one conversation turn. For each agent, you define many intents, where your combined intents can handle a complete conversation. When an end-user writes or says something, referred to as an end-user expression, Dialogflow matches the end-user expression to the best intent in your agent. Matching an intent is also known as intent classification.
A basic intent contains the following:
- Training phrases: These are example phrases for what end-users might say. When an end-user expression resembles one of these phrases, Dialogflow matches the intent. You don’t have to define every possible example, because Dialogflow’s built-in machine learning expands on your list with other, similar phrases.
- Action: You can define an action for each intent. When an intent is matched, Dialogflow provides the action to your system, and you can use the action to trigger certain actions defined in your system.
- Parameters: When an intent is matched at runtime, Dialogflow provides the extracted values from the end-user expression as parameters. Each parameter has a type, called the entity type, which dictates exactly how the data is extracted. Unlike raw end-user input, parameters are structured data that can easily be used to perform some logic or generate responses.
- Responses: You define text, speech, or visual responses to return to the end-user. These may provide the end-user with answers, ask the end- user for more information, or terminate the conversation.
Let’s get started
The first thing we should be doing is to create an agent.
Creating an Agent
Adding an Intent
What’s an Intent: When an end-user writes or says something, referred to as an end-user expression, Dialogflow matches the end-user expression to the best intent in your agent. Matching an intent is also known as intent classification.
Training Phrases
These are example phrases for what end-users might say. When an end-user expression resembles one of these phrases, Dialogflow matches the intent. For this demo. We will create: <DO THIS>
Responses
You define text, speech, or visual responses to return to the end-user. These may provide the end-user with answers, ask the end-user for more information, or terminate the conversation.
We define a custom response as marked in the screenshot
Testing out the Intent
In the console on the right, type in a request. The request should be a little different than the examples you provided in the Training Phrases section. This can be something like “What’s Lanschool”. After you type the request, hit “Enter/Return”.
Response – shows an appropriate response from the ones provided
Small Talks
Small talk is used to provide responses to casual conversation. This feature can greatly improve the end-user experience by answering common questions outside the scope of your agent. We’ve added 3 such as shown below
Integrations
Dialogflow integrates with many popular conversation platforms like Google Assistant, Slack, and Facebook Messenger. If you want to build an agent for one of these platforms, you should use one of the many integrations options. Direct end-user interactions are handled for you, so you can focus on building your agent
Chatting with Brian the Bot
Conclusion
As of v2.0 Dialogflow requires a server-side implementation. A RESTful API can be exposed and consumed by the client-side application. Basic Node.JS implementation shown below.
const dialogflow = require('@google-cloud/dialogflow');
const uuid = require('uuid');
/**
* Send a query to the dialogflow agent, and return the query result.
* @param {string} projectId The project to be used
*/
async function runSample(projectId = 'your-project-id', query) {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.projectAgentSessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: query,
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}
We’ve gone only through the basic services as of now, with more features out of the box, the use cases are limitless.
Leave a Reply