Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get user info #115

Closed
wtavares opened this issue Mar 20, 2019 · 10 comments
Closed

Get user info #115

wtavares opened this issue Mar 20, 2019 · 10 comments

Comments

@wtavares
Copy link

Hi,

A very simple doubt: How can I can the user info comming from Google Assistant?

I could see the the Assintant.request brings the user list and there is a userId coming from the request.

There is a way to get another info like email?

Thanks in advance and congrats by the project... it is awesome!

@wtavares
Copy link
Author

wtavares commented Mar 20, 2019

I believe that my answer is related with the comment at the end of issue #26

But it's not clear to me how to do this exactly... someone know a howto or tutorial?

Also the userID will be deprecated... so here goes the actual way to configure the Actions:
https://developers.google.com/actions/identity/

@treethought
Copy link
Owner

Hi @wtavares thanks for the kind words.
You can now update to version 0.3.7 with pip install -U flask-assistant and access the user object by importing user.

Unfortunately it seems like the only user info provided is "lastSeen", "locale", userId (which will be deprecated), and any permissions granted.

However you can store information to be persisted across sessions in user['userStorage'].

And as for the soon-to-be deprecated userID, take a look at Migrating to Webhook-generated IDs. You can create your own unique ID and store in in userStorage.

import uuid
from flask_assistant import ask, user

...

@assist.action('Default Welcome Intent')
def welcome():
    if user.get('userStorage') is None:
        user['userStorage'] = {}
        uid = uuid.uuid4()
        user['userStorage']['ID'] = str(uid)
        return ask('Looks like you're new here')
    
    elif user['userStorage'].get('ID') is not None:
        last_seen = user['lastSeen']
        return ask('welcome back! Haven't seen you since {}'.format(last_seen))

@diedezp
Copy link

diedezp commented Jul 22, 2019

Hi there, I just tried adding this snippet below to my script and it keeps returning else: error when I test it out in the simulator. Am I missing somthing? Thanks!

from flask import Flask
from flask_assistant import Assistant, user, request, ask, tell, event
import uuid

...

@assist.action('Usersettings')
def usersettings():
    if user.get('userStorage') is None:
        user['userStorage'] = {}
        uid = uuid.uuid4()
        user['userStorage']['ID'] = str(uid)
        return ask('new here?')

    elif user['userStorage'].get('ID') is not None:
        return ask('welcome back!')

    else:
        return ask('error')

@davidalbertonogueira
Copy link
Contributor

Same @diedezp . Storing a new generated uuid in user['userStorage'] is not working (no persistence).
How should we operate @treethought ?

@treethought
Copy link
Owner

@diedezp @davidalbertonogueira due to the changes in how user storage is handled, you can now simply use the storage local.

using @diedezp's example, you would adapt it like so:

from flask import Flask
from flask_assistant import Assistant, request, ask, tell, event, storage
import uuid

...

@assist.action("Usersettings")
def usersettings():
    if storage.get('ID') is None:
        uid = uuid.uuid4()
        storage['ID'] = str(uid)
        return ask('new here?')

    elif storage.get('ID') is not None:
        return ask('welcome back!')

    else:
        return ask('error')

@treethought treethought pinned this issue Oct 11, 2019
@davidalbertonogueira
Copy link
Contributor

@treethought I'm sorry, but using that code above, the storage variable is not saving the ID. Whenever I get a new request, storage is an empty dict.

@treethought
Copy link
Owner

hi @davidalbertonogueira i have seen a lot of reports with user storage not persisting on actions on google (across multiple clients/languages etc).

can you please take a look at this comment and ensure you have the proper options set in your google account? Unfortunately, User storage appears to only be applicable when the user has enabled "Include Chrome history..."

@davidalbertonogueira
Copy link
Contributor

Hi @treethought . I already had a tick in "Include Chrome history", so that wouldn't fix it for me...

@davidalbertonogueira
Copy link
Contributor

any news? @treethought

@Achyut4
Copy link

Achyut4 commented Feb 25, 2020

@treethought

There are two definitions in flask_assistant "core.py" (class Assistant)

@property
    def user(self):
        return getattr(_app_ctx_stack.top, "_assist_user", {})

    @user.setter
    def user(self, value):
        storage_data = value.get("userStorage", {})

        if not isinstance(storage_data, dict):
            storage_data = json.loads(storage_data)

        value["userStorage"] = storage_data

        _app_ctx_stack.top._assist_user = value
        _app_ctx_stack.top._assist_storage = storage_data

    @property
    def storage(self):
        return self.user.get("userStorage", {})

    @storage.setter
    def storage(self, value):
        if not isintance(value, dict):
            raise TypeError("Storage must be a dictionary")

        self.user["userStorage"] = value

but none of them are storing user's data persistently, for every new session on the same user userStorage gets empty.
Hey @davidalbertonogueira Any luck?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants