Access data from Google sheets in DialogFlow's index.JS - dialogflow-es

I am very new to DialogFlow.
I need to access data from one of my google sheet .
How can I achieve this by coding in inbuilt Index.JS provided by DialogFlow

In your index.js, you'll need to setup Intent handlers for each Intent.
In those handlers, you can get the parameters from the Intent and then make calls to the Sheets API to get data based on those parameters.

Related

Any ideas/ examples on how to use the detect-intent api on dialogflow to read the intent from a json file?

Any idea or examples as to how to detect intent using the Dialogflow detect-intent api(https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.sessions/detectIntent) from a JSON file?
Thank you in advance.
The function is supposed to be hosted on Firebase functions and I am using nodejs.
I will try to explain what I am trying to do.
So I have a bunch of Intents on Dialogflow already. And I know that the starting intent is going to be the Welcome intent. After the Welcome Intent I want to shape the conversation according to the intent list on the json file.
The entire flow is something like this.
Bot: Hello, What form would you like to fill up today?
User: Leave form
Dialogflow matches the leave form with the leave form entity and pulls the leave form json from the storage. The json will contain the fields that are required to be filled up for the form
Bot: Hi, so I would need some details to fill this form.
Bot: Let's start with your name ..... etc etc
So, instead of detecting the intent from the user's side, I need to detect what intent, from the json. The Webhook fulfillment is currently being hosted on Firebase functions and the json is being stored on Firebase Storage(not Database)
The Detect Intent API only helps you to detect the intent from the text sent by you to the Dialogflow agent using the API. So you cannot read the intent from the JSON file using the Detect Intent API, your intent must be imported to the Dialogflow agent.

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.

use dialogflow webhooks from alexa

I have developed a complex dialogflow bot, which uses complex dialogs to get data from user and then store it in database. And then give responses to users by querying db.
Can i use the same logic/webhooks/code to call from alexa skill? I don't want to write such a complex logic again for alexa skill.
What I want is whenever an alexa intent is called by user, i want to transfer that intent to my dialogflow webhook to handle it. Is it possible? If so then can you please provide any documentation/examples/tutorials ets.
My dialogflow model consists of 4 slot types:
Date
Number
any
some custom slots
I am certain this is not possible straight away as the REST API of Dialogflow will be different from that of Alexa. Also, Alexa is not fully supported for integration in Dialogflow like Facebook or Slack. If your code is well written and business logic is separate from the platform/request/response mapping then you will be able to use the same business logic in your Alexa webhook code. You just need to write the code for consuming the REST API of Alexa in this case.
Yes, this is possible. While Dialogflow and Alexa have different webhook JSON formats, fundamentally they both do the same thing. You will need to handle parsing the JSON to get what you need, and then formatting the response, so each uses their particular format - but the logic that you are using should still be sound and available to both.
Dialogflow lets you export the model into an Alexa compatible format that you can paste into the Alexa Skills Kit. This helps at least a bit.

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

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

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.

Resources