当他第二次访问我的应用程序时,我想用他的名字问候用户。为此,我已经实现了帐户链接,现在我想获取他的displayName,并且我已经阅读了我需要请求他的访问这些信息的权限,所以我在下面的代码中做了:
welcome(app){
let welcomePhrase = "";
console.log('UserId: ' + app.getUser().userId);
if (app.isPermissionGranted()) {
console.log('--------------- Permission granted ---------------');
const displayName = app.getUserName().displayName;
welcomePhrase = "Welcome back $1!".replace("$1",displayName);
}
else{
console.log('--------------- Permission denied ---------------');
this.requestPermission(app);
welcomePhrase = "Welcome";
}
app.ask(welcomePhrase);
}
requestPermission (app) {
app.askForPermission('Can I keep one information from you?', app.SupportedPermissions.NAME);
}
从我的默认欢迎意图中调用欢迎方法,我可以看到应用程序要求获得权限:
我没有得到的是我作为用户应该回答的问题,因为回复“sim”(是),“sim,vocêpode”(是的,你可以)或任何类似的东西都会被我的默认回退所回答。
主要的想法是你必须请求许可,谷歌向你询问用户,你通过捕获回到Dialogflow的事件得到了答案。
Wassim Chegham写了一篇好文章:https://medium.com/google-developer-experts/handling-permissions-with-dialogflow-and-actions-on-google-b08c8f228c00
更多文档:https://developers.google.com/actions/assistant/helpers