Dialogflow CX - How to make an API Call to a specific Flow - dialogflow-es

How can I make a Google Dialogflow REST API call to a specific flow? I basically want to query an intent detection for a different flow other than the "Default Start Flow".
For example I can use this link to make an API call:
https://{endpoint}/v3/{session=projects/*/locations/*/agents/*/sessions/*}:detectIntent
Except it will use the Default Start Flow.

I just realized that it does not make sense to do this, what we should be doing instead is creating a route from the "Default Start Flow" to the other Flow

According to the Dialogflow CX request documentation you can specify a "currentPage" parameter. Dialogflow will start intent recognition from that page instead of the "Default Start Flow". This allows you to directly jump into a specific entry point of another flow.
Note: previous state, including parameters, will be ignored. So if parameters have already been set, they should be passed along as well.

Related

Do we need webhook when our server is interacting with dialogflow?

We are implementing our customized chatbot using dialog flow. When user enters any text, our javascript code sends this text to our python server and the server interacts with google dialog flow and server gets complete response. I just have couple of questions as below.
When server gets the response from dialog flow, it will process the
response and sends some response to UI. Do we still need to have
fulfillment enabled as our server is getting response? Basically if
server is interacting with dialog flow and getting response, what is
the use of webhook?
Is there anyway to enforce the dialog flow intents require at least
one of entities? I went through Can I make Dialogflow intents require atleast one of the trained entities? which says to enable webhook fulfillment for that intent and if no entities were provided, re prompt the user for at least one of a list of entities. So in my case, if webhook is not needed, do I need to do it in the server once server receives response or is there anyway dialog flow will automatically enforce the condition with out server taking the responsibility?
In your case, no, you don't need to use webhook fulfillment.
You may still wish to use it, however, if you want to separate business logic (which would be in the webhook) from UI/UX logic (which would be in your python server and in the javascript client). But there is no requirement that you separate things this way.
Similarly, you can use your python code to enforce "at least one of" the parameters matching - you're moving that logic from the webhook into your existing server.
Either way, this is a bit kludgy. One alternative if you have different entity types is to have multiple Intents, one for each possible type, and to mark the parameter as required. This way the Intent will only match if the parameter is provided. If you then need to report each of these Intents as the "same" Intent, you can add that logic to your python code.

Dialogflow Integration into Custom CRM

I am trying to wrap my head around using Dialogflow for developing and integrating an SMS chatbot with our custom CRM. The creation of an Intent is pretty powerful and straight forward. However, I am trying to understand best practices for something. If I have an intent used to return the price of a service at a certain location, I can model that very easily within dialog flow. However, when an SMS message comes in, it will be from a new customer or a known existing customer for a certain location. For existing customers, we already know the location and therefore don't want them to have to specify the location value in the intent. Prior to sending the inbound SMS message to the client API to match the intent, how can I pre-set the "location" parameter value in the intent so it does exists even if that inbound SMS message did not include it? For example a known customer in Dallas would just have to say "how much is a xxx" instead of "how much is a xxx in Dallas".
Can you use the API to set a parameter value prior to calling the API to try and match the intent? If so, how do you get do that without a session ID? The reason the "location" is needed is because when we get to the fulfillment, the prices for the same service are different based on the location so I will need to be known but we don't want to make existing customers say the location.
Maybe another option is to have a Location intent with an event that we can trigger through the API. this would have an output context on it called location and fulfillment that sets the parameter value. But even then I struggle with understanding how to pass in values like location, phone number, etc into dialogflow from the calling application so dialogflow has those parameter values to use in fulfillment.
Reading documentation, watching videos and starting to test client API v2
This is certainly possible. What you would want to do is use the Dialogflow API for this. Here you can find the languages for which Google has created client libraries: https://cloud.google.com/dialogflow/docs/reference/libraries/overview
As soon as you have any 'if' in your code you should use the fulfillment: https://dialogflow.com/docs/fulfillment
How I would handle this:
Client sends SMS
You check in your back-end if this user is known. If known -> don't ask location, else you ask the location
Match the user query against the Dialogflow client library
Dialogflow will return the intent if (any) is matched
You should define and implement any logic before calling the Dialogflow library.

Server-side query using events or/and context?

I’m coding a bot using PHP-BotMan for complexity reasons and using Dialogflow query api to extract and manipulate the informations from the response. I saw examples and hints from people here and on dialogflow forum suggesting using context or events, some of them mixing both. What is the better way to handle this?
The flow of the application is:
user messages bot
bot queries (text or/and #event?) dialogflow
internally process a reply or return dialogflow slotfilling* request
text response bot reply user with last reply or asking to fill slot
Also, how can I be sure that a slotfilling process is finished with “actionIncomplete” only having two values, NULL or TRUE? The dialogflow query response doesn’t show wich slotfilling parameters are required or not…
Thanks for the help!!
slotfilling is when dialogflow sends a text response requesting required parameters to finish an intent, adding those replied values to the context
I was trying something similar to your scenario, here are few points i found helpful:
When Slotfitting with webhook, i can't use the "Required" params field since i have to control the input parameters via webhook (query database to provide options). Which means actionIncomplete field is not useful anymore.
I personally prefer to use context as it can add/remove params which gives you more control.
Hence the dialog was designed to use webhook to check all required params before move on to next conversation flow. and pop quick replies menu to ease and restrict possible input from users.
HTH.

How to call functions from an external js file using api.ai

I want to perform action from a js file when a certain intent is matchef; For example, If user says, "Show me levis jeans", I want to call a search function from my file which returns a result. If this is not viable, please explain how to make api calls from the agent itself.
Yes, you do this with the webhook functionality.
On the page where you configure your intent, go down to the very bottom and click on fulfillment and then check 'use webhook'.
Now go to the fulfillment page and configure you webhook.
There is more info here.

How to get dynamic response based on the result of the action performed in Api.ai?

I'm trying out few examples in Api.ai console. I see there are examples where the agent responds by using the values that are extracted from the user query or from the context. But is there a way to display response that is formed using the output of the action performed?
For example -
User: Is my pizza order confirmed?
Action: check order status
Response: Yes, it's confirmed (or "No, it's not")
You will have to use some custom webhook to do this, either integrating with a 3rd party API or will a server side call of your own to a database- in this case the webhook would take the user's ID and query if their pizza is ready or not, and this would then be passed back to API.ai.
Here is an example using a 3rd party webhook to do what you are asking:
https://github.com/api-ai/apiai-weather-webhook-sample
Yes you can do this with webhooks.
Typically, you would save the status of the order in your db, then you could have an intent that would:
Understand the query of your user (Is my pizza order confirmed)
The intent would call your webhook
the webhook would return the status order.
Api.ai would then give the answer.
When you use webhooks you need to return the speech response, the displayText, optionally the data that your apps need, the contextOut and the source.
I guess you would also need to have implement some context in api.ai so that you could now who is asking about the satus of the order. You would then be able to use the sessionId
Matt is correct here. You must use a webhook. Unfortunately the documentation from API.AI is currently very poor. Here's a screenshot example of an incoming post request. My message function will return an object with a desired response. In this case, I am using a Telegram chat bot. If you are not using any messenger, you can drop the data key: value. FollowupEvent is also optional.
Node.JS code with Restify
On your API.AI intent, make sure to check off Webhook. If you end getting the text response 'Broken' here, then something went wrong and you should check your error codes.
API.AI intent
And lastly, under the fulfillment tab, make sure to enable the webhook and point it at the right endpoint.

Resources