Last active
May 1, 2018 15:40
-
-
Save rishabhgupta/6937c34c2bb049acc2e4d65b5c16c737 to your computer and use it in GitHub Desktop.
FlaskASK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import Flask | |
from flask import Flask | |
# import Ask Class and statement method from flask_ask | |
from flask_ask import Ask, statement | |
# create a flask app | |
app = Flask(__name__) | |
# define alexa endpoint | |
ask = Ask(app, '/alexa_end_point') | |
@ask.launch | |
def launch(): | |
# this method will handle launch request | |
pass | |
@ask.intent('HelloIntent') | |
def hello(SlotName): | |
# this method will handle HelloIntent request | |
pass | |
@ask.session_ended | |
def session_ended(): | |
return "", 200 | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
import os | |
port = int(os.getenv('PORT', 5000)) | |
print ('Starting app on port %d' % port) | |
app.run(debug=False, port=port, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import request | |
from flask import make_response | |
from flask_ask import Ask, statement, question | |
from datetime import datetime, timedelta | |
import json | |
import datetime | |
app = Flask(__name__) | |
ask = Ask(app, '/alexa_end_point') | |
@ask.launch | |
def launch(): | |
speech_text = 'Welcome to HelloWorld skill, using this skill you can great your guests.' | |
reprompt_text = 'Whom would you like to greet, you can say, say hello to Cipherhack' | |
return question(speech_text).reprompt(reprompt_text) | |
@ask.intent('HelloIntent', mapping={'first_name': 'FirstName'}, default={'first_name': 'Unknown'}) | |
def hello(first_name): | |
speach_text = 'Hello %s' % first_name | |
speach_text += get_wish() | |
return statement('<speak>' + speach_text + '</speak>').standard_card('Chipherhack', speach_text) | |
def get_wish(): | |
current_time = datetime.datetime.utcnow() | |
hour = current_time.hour - 5 | |
if hour < 0: | |
hour += 24 | |
if hour < 12: | |
return '. Good morning.' | |
elif hour < 18: | |
return '. Good evening.' | |
else: | |
return '. Good night.' | |
@ask.session_ended | |
def session_ended(): | |
return "", 200 | |
if __name__ == "__main__": | |
import os | |
port = int(os.getenv('PORT', 5000)) | |
print ('Starting app on port %d' % port) | |
app.run(debug=False, port=port, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ask.intent('HelloIntent', mapping={'first_name': 'FirstName'}, default={'first_name': 'Unknown'}) | |
def hello(first_name): | |
speach_text = 'Hello %s' % first_name | |
return statement('<speak>' + speach_text + '</speak>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ask.launch | |
def launch(): | |
speech_text = 'Welcome to HelloWorld skill, using this skill you can great your guests.' | |
reprompt_text = 'Whom would you like to say hello to, you can say, say hello to Cipherhack' | |
return question(speech_text).reprompt(reprompt_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ask.launch | |
def launch(): | |
speech_text = '<speak>Welcome to HelloWorld skill, using this skill you can great your guests.</speak>' | |
reprompt_text = '<speak>Whom would you like to say hello to, you can say, say hello to Cipherhack.</speak>' | |
return question(speech_text).reprompt(reprompt_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment