/
webhook.py
152 lines (109 loc) · 5.22 KB
/
webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
import logging
from flask import Flask
from flask_assistant import Assistant, ask, tell, build_item
app = Flask(__name__)
assist = Assistant(app)
logging.getLogger('flask_assistant').setLevel(logging.DEBUG)
app.config['ASSIST_ACTIONS_ON_GOOGLE'] = True
ASSIST_LOGO_URL = "http://flask-assistant.readthedocs.io/en/latest/_static/logo-xs.png"
ASSIST_REPO_URL = 'https://github.com/treethought/flask-assistant'
ASSIST_DOCS_URL = "https://flask-assistant.readthedocs.io/en/latest/"
ASSIST_DESCRIPT = """Flask-Assistant allows you to focus on building the core business logic
of conversational user interfaces while utilizing API.AI’s
Natural Language Processing to interact with users."""
ASK_LOGO_URL = 'https://alexatutorial.com/flask-ask/_images/logo-full.png'
ASK_REPO_URL = 'https://github.com/johnwheeler/flask-ask'
ASK_DOCS_URL = 'https://alexatutorial.com/flask-ask/'
ASK_DESCRIPT = 'Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo easier and much more fun.'
FLASK_LOGO_URL = 'http://flask.pocoo.org/static/logo/flask.svg'
FLASK_REPO_URL = 'https://github.com/pallets/flask'
FLASK_DOCS_URL = 'http://flask.pocoo.org/docs/0.12/'
FLASK_DESCRIPT = """Flask is a microframework for Python based on Werkzeug
and Jinja2. It's intended for getting started very quickly
and was developed with best intentions in mind."""
API_LOGO_URL = 'https://static.api.ai/assets/images/logo.png'
API_DOCS_URL = 'https://docs.api.ai/docs/welcome'
API_DESCRIPT = """API.AI is a natural language understanding platform
that makes it easy for developers (and non-developers)
to design and integrate intelligent and sophisticated
conversational user interfaces into mobile apps,
web applications, devices, and bots."""
@assist.action('Default Welcome Intent')
def welcome():
speech = 'Welcome to Flask-Assistant on Google Assistant! Try Asking to see a card!'
return ask(speech).reprompt('Do you want to see some examples?').suggest('Show card', 'Show List')
@assist.action('Default Welcome Intent - yes')
def action_func():
speech = """This is just a simple text to speech message.
Ask to see a card!"""
return ask(speech).suggest('Show card', 'Show List')
@assist.action('ShowCard')
def show_card():
# Basic speech/text response
resp = ask('Now ask to see a list...')
# Now add a card onto basic response
resp.card(text=ASSIST_DESCRIPT, title='Flask-Assistant',
img_url=ASSIST_LOGO_URL)
# Suggest other intents
resp.suggest('Show List', 'Show Carousel')
# Provide links to outside sources
resp.link_out('Github', ASSIST_REPO_URL)
return resp
@assist.action('ShowList')
def action_func():
# Basic speech/text response
resp = ask("Select Flask-Assistant for a carousel")
# Create a list with a title
mylist = resp.build_list('Awesome List')
# Add items directly to list
mylist.add_item('Flask-Assistant',
key='flask_assistant', # query sent if item selected
img_url=ASSIST_LOGO_URL,
description='Select for carousel',
synonyms=['flask assistant', 'number one', 'assistant', 'carousel'])
mylist.add_item('Flask-Ask',
key='flask_ask',
img_url=ASK_LOGO_URL,
description='Rapid Alexa Skills Kit Development for Amazon Echo Devices',
synonyms=['ask', 'flask ask', 'number two'])
# Or build items independent of list
flask_item = build_item('Flask',
key='flask',
img_url=FLASK_LOGO_URL,
description='A microframework for Python based on Werkzeug, Jinja 2 and good intentions',
synonyms=['flask', 'number three'])
# and add them to the lsit later
mylist.include_items(flask_item)
return mylist
@assist.action('FlaskAssistantCarousel')
def action_func():
resp = ask('Heres some info on Flask-Assistant and API.AI').build_carousel()
resp.add_item('Overview', key='overview',
description=ASSIST_DESCRIPT,
img_url=ASSIST_LOGO_URL)
resp.add_item('API.AI',
key='api.ai',
description=API_DESCRIPT,
img_url=API_LOGO_URL)
return resp
@assist.action('FlaskAskCard')
def action_func():
resp = ask('Many thanks to Flask-Ask and John Wheeler')
resp.card(text=ASK_DESCRIPT, title='Flask-Ask',
img_url=ASK_LOGO_URL, link=ASK_DOCS_URL)
# Provide links to outside sources
resp.link_out('View on Github', ASK_REPO_URL)
resp.link_out('Read the Docs', ASK_DOCS_URL)
return resp
@assist.action('FlaskCard')
def action_func():
resp = ask('The one and only Flask')
resp.card(text=FLASK_DESCRIPT, title='Flask',
img_url=FLASK_LOGO_URL, link=FLASK_DOCS_URL)
# Provide links to outside sources
resp.link_out('View on Github', FLASK_REPO_URL)
resp.link_out('Read the Docs', FLASK_DOCS_URL)
return resp
if __name__ == '__main__':
app.run(debug=True)