How can I trigger a dialogflow intent inside a javascript code? - dialogflow-es

I have a chatbot using dialogflow agent. I wrote a javascript back end code for its webhook fulfillment. I checked some condition in this code and if the condition is true I want a special intent to be triggered. How can I do this? What is the correct java script code to triggered an intent inside a java script if statement?

What function do you intend to perform by triggering an intent? Diaglogflow has v1 & v2 API references for this. You can do GET/POST/PUT/DELETE operations by triggering an intent using ajax call in your javascript code. Please read more about this here https://dialogflow.com/docs/reference/agent/intents

To make things clearer, DialogFlow intents are triggered by querying using the query API (https://dialogflow.com/docs/reference/agent/query)
Note: V1 of the DialogFlow API will deprecate soon, and will be replaced by V2 which is using gRPC.
This means that if you wish to trigger the intent programmatically and have the fulfilment triggered as well, you should have the following:
Script (can be on JavaScript as you would like to) with REST API request (doable using the Axios library) to the DialogFlow Query API.
DialogFlow will pick up the query, runs it through and triggers the Intent (if the query matches the intent).
In processing the intent, because there is a fulfilment, DialogFlow will run the fulfilment, which is another API/webhook call to your server hosted somewhere.
Your server will pick up the API request, and process accordingly.
Try out the Query API from DialogFlow and see if it works out for you.

Okay, I am late here, but I have used the below approach to encounter such a situation.
You can use custom event and intent chaining.
I followed the below URL and implemented the same. Maybe this help someone.
enter link description here

Related

How can I manage suicidal intents using actions-on-google npm package

My setup:
I'm using actions-on-google to create a custom action for google assistant, every intent is a fallback in dialogflow that is then redirected to my server where I check the intent with a custom nlp engine and then respond to it, using the actions-on-google package.
The issue:
But when an intent is suicidal, for example: "I want to kill myself", google stop the action and give a response instead of letting my custom action handle it. Is there a way to avoid this?, it also happens with certain words like "Save" in that case google stop the action and ask me if I want to save an event or whatnot.
Can I override this behavior?
You're running into a "feature" that Google calls "no-match yielding". In some cases, if you're using a Fallback Intent in Dialogflow, and the Google Assistant itself can handle the question - it will do so.
To avoid this you can use regular Intents that match the #sys.any System Entity.
However, if all you're doing for everything is sending it to your NLU, then you don't need to be using Dialogflow at all. You can just use the Actions on Google v2 to send all TEXT Intents to your NLU for processing.

Dialogflow query working in console but not when you use embedded url

I have made a query flow in dialogflow and it has four intent and in the last intent it uses a webhook to get data from server side and displays the result. It is trained automatically and works perfectly in dialogflow console returning response and query answer. The issue is it does not work when I use embedded url. It fails to recognize the name intent and asks (Can you repeat again or fallback intent). I've removed all intents and made query again, there is no similar name intents. Yet it works well in console and not in embedded url.
For the webhook part I've used node.js service.
Please help in this issue.
By 'embedded url' if you mean Dialogflow Web Demo (DWD), you should keep in mind that DWD can be used only for simple text messages. It does not support messages from webhook or even rich responses. However, if you steel need a web widget to embed your bot to your webpage you either create your own or you should use third party solutions (like Kommunicate). Here's the link regarding the limitations of DWD.

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.

Google Actions with custom webhook

I have built a small conversational bot using API.AI with Node.js as the back end. So every time a user makes a request it goes to my server and then from my server to API.Ai and it follows the same route with a response.
Now, I want to integrate it with Google Actions. But, Google Actions allows me to use API.AI as my webhook whereas I want Google Actions to talk to my server.
I have checked everywhere and can't find the correct process. Any, help will be appreciated in Integrating Actions with custom webhook instead of API.API
The normal way it would work would be to have the Google servers for the Assistant talk to API.AI, and then API.AI would call your webhook. This lets API.AI do all of the natural language processing (NLP) and not have you attempt to write this part yourself to load into the Actions console.
Your API.AI project and your Action project need to be the same - if not, you can create a new Action project using the same project as API.AI, or you can export the contents of your API.AI project and import it into a new one.
Your API.AI project also needs to have the Actions on Google Integration turned on. From the left menu, select Integrations and then the Actions on Google tile and turn it on.
However
If you want to send things through your server, and then have your server call the API.AI API yourself, you can certainly do this. You would develop against the Actions SDK and provide an actions.json file which describes the intents and webhook to use.

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