def handle(self, handler_input): # type: (HandlerInput) -> Response fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': True, 'intent': 'CancelOrStopIntent', 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) handler_input.response_builder.speak(response["response_text"]) image_url = response.get('image_url') if image_url: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) handler_input.response_builder.set_should_end_session(True) return handler_input.response_builder.response
def handle(self, handler_input): # type: (HandlerInput) -> Response destinations_choice = handler_input.attributes_manager.session_attributes.get( 'destinations_choice') fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'state': 'Launch', 'destinations_choice': destinations_choice, 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) if response.get('destinations_choice'): handler_input.attributes_manager.session_attributes[ 'destinations_choice'] = response['destinations_choice'] handler_input.attributes_manager.session_attributes['state'] = \ response['state'] if response.get('node'): handler_input.attributes_manager.session_attributes['node'] = \ response['node'] print(f'response: {response}, type: {type(response)}') speech_text = response["response_text"] image_url = response.get('image_url') bg_image_url = response.get('bg_image_url') image_title = response.get('image_title') image_text = response.get('image_text') if image_url: img_obj = Image(sources=[ImageInstance(url=image_url)]) bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)]) if util.is_support_display(handler_input): handler_input.response_builder.add_directive( RenderTemplateDirective( BodyTemplate7( back_button=BackButtonBehavior.VISIBLE, image=img_obj, background_image=bg_img_obj, title='') ) ) else: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) handler_input.response_builder.speak(speech_text).ask( speech_text).set_should_end_session( response.get('set_should_end_session', True)) return handler_input.response_builder.response
def handle(self, handler_input): # type: (HandlerInput) -> Response session = handler_input.attributes_manager.session_attributes state = session.get('state') node = session.get('node') fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': True, 'intent': 'HelpIntent', 'state': state, 'node': node, 'destinations_choice': handler_input.attributes_manager.session_attributes.get( 'destinations_choice'), 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) speech_text = response["response_text"] handler_input.response_builder.speak(speech_text).ask(speech_text) return handler_input.response_builder.response
def handle(self, handler_input): # type: (HandlerInput) -> Response session = handler_input.attributes_manager.session_attributes fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': True, 'intent': 'WhatHaveIGotIntent', 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'product_name' in response: session['product_name'] = response['product_name'] speech_text = response["response_text"] handler_input.response_builder.speak(speech_text).ask(speech_text) return handler_input.response_builder.response
def handle(self, handler_input: HandlerInput): in_skill_response = util.in_skill_product_response(handler_input) if not in_skill_response: return handler_input.response_builder.speak( '購入処理でエラーが発生しました。' 'もう一度試すか、カスタマーサービスにご連絡ください。' ).response purchase_result = handler_input.request_envelope.request.payload.get( 'purchaseResult') should_end_session = False speech = '購入フローにはいりませんでした。' if purchase_result == PurchaseResult.ACCEPTED.value: # ユーザーは製品の購入オファーを受け入れました # ex) amzn1.adg.product.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX product_id = handler_input.request_envelope.request.payload.get( 'productId') product = util.get_skill_product( in_skill_response, product_id=product_id) fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': True, 'intent': 'Connections.Response', 'product_reference_name': product.reference_name, 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) session = handler_input.attributes_manager.session_attributes if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'destinations_choice' in response: session['destinations_choice'] = response[ 'destinations_choice'] if 'turn_times' in response: session['turn_times'] = response['turn_times'] if 'total_ticket_amount' in response: session['total_ticket_amount'] = response[ 'total_ticket_amount'] image_url = response.get('image_url') bg_image_url = response.get('bg_image_url') image_title = response.get('image_title') image_text = response.get('image_text') if image_url: img_obj = Image(sources=[ImageInstance(url=image_url)]) bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)]) if util.is_support_display(handler_input): handler_input.response_builder.add_directive( RenderTemplateDirective( BodyTemplate7( back_button=BackButtonBehavior.VISIBLE, image=img_obj, background_image=bg_img_obj, title='') ) ) else: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) speech = response["response_text"] elif purchase_result == PurchaseResult.DECLINED.value: session = handler_input.attributes_manager.session_attributes destinations_choice = session.get('destinations_choice') fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'state': 'Launch', 'destinations_choice': destinations_choice, 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] speech = response["response_text"] image_url = response.get('image_url') bg_image_url = response.get('bg_image_url') image_title = response.get('image_title') image_text = response.get('image_text') if image_url: img_obj = Image(sources=[ImageInstance(url=image_url)]) bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)]) if util.is_support_display(handler_input): handler_input.response_builder.add_directive( RenderTemplateDirective( BodyTemplate7( back_button=BackButtonBehavior.VISIBLE, image=img_obj, background_image=bg_img_obj, title='') ) ) else: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) elif purchase_result == PurchaseResult.ERROR.value: # 内部エラーが発生しました speech = '内部エラーが発生しました' should_end_session = True elif purchase_result == PurchaseResult.ALREADY_PURCHASED.value: # ユーザーはすでに製品を購入しています speech = 'ユーザーはすでに製品を購入しています' elif purchase_result == PurchaseResult.NOT_ENTITLED.value: # ユーザーは資格のない製品をキャンセル/返品しようとしました speech = 'ユーザーは資格のない製品をキャンセルまたは返品しようとしました' handler_input.response_builder.speak(speech).ask( speech).set_should_end_session(should_end_session) return handler_input.response_builder.response
def handle(self, handler_input: HandlerInput) -> Response: session = handler_input.attributes_manager.session_attributes state = session.get('state') node = session.get('node') destinations_choice = session.get('destinations_choice') total_ticket_amount = session.get('total_ticket_amount') turn_times = session.get('turn_times') not_enough_gem = session.get('not_enough_gem') fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'intent': 'AMAZON.YesIntent', 'state': state, 'node': node, 'destinations_choice': destinations_choice, 'total_ticket_amount': total_ticket_amount, 'turn_times': turn_times, 'not_enough_gem': not_enough_gem, 'env_type': util.get_env_type(handler_input) } if node: fof_sfn_input['node'] = node if node == 'recommend_gem' or node == 'ask_gem_pack': in_skill_response = util.in_skill_product_response( handler_input) product_name = session.get('product_name') skill_product = util.get_skill_product( in_skill_response, product_name) return handler_input.response_builder.add_directive( SendRequestDirective( name='Buy', payload={ 'InSkillProduct': { 'productId': skill_product.product_id } }, token='correlationToken' ) ).response print(fof_sfn_input) response = sfn_ctl.execute(fof_sfn_input) if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'destinations_choice' in response: session['destinations_choice'] = response['destinations_choice'] if 'turn_times' in response: session['turn_times'] = response['turn_times'] if 'total_ticket_amount' in response: session['total_ticket_amount'] = response['total_ticket_amount'] if 'product_name' in response: session['product_name'] = response['product_name'] if 'not_enough_gem' in response: session['not_enough_gem'] = response['not_enough_gem'] image_url = response.get('image_url') bg_image_url = response.get('bg_image_url') image_title = response.get('image_title') image_text = response.get('image_text') if image_url: img_obj = Image(sources=[ImageInstance(url=image_url)]) bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)]) if util.is_support_display(handler_input): handler_input.response_builder.add_directive( RenderTemplateDirective( BodyTemplate7( back_button=BackButtonBehavior.VISIBLE, image=img_obj, background_image=bg_img_obj, title='') ) ) else: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) speech_text = response["response_text"] handler_input.response_builder.speak(speech_text).ask(speech_text) return handler_input.response_builder.response
def handle(self, handler_input: HandlerInput) -> Optional[Response]: session = handler_input.attributes_manager.session_attributes node = session.get('node') state = session.get('state') total_ticket_amount = session.get('total_ticket_amount') turn_times = session.get('turn_times') if state == 'ganesha': fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'state': 'ganesha', 'node': node, 'total_ticket_amount': total_ticket_amount, 'turn_times': turn_times, 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) else: fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': True, 'state': state, 'intent': 'UseIntent', 'node': node, 'env_type': util.get_env_type(handler_input) } response = sfn_ctl.execute(fof_sfn_input) if response.get('state') == 'Buy': in_skill_response = util.in_skill_product_response( handler_input) product_name = session.get('product_name') skill_product = util.get_skill_product( in_skill_response, product_name) return handler_input.response_builder.add_directive( SendRequestDirective( name='Buy', payload={ 'InSkillProduct': { 'productId': skill_product.product_id } }, token='correlationToken' ) ).response if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'destinations_choice' in response: session['destinations_choice'] = response['destinations_choice'] if 'turn_times' in response: session['turn_times'] = response['turn_times'] if 'total_ticket_amount' in response: session['total_ticket_amount'] = response['total_ticket_amount'] speech_text = response["response_text"] handler_input.response_builder.speak(speech_text).ask(speech_text) return handler_input.response_builder.response
def handle(self, handler_input: HandlerInput) -> Optional[Response]: session = handler_input.attributes_manager.session_attributes destinations_choice = session.get('destinations_choice') fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'intent': 'GaneshaShopIntent', 'state': 'Ganesha', 'destinations_choice': destinations_choice, 'env_type': util.get_env_type(handler_input), } if 'node' in session: if session.get('state') == 'Ganesha': fof_sfn_input['node'] = session['node'] response = sfn_ctl.execute(fof_sfn_input) if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'turn_times' in response: session['turn_times'] = response['turn_times'] speech_text = response["response_text"] image_url = response.get('image_url') bg_image_url = response.get('bg_image_url') image_title = response.get('image_title') image_text = response.get('image_text') if image_url: img_obj = Image(sources=[ImageInstance(url=image_url)]) bg_img_obj = Image(sources=[ImageInstance(url=bg_image_url)]) if util.is_support_display(handler_input): handler_input.response_builder.add_directive( RenderTemplateDirective( BodyTemplate7( back_button=BackButtonBehavior.VISIBLE, image=img_obj, background_image=bg_img_obj, title='') ) ) else: handler_input.response_builder.set_card( ui.StandardCard( title='', text='', image=ui.Image( small_image_url=image_url, large_image_url=image_url ) ) ) handler_input.response_builder.speak(speech_text).ask( speech_text) return handler_input.response_builder.response
def handle(self, handler_input: HandlerInput) -> Response: session = handler_input.attributes_manager.session_attributes state = session.get('state') node = session.get('node') destinations_choice = session.get('destinations_choice') total_ticket_amount = session.get('total_ticket_amount') turn_times = session.get('turn_times') not_enough_gem = session.get('not_enough_gem') intent = handler_input.request_envelope.request.intent.name fof_sfn_input = { 'alexa_user_id': handler_input.request_envelope.context.system.user.user_id, 'IsPreResponse': False, 'intent': intent, 'state': state, 'node': node, 'destinations_choice': destinations_choice, 'total_ticket_amount': total_ticket_amount, 'turn_times': turn_times, 'not_enough_gem': not_enough_gem, 'env_type': util.get_env_type(handler_input) } if state == 'ganesha' and node == 'launch': if handler_input.request_envelope.request.intent.name == 'AMAZON.NoIntent': speech = '本日も祈りを受け入れてくださり、ありがとうございました。 ' \ 'また信仰を捧げさせていただく機会を、どうか、お与えくださいませ。' handler_input.response_builder.speak(speech).ask( speech).set_should_end_session(True) return handler_input.response_builder.response slots = handler_input.request_envelope.request.intent.slots if slots: village = slots['village'].value if 'village' in slots else '' fof_sfn_input['destination'] = village if 'turn_times' in slots: turn_times = int(slots['turn_times'].value) if not valid_turn_times(turn_times): speech_text = '一回か十回で!' handler_input.response_builder.speak(speech_text).ask( speech_text) return handler_input.response_builder.response fof_sfn_input['turn_times'] = turn_times response = sfn_ctl.execute(fof_sfn_input) print(f'response: {response}, type: {type(response)}') if 'state' in response: session['state'] = response['state'] if 'node' in response: session['node'] = response['node'] if 'destinations_choice' in response: session['destinations_choice'] = response['destinations_choice'] if 'turn_times' in response: session['turn_times'] = response['turn_times'] if 'total_ticket_amount' in response: session['total_ticket_amount'] = response['total_ticket_amount'] if 'product_name' in response: session['product_name'] = response['product_name'] if 'not_enough_gem' in response: session['not_enough_gem'] = response['not_enough_gem'] speech_text = response["response_text"] image_url = response.get('image_url') if image_url: handler_input.response_builder.set_card( ui.StandardCard(title='', text='', image=ui.Image(small_image_url=image_url, large_image_url=image_url))) handler_input.response_builder.speak(speech_text).ask( speech_text).set_should_end_session( response.get('set_should_end_session', True)) return handler_input.response_builder.response