Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 39f5e16

Browse files
committed
create and set user local proxy
1 parent 19781ae commit 39f5e16

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

flask_assistant/core.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def find_assistant(): # Taken from Flask-ask courtesy of @voutilad
3939
context_manager = LocalProxy(lambda: find_assistant().context_manager)
4040
convert_errors = LocalProxy(lambda: find_assistant().convert_errors)
4141
session_id = LocalProxy(lambda: find_assistant().session_id)
42+
user = LocalProxy(lambda: find_assistant().user)
4243

4344
# Converter shorthands for commonly used system entities
4445
_converter_shorthands = {
@@ -220,6 +221,14 @@ def session_id(self):
220221
def session_id(self, value):
221222
_app_ctx_stack.top._assist_session_id = value
222223

224+
@property
225+
def user(self):
226+
return getattr(_app_ctx_stack.top, "_assist_user", {})
227+
228+
@user.setter
229+
def user(self, value):
230+
_app_ctx_stack.top._assist_user = value
231+
223232
def _register_context_to_func(self, intent_name, context=[]):
224233
required = self._required_contexts.get(intent_name)
225234
if required:
@@ -367,8 +376,14 @@ def _flask_assitant_view_func(self, nlp_result=None, *args, **kwargs):
367376
# TODO: acces context_manager from assist, instead of own object
368377
self.context_manager._assist = self
369378

370-
# Get access token from request
379+
371380
original_request = self.request.get("originalDetectIntentRequest")
381+
382+
383+
if original_request and original_request["payload"].get("user"):
384+
self.user = original_request["payload"]["user"]
385+
386+
# Get access token from request
372387
if original_request and original_request.get("user"):
373388
self.access_token = original_request["user"].get("accessToken")
374389

flask_assistant/response.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ def __init__(self, speech, display_text=None, is_ssml=False):
2828
}
2929

3030
if "ACTIONS_ON_GOOGLE" in self._integrations:
31+
self._set_user_storage()
3132
self._integrate_with_actions(self._speech, self._display_text, is_ssml)
3233

3334
def add_msg(self, speech, display_text=None, is_ssml=False):
3435
self._messages.append({"text": {"text": [speech]}})
3536
if "ACTIONS_ON_GOOGLE" in self._integrations:
3637
self._integrate_with_actions(speech, display_text, is_ssml)
3738

38-
return self
39+
def _set_user_storage(self):
40+
from flask_assistant.core import user
41+
42+
# If empty or unspecified,
43+
# the existing persisted token will be unchanged.
44+
if user.get("userStorage"):
45+
self._response["payload"]["google"]["userStorage"] = user["userStorage"]
3946

4047
def _integrate_with_actions(self, speech=None, display_text=None, is_ssml=False):
4148
if display_text is None:

0 commit comments

Comments
 (0)