Skip to content

Commit

Permalink
Merge pull request #142 from treethought/develop
Browse files Browse the repository at this point in the history
Fix Google Certs, Media Repsonses, Dialogflow Messenger
  • Loading branch information
treethought committed Nov 24, 2020
2 parents d9e807c + c9067a6 commit adc4cff
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 68 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Expand Up @@ -18,12 +18,12 @@ idna = "==2.8"
itsdangerous = "==1.1.0"
requests = "==2.21.0"
urllib3 = "==1.24.2"
Flask = "==1.0.2"
Jinja2 = "==2.10"
Flask = "==1.1.1"
MarkupSafe = "==1.1.0"
"ruamel.yaml" = "==0.15.81"
Werkzeug = "==0.15.3"
google-auth = "*"
dialogflow = "*"

[requires]
python_version = "3.7"
Expand Down
13 changes: 11 additions & 2 deletions flask_assistant/__init__.py
Expand Up @@ -23,10 +23,19 @@
storage,
session_id,
context_in,
profile
profile,
)

from flask_assistant.response import (
ask,
tell,
event,
build_item,
permission,
sign_in,
build_button,
)

from flask_assistant.response import ask, tell, event, build_item, permission, sign_in
from flask_assistant.manager import Context

import flask_assistant.utils
Expand Down
20 changes: 12 additions & 8 deletions flask_assistant/core.py
Expand Up @@ -102,9 +102,13 @@ def __init__(

if app is not None:
self.init_app(app)

elif blueprint is not None:
self.init_blueprint(blueprint)

if self.client_id is None and self.app is not None:
self.client_id = self.app.config.get("AOG_CLIENT_ID")

if project_id is None:
import warnings

Expand All @@ -125,10 +129,9 @@ def init_app(self, app):
app.add_url_rule(
self._route, view_func=self._flask_assitant_view_func, methods=["POST"]
)
if self.client_id is None:
if self.client_id is None and self.app is not None:
self.client_id = self.app.config.get("AOG_CLIENT_ID")


# Taken from Flask-ask courtesy of @voutilad
def init_blueprint(self, blueprint, path="templates.yaml"):
"""Initialize a Flask Blueprint, similar to init_app, but without the access
Expand All @@ -154,11 +157,11 @@ def init_blueprint(self, blueprint, path="templates.yaml"):
blueprint.add_url_rule(
"", view_func=self._flask_assitant_view_func, methods=["POST"]
)

# blueprint.jinja_loader = ChoiceLoader([YamlLoader(blueprint, path)])
if self.client_id is None:
if self.client_id is None and self.app is not None:
self.client_id = self.app.config.get("AOG_CLIENT_ID")


@property
def request(self):
"""Local Proxy refering to the request JSON recieved from Dialogflow"""
Expand Down Expand Up @@ -392,15 +395,16 @@ def _set_user_profile(self):
from flask_assistant.utils import decode_token

token = self.user["idToken"]
profile_payload = decode_token(token, self.client_id)
decode_resp = decode_token(token, self.client_id)
if decode_resp["status"] == "BAD":
return
else: # decode_resp["status"]=="OK"
profile_payload = decode_resp["output"]
for k in ["sub", "iss", "aud", "iat", "exp"]:
profile_payload.pop(k)

self.profile = profile_payload




def _flask_assitant_view_func(self, nlp_result=None, *args, **kwargs):
if nlp_result: # pass API query result directly
self.request = nlp_result
Expand Down
2 changes: 2 additions & 0 deletions flask_assistant/response/__init__.py
@@ -0,0 +1,2 @@
from .base import _Response, _ListSelector, ask, tell, event, permission
from .base import *
25 changes: 25 additions & 0 deletions flask_assistant/response/actions.py
@@ -0,0 +1,25 @@
def build_card(
text,
title,
img_url=None,
img_alt=None,
subtitle=None,
link=None,
link_title=None,
buttons=None,
):

card_payload = {"title": title, "subtitle": subtitle, "formattedText": text}

if buttons:
card_payload["buttons"] = buttons

elif link and link_title:
btn_payload = [{"title": link_title, "openUriAction": {"uri": link}}]
card_payload["buttons"] = btn_payload

if img_url:
img_payload = {"imageUri": img_url, "accessibilityText": img_alt or img_url}
card_payload["image"] = img_payload

return {"platform": "ACTIONS_ON_GOOGLE", "basicCard": card_payload}

0 comments on commit adc4cff

Please sign in to comment.