1

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!

Quang Thái
  • 649
  • 5
  • 17
  • Does this answer your question? [Sample python code for Account Linking in Amazon Alexa](https://stackoverflow.com/questions/51358106/sample-python-code-for-account-linking-in-amazon-alexa) – Oscar Schafer May 06 '20 at 10:35
  • No, i found that answer. I tried to follow that instruction but nothing happened, because there was no code in that post. So that i decided to post the new question here :( – Quang Thái May 06 '20 at 13:01
  • We use `from ask_sdk_model.iu import Card` and `Card('LinkAccount')` but this produces the same (working) end result as what have. I also tested it ending and not ending the session. I think you've got a problem elsewhere... but I can't find it in the code you've provided. ¯\\_(ツ)_/¯ – Timothy Aaron May 08 '20 at 13:01
  • the problem was i passed speech as parameter to LinkAccountCard(), so it didnt work. I changed to "from ask_sdk_model.iu import Card" to import and "handler_input.response_builder.set_card(Card('LinkAccount'))" in the response and then it works perfectly! – Quang Thái May 11 '20 at 09:22

2 Answers2

1

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'))
Timothy Aaron
  • 3,059
  • 19
  • 22
0

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