ask-sdk python to return LinkAccountCard

241 Views Asked by At

I'm newbie to Alexa custom skill and if my users trigger an intent which requires authentication, i want them to link their accounts to continue using my skill. Of course my skill needs to return an instructions for them to know how to link their account.

I found in the Officical docs but unfortunately there is no example code for python. After hours researching on internet, i found LinkAccountClass on ask_sdk_model.ui. So i started to add this class to my code like that:

from ask_sdk_model.ui import LinkAccountCard if not handler_input.request_envelope.context.system.user.access_token: speech = "You must open alexa app on your phone and link you account to continue" handler_input.response_builder.speak(speech).set_card(LinkAccountCard(speech)) return handler_input.response_builder.set_should_end_session(False).response

But Alexa keeps saying to me that "Sorry, i can't help you with this". If i use .set_card(SimpleCard(speech)) instead of .set_card(LinkAccountCard(speech)), Alexa display the message "You must open alexa app on your phone and link you account to continue" without any error. So how can i return the linkAccountCard to user to help them go to the linking accout in setting?

Thank a lot!

2

There are 2 best solutions below

0
On BEST ANSWER

LinkAccountCard doesn't accept any parameters; change it to .set_card(LinkAccountCard()) and you should be good. Alexa provides the copy for that card.

Alternatively, you could use…

from ask_sdk_model.ui import Card

… 

handler_input.response_builder.set_card(Card('LinkAccount'))
0
On

You don't need to pass any parameters to the LinkAccountCard

Here's a sample code:

from ask_sdk_model.ui import LinkAccountCard

...

return handler_input.response_builder.speak("Hello").set_card(LinkAccountCard()).response