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

Commit adc4cff

Browse files
authored
Merge pull request #142 from treethought/develop
Fix Google Certs, Media Repsonses, Dialogflow Messenger
2 parents d9e807c + c9067a6 commit adc4cff

File tree

12 files changed

+331
-68
lines changed

12 files changed

+331
-68
lines changed

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ idna = "==2.8"
1818
itsdangerous = "==1.1.0"
1919
requests = "==2.21.0"
2020
urllib3 = "==1.24.2"
21-
Flask = "==1.0.2"
22-
Jinja2 = "==2.10"
21+
Flask = "==1.1.1"
2322
MarkupSafe = "==1.1.0"
2423
"ruamel.yaml" = "==0.15.81"
2524
Werkzeug = "==0.15.3"
2625
google-auth = "*"
26+
dialogflow = "*"
2727

2828
[requires]
2929
python_version = "3.7"

flask_assistant/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@
2323
storage,
2424
session_id,
2525
context_in,
26-
profile
26+
profile,
27+
)
28+
29+
from flask_assistant.response import (
30+
ask,
31+
tell,
32+
event,
33+
build_item,
34+
permission,
35+
sign_in,
36+
build_button,
2737
)
2838

29-
from flask_assistant.response import ask, tell, event, build_item, permission, sign_in
3039
from flask_assistant.manager import Context
3140

3241
import flask_assistant.utils

flask_assistant/core.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ def __init__(
102102

103103
if app is not None:
104104
self.init_app(app)
105+
105106
elif blueprint is not None:
106107
self.init_blueprint(blueprint)
107108

109+
if self.client_id is None and self.app is not None:
110+
self.client_id = self.app.config.get("AOG_CLIENT_ID")
111+
108112
if project_id is None:
109113
import warnings
110114

@@ -125,10 +129,9 @@ def init_app(self, app):
125129
app.add_url_rule(
126130
self._route, view_func=self._flask_assitant_view_func, methods=["POST"]
127131
)
128-
if self.client_id is None:
132+
if self.client_id is None and self.app is not None:
129133
self.client_id = self.app.config.get("AOG_CLIENT_ID")
130134

131-
132135
# Taken from Flask-ask courtesy of @voutilad
133136
def init_blueprint(self, blueprint, path="templates.yaml"):
134137
"""Initialize a Flask Blueprint, similar to init_app, but without the access
@@ -154,11 +157,11 @@ def init_blueprint(self, blueprint, path="templates.yaml"):
154157
blueprint.add_url_rule(
155158
"", view_func=self._flask_assitant_view_func, methods=["POST"]
156159
)
160+
157161
# blueprint.jinja_loader = ChoiceLoader([YamlLoader(blueprint, path)])
158-
if self.client_id is None:
162+
if self.client_id is None and self.app is not None:
159163
self.client_id = self.app.config.get("AOG_CLIENT_ID")
160164

161-
162165
@property
163166
def request(self):
164167
"""Local Proxy refering to the request JSON recieved from Dialogflow"""
@@ -392,15 +395,16 @@ def _set_user_profile(self):
392395
from flask_assistant.utils import decode_token
393396

394397
token = self.user["idToken"]
395-
profile_payload = decode_token(token, self.client_id)
398+
decode_resp = decode_token(token, self.client_id)
399+
if decode_resp["status"] == "BAD":
400+
return
401+
else: # decode_resp["status"]=="OK"
402+
profile_payload = decode_resp["output"]
396403
for k in ["sub", "iss", "aud", "iat", "exp"]:
397404
profile_payload.pop(k)
398405

399406
self.profile = profile_payload
400407

401-
402-
403-
404408
def _flask_assitant_view_func(self, nlp_result=None, *args, **kwargs):
405409
if nlp_result: # pass API query result directly
406410
self.request = nlp_result
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .base import _Response, _ListSelector, ask, tell, event, permission
2+
from .base import *
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def build_card(
2+
text,
3+
title,
4+
img_url=None,
5+
img_alt=None,
6+
subtitle=None,
7+
link=None,
8+
link_title=None,
9+
buttons=None,
10+
):
11+
12+
card_payload = {"title": title, "subtitle": subtitle, "formattedText": text}
13+
14+
if buttons:
15+
card_payload["buttons"] = buttons
16+
17+
elif link and link_title:
18+
btn_payload = [{"title": link_title, "openUriAction": {"uri": link}}]
19+
card_payload["buttons"] = btn_payload
20+
21+
if img_url:
22+
img_payload = {"imageUri": img_url, "accessibilityText": img_alt or img_url}
23+
card_payload["image"] = img_payload
24+
25+
return {"platform": "ACTIONS_ON_GOOGLE", "basicCard": card_payload}

0 commit comments

Comments
 (0)