How to get user input from actions SDK(recent version).
In the previous version, we just use text intent like the example
app.intent('actions.intent.TEXT', async (conv, input) => {
console.log('input', input)
})
I want to get user input as we do get in the previous version but the previous version is deprecating.
How to get user input from the action builder?
In recent version they are providing intents, scenes, types etcc...
The custom NLU sample provides an example of sending the user's full text to your webhook to process.
It is accomplished through a simple user_utterance intent that accepts freeText and then calls a webhook.
Then your webhook can handle the intent's parameter:
app.handle('doAny', (conv) => {
const any = conv.intent.params.any.original;
conv.add(`You said ${any}.`);
});
Related
I am creating a chatbot using DialogFlow. Here, I am trying to get response from the API, which has been created by my development team (using python). They provided the API URL and requested to fetch data from it according to the users query. I have created a function in the inline editor and pasted the given API URL.
Below is the API format they have created,
{
“data”: [{
“pincode”: “”,
“location_formatted_address”: “”,
“user_id”: “”,
“department_name”: “Education”,
“locality”: “”,
“status”: “Select_Status”
}]
}
Here, when a user gives a department name, it must respond the user with locality of that specific department.
In the Inline editor, I have applied the following logic to fetch the locality,
function getDatafromApI(agent){
const name = agent.parameters.name;
return getAPIData().then(res => {
res.data.map(issues => {
if(issues.department_name === name)
agent.add(`${name}. ${issues.locality}`);
intentMap.set('Fetch API', APIData);
In the above code, "name" is the parameter given in the intent section.
But, I am not getting any response. Any help?
The inline editor uses Firebase. You will have to upgrade to Firebase "Blaze" OR "Flame" plan as the "Spark"(free) plan does not allow external api calls.
However if you have already upgraded Firebase plan and still seeing this error, you can see the execution logs by clicking "view execution logs" link at bottom of Dialogflow fulfillment window.
I am trying to connect my chat bot created using Dialogflow to the Google Cloud Firestore. I was thinking if I have to map the intent in the fulfillment one by one that'd be a huge amount of work.
Is it possible to write a fulfillment to detect the user input and maps to the intent then go on to query data from the Firestore?
For example, I would like the agent below to map the user input to the intent I already created then query
function intentHandler(agent) {
const userInput = request.body.queryResult.parameters['Entity_detected'];
}
Dialogflow provides default intent called Fallback Intent. It will be called when there is no matching intent found.
You can take advantage of this and call webhooks on this intent.
Checkout official document
You can indeed map to a different intent using the user input. For this you can use context to map to a different intent after sending a response. I've never tried it with entities, but I imagine it would be implemented something like this.
const userInput = request.body.queryResult.parameters['Your Entity'];
switch (typeof(userInput)) {
case SelectQueryEntity:
// perform select query
conv.ask("I've performed a select query");
conv.context.set("SelectQueryIntent", 1);
break;
case UpdateQueryEntity:
// perform update query
conv.ask("I've performed a update query");
conv.context.set("UpdateQueryIntent", 1);
break;
etc..
};
The context will allow you to navigate the conversation into your desired direction. So if the user inputs anything that matches a SelectQueryEntity, the context will be set to SelectQueryIntent. Any intent which has SelectQueryIntent as an input context will then be allowed to follow up the users next input. Using an intent lifespan of 1 makes this navigation easier to work with.
I am setting up GTM Event Tracking and Facebook Pixel tracking for a client.
They are using a CRM system with a form widget which is embedded on the website via Javascript. As such, there is no direct way of tracking the form.
Their developers have asked me to use their global variables, one of which allows me to add in a callback which is triggered upon 'formCompleted'.
Please see the code below. The last variable allows me to input a callback, but honestly speaking, I have no idea how to make it fire an event to Google Tag Manager, or Facebook Pixel.
var intouchFormConfig = {
includeCss: true, //s et false to stop the default stylesheet from being loaded
foregroundColour: null, //set to a css colour - e.g. #fff- to override what is
configured on the server
matterGuid: null, // Id of a matter. If this is set the matter will be updated with
the results of this form
bannerUrl: null, //a n image to display at the top of the form
autoActivate: true,//by default the widget will automatically activate,
events: {
activa ted: () => {}, //an optional callback triggered once the widget is
activated
formCompleted: (response) => {}, //an optional callback triggered once a form
inside the widget has been completed by the user
},
};
The general concept to generate custom events in Google Tag Manager (GTM) is to push the event variable into dataLayer of GTM. You can set up Custom Event triggers in GTM to launch any tags, that are relevant to this event. You need to provide the name of the event as Event name in the trigger settings.
The general syntax for this is:
dataLayer.push({
event: 'myEventName'
});
In your case, you need to provide a function, that will make this call. You can also pass the response to GTM as a dataLayer variable, if you need to use it in connection to your event. (E.g. check for success, failure, or any other outcome.) So your code should look something like this:
var intouchFormConfig = {
//your other configuration items
//events part
events: {
activated: () => {},
formCompleted: (response) => {
dataLayer.push({
event : 'intouchFormCompleted', //an event name you can use in GTM, should be unique to this event
intouchResponse: response //optional part, if you need the response in GTM
})
},
}
};
Please note, you have a typo in your original code (activa ted object key with a space in it).
Your GTM trigger will look something like this, in case of an event name from my example:
I have a query on a Google home (Dialogflow).
In a specific, after I execute fallback intent three times it exits with a statement
Sorry I can't help
But it should prompt
I am ending this session see you again later.
Here is code of fallback intent
app.intent('Default Fallback Intent', (conv) =>
{
const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
if (repromptCount === 0) { conv.ask(`Hey are you listening?`); }
else if (repromptCount === 1) { conv.ask(`Are you still around?`); }
else if (conv.arguments.get('IS_FINAL_REPROMPT')) { conv.close(`I am ending this session see you again later.`); }
});
I am assuming you're trying to follow the directions in the documentation about dynamic reprompts for "no-input" type responses.
The problem appears to be that you're trying to use this for the Fallback Intent, which is not specifically triggered on a NO_INPUT event. So it is doing the test, and neither the REPROMPT_COUNT nor IS_FINAL_REPROMPT arguments are set.
If you're using the multivocal library, it will keep counters of all the Intents and Actions that are called (both for the session and sequentially) and has some macros that assist in your responses.
If you want to use the existing library, you'll need to keep track of this yourself and either store this in a Context or store it in the session data object.
If you intended to use this as part of a "no-input" response, you need to make sure you're using this with an Intent that has the actions_intent_NO_INPUT event set.
Are in-dialog intents supported? I tried something that I thought might work. It didn't. I'm wondering if I need to look harder for a bug on my part or if I can't get there from here. I looked at the ask() method:
ask (inputPrompt, dialogState) {
debug('ask: inputPrompt=%s, dialogState=%s',
JSON.stringify(inputPrompt), JSON.stringify(dialogState));
const expectedIntent = this.buildExpectedIntent_(this.StandardIntents.TEXT, []);
if (!expectedIntent) {
error('Error in building expected intent');
return null;
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
It is specifying the name of the intent where the user's response will end up. The comments above the buildExpectedIntent_() method have this quip
intent Developer specified in-dialog intent inside the Action
* Package or an App built-in intent like
* 'assistant.intent.action.TEXT'.
So I thought I might be able to create a new method by starting with the ask method and adding a parameter to take the name of an in-dialog intent and then defining the intent in my action package. I don't see an obvious error when I do that but my text intent is the one that gets the text spoken by the user, not the in-dialog intent.
Should this work - that is should I keep looking for where I went wrong?
While I'm at it, there is also this
* Refer to {#link ActionsSdkApp#newRuntimeEntity} to create
* the list of runtime entities required by this method.
* Runtime entities need to be defined in the Action Package.
just above the description of the intent. What are runtime entities in this context?
It is not possible to match any user defined intent using the Actions SDK integration after the MAIN intent as all the next intents will match the TEXT intent unless it's a built-in intent (system intent). You can find more info on ExpectedIntent in this page.
User defined intents are only accessible through deep-linking. More info here.