Save granted permissions across conversations in a Actions on Google app

狂风中的少年 提交于 2019-12-10 15:55:07

问题


i programming a Actions on Google app where i request the user for permission. All works fine. Now i want to ask the user for permission in his first conversation. When he starts the conversation a second time the actions app should remember that this user granted permissions in the conversation before. So its more comfortable when the user did not have to accept permission every time i starts the conversation. Is there any way to make this possible?


回答1:


Short answer: you can't.

However, you don't necessarily need to do so for some things. For example, if you're asking for their name - it probably won't change, so you can ask for this the first time and then cache the answer.

If you're using the node.js library, you can easily do this by adding the information to the app.userStorage object. This will be saved for you in between sessions. So your code might look something like this:

var userName = app.userStorage.userName;
if( !userName ){
  if( app.isPermissionGranted() ){
    userName = app.userStorage.userName = app.getUser().displayName;
  } else {
    requestPermission();
  }
}

(Tho I haven't tested this, it looks roughly correct.)

If you're requesting location, this may or may not be as good a solution. Although a Google Home device has a fixed location, using the Assistant from the phone can change. In this case, you'll need to re-request it each time.

Clearly this isn't desirable in a lot of situations, and the team is aware how poor an experience this is. No promises on when, but hopefully they're working on a better solution.



来源:https://stackoverflow.com/questions/47486887/save-granted-permissions-across-conversations-in-a-actions-on-google-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!