DialogFlow within Android

Fares Othmane Mokhtari
Dev TEch
Published in
5 min readOct 28, 2018

recently I have participated as speaker in devfest 18 , in Algiers and my talk was about Dialogflow, something inside me tells that a talk of 20 minutes is not enough to make an overview of DialogFlow ad how can we use it in different scenarios, so I decided to share some posts about it and how can we use this Api as Android developer .

history of DialogFlow :

Dialogflow (formerly API.ai) was created in 2014 by a company named speaktoit and it is the same company who developed the famous assistant app in 2011 for android users. this company has been bought by google in 2016 and in 2017 the api.ai was renamed to Dialogflow.

Overview of dialogFlow

dialogflow allows us to build a conversational interface by using a natural language understanding (NLU) engine, but wait what is a NLU?

Natural-language understanding is a subtopic of natural language processing Natural-language understanding is considered a hard problem in AI .”

Ok! we got it, we have to deal with a lot of mathematics equations to build an app which support NLU.

no, no and no ! we don’t have to worry about this, thanks goodness, because DialogFlow is an API so we have just to use it without worry about the machine learning algorithms behind it .

so let’s have look at dialogflow .

to use Dialogflow you have just to login by using your Gmail account and oups! we’re inside our API as shown in the figure bellow

we can divide this screen into three parts , at the left we have the main tasks (intents, entities, fulfillment,integration , and training ), on the right we have the simulator and the in the middle is the main part in which we are going to build our agent.

Agents are best described as Natural Language Understanding (NLU) modules. These modules can be included in your app, website, product, or service and translate text or spoken user requests into actionable data. This translation occurs when a user’s utterance matches an intent within your agent.

so let’s build our agent together and explain what each tasks does are you ready ! let’s go

  1. to create an agent you just need to write the name of the agent and press on create button as shown in picture above (my agent called mindorks once created we can start create intents

2 Intents :

intents are dialog turned within a conversation ! but what does it mean that ? in fact an intent is a map between a user input and and the agent output and there are three components of the intent:

  • intent name : The name of the intent. The intent name is passed to your fulfillment and identifies the matched intent.
  • training phrases: some examples given by developer of what user can say.
  • actions and parameters : parameters are piece of information extracted from the user and actions are something generated by the intents to recognize them when we implement our business logic in webhook (don’t worry about his we’re going to talk about it bellow ) .
  • response:utterance that display to the user .

it is important to talk about the contest, because the human conversation is usually relies on the context , so DialogFlow allow as to implement the context to build a real conversation experience , so what is the the context.

Context:

context allows the developer to control the conversation, so the dialogflow matches the user input with different intent to answer with the right response as illustrated in the figure bellow .

screen shot from https://dialogflow.com/docs/agents

but when we add the context to an intent the agent is only considering that intent for matching if the context is active.

there are two types of context :

  • Input contexts: the input context tells the agent do not take into consideration the intent until the context is activated .
  • Output contexts: , we use output context to activate a specific context after the user input is lose enough to the intent which the context is applied on.

2. entity:

is mechanism used by Dialogflow to extract data from user input,i have to mention that dialog flow has three types of entities:

  • system entities : which allow the agent to extract information about wide range of concepts ,for example, system entities are available for extracting dates, times, and locations from natural language inputs.
  • developer entities:it is clear as developer we have to work with our entities to extract information beyond those allowed by system entities
  • session entities : some times we need entities for special case and of the all the agent so we use session entities.

to create an entity you have :

  1. In the left menu, click Entities.
  2. Click CREATE ENTITY.
  3. Enter a name for the entity at the top of the page.
  4. Click in the first row and enter an entry.
  5. adding entries and synonyms.
  6. Click SAVE.

3. fulfillment:

fulfillment is a logic implemented on a server as webhook to extend an agent (for example to generate an answers based on the information got from the parameters)

when an intent integrated a fulfillment is matched , the agent makes http post request to the webhook with jason format .

4.integration:

dialogflow is cross cross platform, so after developing our agent we can deploy it in almost every social network in the world , and also we will be able to invoke it using google assistant .

5.Training :

so because our assistant can be integrated in every social network (that means many users can used it) so we need to train it , that is why we have a tab which allows us to read all logs and train our agent

I think now we have made a tour on Dialogflow api next time we will build an android app to chat with our agent .

--

--