logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # request handlers launch bstython with bstpy lambda.py.lambda_function.handler # pip install -e /home/ric/Python-Projects/ALEXA_SDK/bst_python/bstpy def _load_apl_document(file_path): # type: (str) -> Dict[str, Any] """Load the apl json document at the path into a dict object.""" with open(file_path) as f: return json.load(f) @sb.request_handler(can_handle_func=is_request_type("LaunchRequest")) def launch_request_handler(handler_input): speechText = 'Welcome to the the Food Pyramid skill. You can ask about ' \ 'the different tiers or a specific food group!' return (handler_input.response_builder.speak( speechText).ask(speechText).set_card( SimpleCard("Food Pyramid", speechText)).add_directive( RenderDocumentDirective( document=_load_apl_document("lambda/custom/homepage.json")) ).set_should_end_session(False).response) @sb.request_handler(can_handle_func=is_intent_name('GrainsIntent')) def grains_intent_handler(handler_input): speechText = 'These foods provide complex carbohydrates, which are a ' \ 'good source of energy but provide little nutrition.'
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (handler_input.request_envelope.request.object_type.startswith( "AlexaSkillEvent") or is_request_type("SessionEndedRequest")(handler_input))
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return ask_utils.is_request_type("SessionEndedRequest")(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return is_request_type("AudioPlayer.PlaybackFailed")(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return is_request_type("PlaybackController.PlayCommandIssued")( handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return is_request_type("IntentRequest")(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("LaunchRequest")(handler_input) or is_intent_name("RoarIntent")(handler_input))
def can_handle(self, handler_input: HandlerInput) -> bool: return ask_utils.is_request_type('LaunchRequest')(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("LaunchRequest")(handler_input) or is_intent_name("OpenDepressionDetectIntent")(handler_input))
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("IntentRequest")(handler_input) and is_intent_name("ProsAndConsEndIntent")(handler_input))
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("IntentRequest")(handler_input) and is_intent_name("SolutionIntent")(handler_input))
from ask_sdk_core.utils import is_request_type from ask_sdk_model.ui import SimpleCard from ask_sdk_core.utils import is_intent_name from fact_file import facts ## Instantiate Skill Builder object sb = SkillBuilder() ## The following functions are implemented using decorators ## Reference: https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/DEVELOPING_YOUR_FIRST_SKILL.html#option-2-implementation-using-decorators ## Create LaunchRequest Handler @sb.request_handler(can_handle_func=is_request_type('LaunchRequest')) def launch_request_handler(handler_input): speech_text = 'Welcome to Facts. You can ask me to tell you a fact about Mumbai' handler_input.response_builder.speak(speech_text).set_card( SimpleCard('Hello', speech_text)).set_should_end_session(False) return handler_input.response_builder.response ## Create Request Handler for rolling one die. @sb.request_handler(can_handle_func=is_intent_name('FactIntent')) def roll_die_intent_handler(handler_input): speech_text = random.choice(facts) card_title = 'Fact: '
number_slot = "number" roll_slot = "rolloption" skill_name = "Dice Roller" quantity_help_text = ("Please tell me how many dice you would like to roll. " "You can give me a number from one to ten.") sides_help_text = ( "Please give me a number from 2 to 20. " "For example, the average dice used for board games has 6 sides.") roll_help_text = "Ready for me to roll? You can say yes or roll to start or no to wait." sb = SkillBuilder() @sb.request_handler(can_handle_func=is_request_type("LaunchRequest")) def launch_request_handler(handler_input): print("LaunchRequest") response_builder = handler_input.response_builder speech = "Welcome to dice roller." response_builder.speak(speech + " " + quantity_help_text).ask(quantity_help_text) return response_builder.response @sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent")) def help_intent_handler(handler_input): response_builder = handler_input.response_builder response_builder.speak(quantity_help_text).ask(quantity_help_text) return response_builder.response
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return is_request_type(LAUNCH_REQUEST)(handler_input)
def can_handle(self, handler_input): return is_request_type('LaunchRequest')(handler_input)
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 app = Flask(__name__) logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # register intent handlers to skill_builder object skill_builder = SkillBuilder() @skill_builder.request_handler(can_handle_func=is_request_type("LaunchRequest") ) def launch_request_handler(handler_input): # """Handler for Skill Launch.""" # type: (HandlerInput) -> Response speech_text = "Move plan is an Alexa skill and is live, you can say hello!" return handler_input.response_builder.speak(speech_text).set_card( SimpleCard("Hello World", speech_text)).set_should_end_session(False).response @skill_builder.request_handler( can_handle_func=is_intent_name("HelloWorldIntent")) def hello_world_intent_handler(handler_input): # """Handler for Hello World Intent."""
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return ( ask_utils.is_request_type("Connections.Response")(handler_input) and handler_input.request_envelope.request.name == "Buy")
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type('Connections.Response')(handler_input) and handler_input.request_envelope.request.name == 'Upsell')
def can_handle(self, handler_input): return ask_utils.is_request_type("LaunchRequest")(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("LaunchRequest")(handler_input) or is_intent_name("GetMachineAvailability")(handler_input))
def can_handle(self, handler_input): return is_request_type('SessionEndedRequest')(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("LaunchRequest")(handler_input) or is_intent_name("GetNewNetworkingFactIntent")(handler_input))
def can_handle(self, handler_input): # type; (HandlerInput) -> bool return is_request_type("System.ExceptionEncountered")(handler_input)
def can_handle(self, handler_input): # type (HandlerInput) -> bool return is_request_type("LaunchRequest")(handler_input) # Returns true if it can handle this request
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return (is_request_type("PlaybackController.NextCommandIssued") (handler_input) or is_request_type("PlaybackController.PreviousCommandIssued") (handler_input))
def can_handle(self, handler_input): """ This class method specifies which is_request_type does this RequestHandler will handle. """ return is_request_type("LaunchRequest")(handler_input)
def can_handle(self, handler_input): # type: (HandlerInput) -> bool return ask_utils.is_request_type("LaunchRequest")(handler_input)
blend=True, color="0000FF"), AnimationStep(duration_ms=300, blend=True, color="FF00FF") ]) breath_animation_red = build_breathe_animation(30, 'FF0000', 1000) breath_animation_green = build_breathe_animation(30, '00FF00', 1000) breath_animation_blue = build_breathe_animation(30, '0000FF', 1000) animations = [ breath_animation_red, breath_animation_green, breath_animation_blue ] @sb.request_handler(can_handle_func=is_request_type("LaunchRequest")) def launch_request_handler(handler_input): """Handler for Skill Launch.""" # type: (HandlerInput) -> Response logger.info("launch_request_handler: handling request") session_attr = handler_input.attributes_manager.session_attributes response_builder = handler_input.response_builder # Start keeping track of some state. session_attr["button_count"] = 0 # Preserve the originatingRequestId. We'll use this to stop the # InputHandler later. # See the Note at https://developer.amazon.com/docs/gadget-skills/receive-echo-button-events.html#start session_attr[
"The Postmaster") goodbye_message = "Thank you for using, The Postmaster by Rabindranath "\ "Tagore. If you like this skill, please write your "\ "feedback on Amazon website. Goodbye!" welcome_message = "Hi, welcome to The Postmaster by Rabindranath Tagore." continue_message = "To continue, say next" sb = SkillBuilder() POSITION = 0 logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @sb.request_handler(can_handle_func=is_request_type("LaunchRequest")) def launch_request_handler(handler_input): """Handler for Skill Launch.""" # type: (HandlerInput) -> Response try: with open('story.txt', 'r', encoding='utf-8') as stream: data = stream.read().split('\n\n\n') length = len(data) speech = welcome_message + data[POSITION] + "." + continue_message handler_input.attributes_manager.session_attributes['data'] = data handler_input.attributes_manager.session_attributes['length'] = length handler_input.attributes_manager.session_attributes['POSITION'] = \ (POSITION + 1) except Exception: speech = "Sorry, an error occured !!"
def can_handle(self, handler_input): return ask_utils.is_request_type("SessionEndedRequest")(handler_input)