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

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.

Related

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.

How to clear the session between two consecutive intents?

We are using bot trees master which uses bot graph dialog for loading graph based dialogs dynamically. We have created a scenario to load multiple intents(whose intents scores are nearly matching). Now the problem I am facing is when I request for single intent , I am getting the bot response and able to enter into next intent but when I request for multiple intents bot is giving the response and when I request for another intent , bot is giving the same response of multiple intents. When bot is entering into multiple intent handler it is not clearing the session and not coming out of that handler. I have tried using session.endConversation().
To understand about bot graph dialog:
https://www.microsoft.com/developerblog/2016/11/11/extending-microsofts-bot-framework-with-graph-baseddialogs-/
Can somebody help on this. Thank you
the builder.IntentDialog() used in this project is no longer considered a best practice. Additionally, further support is not expected. Instead, you will want to use bot.Dialog() to create your dialog flows with a .triggerAction(). The trigger matches on phrases which you can set a score to. Unfortunately, it means you will need to recreate the bot-trees project to fit this new model.
You can find information on managing conversations here, including creating triggers.
If you need a more robust system, you can integrate LUIS into your project. Information regarding recognizing intents with LUIS can be found here.

Port existing custom chatbot as Google Assistant action

We have a framework that implements chatbot / voice assistant logic for handling complex conversations in the health domain. Everything is implemented on our server side. This gives us full control of how responses are generated.
The channel (such as Alexa or Facebook Messenger cloud) calls our webhook:
When user messages, the platform sends these to our webhook: hashed user id, message text (chat message or transcribed voice)
Our webhook responds with the appropriately structured response, which includes text to be displayed, spoken, possibly choice buttons and some images etc. It also includes a flag whether the current session has finished or user input is expected.
Integrating a new channel involves conversion of the response returned into the form expected by a channel and setting some flags (has voice, has display etc.).
This simple framework has worked so far for Facebook Messenger, Cortana, Alexa (a little bit of hacking was needed to abandon it's intent and slot recognition), our web chatbot.
We wanted to write a thin layer of support for Google Assistant action.
Is there any way of passing all the input from Assistant user intact into a webhook such as the one described above and taking full control of the way responses are generated and the end of conversation is determined?
I'd rather not delve into those cumbersome ways of API.AI of structuring a conversation which seems good for a trivial scenarios such as ordering an Uber but seems very bad for longer conversation.
Since you already have a Natural Language Understanding layer for your system, you don't need API.AI/Dialogflow, and you can skip this layer completely. (The NLU is useful, even for large and extensive conversations, but doesn't make sense in your case where you've already defined the conversation through other means.)
You'll need to use the Actions SDK (sometimes known as actions.json after the configuration file it uses) to define triggering phrases, but after that you'll get all the text that the user says as part of your conversation through a webhook that delivers JSON to you. You'll reply with JSON that contains the text/audio response, images on cards, possibly suggestion chips, etc.

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 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