Why doesn't the permission for a name work? - node.js

I'm trying to allow a permission in Google Assistant, but the simulator just asks to "repeat the answer" when asking for a name. Here is the code for permission.
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME'
}));
});
On deploying the code via Firebase, no errors are thrown.
Thanks in advance.

In your agent Default Welcome Intent is the intent which asks for NAME permission.
You will have to implement another intent to handle this permission. Lets call it user_info intent.
So when Actions On Google asks the question, and the user responds “yes” or “no” (grants or declines); Actions On Google will then send an event called “actions_intent_PERMISSION” to DialogFlow. We’ll use that event to trigger this particular intent. Once the intent is triggered, we’ll make sure to send the “user_info” action to our application.
In the application, we’ll register the “user_info” action and make sure to check whether the user has granted or declined the permissions. For that, we call the isPermissionGranted helper method.
app.intent('user_info', (conv, params, permissionGranted) => {
if (!permissionGranted) {
throw new Error('Permission not granted');
}
const {requestedPermission} = conv.data;
if (requestedPermission === 'NAME') {
conv.user.storage.name = conv.user.name.display;
return conv.close(responses.sayName(conv.user.storage.name));
}
throw new Error('Unrecognized permission');
});

Related

Account Linking Actions On Google

After Sign is done, my output for "Get Signin" intent is not displayed.
Using Google-Sign in
app.intent("redeem", (conv) => {
conv.ask(new SignIn("To redeem "));
})
app.intent("Get Signin", (conv, params, signin) => {
if (signin.status === 'OK') {
const payload = conv.user.profile.payload;
conv.ask(`I got your account details ${payload.name} , how would you like to redeem? `)
conv.ask(new Suggestions(['QR code'], ['code']));
}
else {
conv.close("Please sign in to redeem");
}
})
After a successful sign in I get this message:
Dialogflow Get Signin (top part):
Dialogflow Get Signin (bottom part):
When the Sign-In completes, it triggers the actions_intent_SIGN_IN Dialogflow event. So your "Get Signin" Intent needs to have this set in the Event field, with no training phrases.
It might look something like this
Since you don't have an Event or Training phrases set, that Intent will never be triggered. Instead, when the Sign-in completes, Actions will send the Event, but since there is nothing setup to handle the event in Dialogflow, it will fail to do anything, so it will exit with the error about not responding.

How to implement the 'Account Sign-in' helper in Google dialogflow? Getting a 'The agent returned an empty TTS'

I require Account linking for my chatbot and so I included the Account Sign-in helper as below -
const {dialogflow, SignIn} = require('actions-on-google');
const app = dialogflow();
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new SignIn());
});
//I have an intent 'Get Signin' triggered by event 'actions_intent_SIGN_IN'
app.intent('Get Signin', (conv, params, signin) => {
if (signin.status === 'OK') {
const email = conv.user.email;
conv.ask(`I got your email as ${email}. What do you want to do next?`);
} else {
conv.ask(`I won't be able to save your data, but what do you want to next?`);
}
});
When invoking my app, I get a 'The agent returned an empty TTS' response. What changes do I need to make?
Thanks in advance
The Authorization and Token Url are part of an Oauth process. It requires you to have your own service with user accounts to verify the user. If you don't have this I recommend you to use Google Sign-in instead, it is the easiest way of AccountLinking and should work out of the box. If you do need the OAuth sign-in, then I recommend you to read up on how OAuth works, because that is where the Authorization and Token Url are for.
When you setup acccountlinking correctly, the empty TTS should be fixed.

Asking for location permissions

I have an action that is requesting location, but I'm a little confused by the Dialogflow setup of this. This is my code:
app.intent('bus_stop_nearby_permission', (conv) => {
conv.ask(new Permission({
context: 'To get nearby bus stops',
permissions: 'DEVICE_PRECISE_LOCATION',
}));
});
app.intent('bus_stop_nearby', (conv, input, granted) => {
if (granted) {
conv.close(`Location was granted ${JSON.stringify(conv)}`);
} else {
conv.close(`Location was not granted!`);
}
});
In Dialogflow the initial intent bus_stop_nearby_permission is triggered by asking for bus stops near me with a training phrase, there is no event attached to this dialog. The follow-up intent bus_stop_nearby has the action_intent_PERMISSION event attached to it and no training phrases. Right now my action asks for permissions but doesn't understand any confirmation input, and just defers to the fallback intent when I say yes to it.
Screenshots of bus_stop_nearby intent:
Screenshot of bus_stop_nearby_permission:
Do I need to add follow up contexts for when the user approves the location request?
The event should be actions_intent_PERMISSION with an "s" at the end of "action".
Easy and common typo to miss.

How to get device coarse location for each webhook request in actions on google

Hi i'm trying to get device coarse location by getting permission from user.But i required to get device location details for each webhook request without asking permission again and again.So I'm bit confused how to do this one.
Here is the below code which i tried.
const {Permission} = require('actions-on-google');
const {WebhookClient} = require('dialogflow-fulfillment');
const agent = new WebhookClient({ request: req, response: res });
function x(agent){
conv.ask(new Permission({context:'To Locate You',permissions:'DEVICE_COARSE_LOCATION'}));
}
function userinfo(agent){
var conv=agent.conv();
var resp=conv.arguments.get('PERMISSION');
console.log(conv.device.location);
if(resp){
var country=conv.device.location.country;
var speech="you are located in "+country;
conv.ask(speech);
agent.add(conv);
}else{
conv.ask('Sorry, I could not figure out where you are');
agent.add(conv);
}
}
Please check the helper functions here. You need to do the following:
Create an intent to ask for permission.
In that intent, ask the permission you want
Create second intent to capture user's response to intent by putting the Dialogflow event actions_intent_PERMISSION to that intent.
In the webhook handle of the second intent check for confirmation.
Ask Permission in First Intent
app.intent('FIRST_INTENT_NAME', (conv) => {
// Choose one or more supported permissions to request:
// NAME, DEVICE_PRECISE_LOCATION, DEVICE_COARSE_LOCATION
const options = {
context: 'To address you by name and know your location',
// Ask for more than one permission. User can authorize all or none.
permissions: ['NAME', 'DEVICE_PRECISE_LOCATION'],
};
conv.ask(new Permission(options));
});
Capture result in Second Intent
app.intent('SECOND_INTENT_NAME', (conv, params, confirmationGranted) => {
const {name} = conv.user;
if (confirmationGranted) {
if (name) {
conv.ask(`I'll send the driver you're way now ${name.display}.`);
}
}
});
For exact understanding with code example, check out this GitHubb example link.

Account linking Google actions via api.api

We are using api.api with fulfillment
After asking to sign in with the code:
app.askForSignIn();
We get intent call for input.unknown
We added sign handler but it is not called
const SIGN_IN = 'sign.in';
actionMap.set(SIGN_IN, signInLogic);
function signInLogic(app) {
let intent = app.getIntent();
console.log('signInLogic start intent: ', intent);
}
What needs to define in api.ai as intent to get the correct intent call?
I could not find a place to define system intents

Resources