[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:
I expect the skill_adapter to register properly, but it is throwing an error message.
fzimmerman@mifarfzimmer-m1:~/voice/AltBrains_Basketball/selfhosted$ flask routes
Traceback (most recent call last):
File "/Users/fzimmerman/anaconda3/bin/flask", line 10, in <module>
sys.exit(main())
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 557, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 411, in decorator
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
File "/Users/fzimmerman/voice/AltBrains_Basketball/selfhosted/exlambda.py", line 30, in <module>
skill=sb.create(), skill_id="amzn1.ask.skill.5cbfc4d6-35dd-436f-9dbe-bab5dda42409", app=app)
File "/Users/fzimmerman/anaconda3/lib/python3.6/site-packages/flask_ask_sdk/skill_adapter.py", line 151, in __init__
self._skill.custom_user_agent += " flask-ask-sdk"
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
likely my error although I don't understand what line 151 is doing -- what is it trying to do there
#import json
import logging
import random
from flask import Flask
from ask_sdk_core.skill_builder import SkillBuilder
from flask_ask_sdk.skill_adapter import SkillAdapter
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model.ui import SimpleCard
from ask_sdk_model import Response, RequestEnvelope
#import ssml2text
app = Flask(__name__)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
sb = SkillBuilder()
**skill_adapter = SkillAdapter(
skill=sb.create(), skill_id="amzn1.ask.skill.5cbfc4d6-35dd-436f-9dbe-bab5dda42409", app=app)** # I believe this is correct skill id, something may be wrong here...
type_of_shot = "type_of_shot"
# game-specific functions that are not responses to Intents
def setup_situation():
# sets up the situation for the player
player_team = ['Your team']
relation = [' is behind by ', ' is down by ', ' trails by ']
points_down = 1 # two, three ...
pointspread = ['one']
conjunction = [' with ']
time_remaining = ['the clock winding down', 'time almost elapsed', 'the buzzer about to sound', 'the last possession']
possession = ['Your ball. ', 'Over to you. ', 'Your possession. ']
stage_of_season = [' championship game ', ' conference championship ', ' conference tournament']
NBA_stages = [' game five'] * 3 + ['game six'] * 3 + [' game seven'] * 3
overtime = [' regulation'] * 10 + [' the first half'] * 3 + [ ' overtime' ] * 2 + [' double overtime'] * 1 + [' triple overtime'] * 1
special_circumstances = ['Homecoming']
situation = random.choice(player_team) + random.choice(relation) + random.choice(pointspread) + random.choice(conjunction) + random.choice(time_remaining) + ' in ' + random.choice(overtime) + '. '
print(situation)
return situation
def update_situation(myshot):
points_down = 1
raw_probability = 0.5
contesteds = ['Embarrassingly open. '] * 3 + ['Wide open. '] * 5 + ['It is contested... '] * 20 + ['Fiercely contested. '] * 10
contestedness = random.uniform(.8, 1.0)
# distance_modifier
adjusted_probability = raw_probability * contestedness
this_try = random.random()
if this_try < adjusted_probability:
points_down = points_down - 2
basket_made = 1
call = random.choice(['Rattles round the rim and in. ', 'Swish! ', 'That is good. ', 'Good. ', 'Drained it. ', 'Basket. ', 'Friendly bounce! ', 'Nothing but net! '])
compliment = random.choice(['That was clutch. ', 'Great shot. ', 'You da man. ', 'Awesome. ', 'Wow. ', 'Amazing. ', 'Wow. Just wow.'])
else:
points_down = points_down
basket_made = 0
call = random.choice(['Short. ', 'Just short. ', 'Air ball. ', 'Long. ', 'Way long. ', 'Rattles off the rim. ', 'Rattles round the rim and out. ' ])
taunt = random.choice(['Ha ha. ', 'Choke. ', 'Tough luck. ', 'You suck. ', 'I win. ', 'I won. ', ' Go me. ', 'I have bragging rights. '])
# report on how tough the shot was
percentage_this_try = "{:.0%}".format(this_try)
percentage_probability = "{:.0%}".format(adjusted_probability)
print(percentage_this_try, percentage_probability, basket_made)
if points_down < 0:
outcome_description = call + random.choice(['For the win! ', 'You win! ']) + compliment
if points_down > 0:
outcome_description = call + random.choice(['You lose! ', 'That is an L. ']) + taunt
print(outcome_description)
return outcome_description
@sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
def launch_request_handler(handler_input):
"""Handler for Skill Launch."""
# type: (HandlerInput) -> Response
call_to_action = ['Call your shot. ', 'Your turn. ', 'Your shot. ', 'You go.', 'Say type of shot. ']
speech_text ="Welcome to AltBrains Basketball. " + setup_situation() + random.choice(call_to_action)
return handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Welcome to AltBrains Basketball", speech_text)).set_should_end_session(
False).response
@sb.request_handler(can_handle_func=is_intent_name("TakeShotIntent"))
def take_shot_intent_handler(handler_input):
"""Handler for TakeShotIntent."""
# type: (HandlerInput) -> Response
slots = handler_input.request_envelope.request.intent.slots
#myshot = slots['Item'].value
myshot = slots["type_of_shot"].value
print('myshot was ' + str(myshot))
result = update_situation(myshot)
pause = '<break time=\"3s\"/>'
newgame = ['New game. ', 'Rematch. ', 'Play again? ', 'Lets play again. ' ]
transition = ' Call your shot, or say goodbye. '
intro = ['Your attempt was a ', 'You tried a ', ' ', 'That was a ']
speech_text = random.choice(intro) + myshot + '. ' + result + pause + random.choice(newgame) + setup_situation() + transition
card_text = result + transition
return handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Your Shot", card_text)).set_should_end_session(False).response
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))
def help_intent_handler(handler_input):
"""Handler for Help Intent."""
# type: (HandlerInput) -> Response
speech_text = "Call your shot. For example, say jump shot or sky hook."
return handler_input.response_builder.speak(speech_text).ask(
speech_text).set_card(SimpleCard(
"Shot Help", speech_text)).response
@sb.request_handler(
can_handle_func=lambda handler_input:
is_intent_name("AMAZON.CancelIntent")(handler_input) or
is_intent_name("AMAZON.StopIntent")(handler_input))
def cancel_and_stop_intent_handler(handler_input):
"""Single handler for Cancel and Stop Intent."""
# type: (HandlerInput) -> Response
speech_text = "Thanks for playing!"
return handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Thanks for playing!", speech_text)).response
@sb.request_handler(can_handle_func=is_intent_name("AMAZON.FallbackIntent"))
def fallback_handler(handler_input):
"""AMAZON.FallbackIntent is only available in en-US locale.
This handler will not be triggered except in that locale,
so it is safe to deploy on any locale.
"""
# type: (HandlerInput) -> Response
speech = (
"I'm not sure what you want me to do.")
reprompt = "You can call your shot by saying type of shot followed by distance. For example, jump shot from twenty feet."
handler_input.response_builder.speak(speech).ask(reprompt)
return handler_input.response_builder.response
@sb.request_handler(can_handle_func=is_request_type("SessionEndedRequest"))
def session_ended_request_handler(handler_input):
"""Handler for Session End."""
# type: (HandlerInput) -> Response
return handler_input.response_builder.response
@sb.exception_handler(can_handle_func=lambda i, e: True)
def all_exception_handler(handler_input, exception):
"""Catch all exception handler, log exception and
respond with custom message.
"""
# type: (HandlerInput, Exception) -> Response
logger.error(exception, exc_info=True)
speech = "Sorry, I couldn't understand your intent. Please try again!!"
handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response
handler = sb.lambda_handler()