Search code examples
javatestingoauth-2.0bddalexa-skills-kit

Alexa BDD tests


I am trying to implement BDD test on my Alexa skill. I am using Java SDK to implement it.

Basically, I would like to trigger arbitrary intents programmatically in my test suite and assert on responses, but I could not find any materials to implement it.

All I could find is com.amazon.ask.model.services.skillMessaging.SkillMessagingServiceClient.sendSkillMessage, whose Javadoc says:

Send a message request to a skill for a specified user.

That would be what I need, but, in order to create a com.amazon.ask.model.services.skillMessaging.SkillMessagingServiceClient, I have to do the following:

SkillMessagingServiceClient client = new SkillMessagingServiceClient(
                DefaultApiConfiguration.builder()
                        .withApiClient(ApacheHttpApiClient.standard())
                        .withSerializer(new JacksonSerializer())
                        .withAuthorizationValue("<authorization_token").build(),
                DefaultAuthenticationConfiguration.builder()
                        .withClientId("<client_id>")
                        .withClientSecret("<client_secret>")
                        .build()
        );

In order to get client_id and client_secret:

  1. I have accessed Login with Amazon Console
  2. I have created a security profile
  3. I have enabled Account Linking on my skill, with
    1. Authorization URI: https://www.amazon.com/ap/oa
    2. Access token URI: https://api.amazon.com/auth/o2/token
    3. Client ID and Client secret as from point 2
    4. Scopes: alexa:skill_messaging and profile:user_id
    5. Authentication schema: Basic
  4. I have copied all the Alexa Redirect URLs in the allowed return web URIs in my security profile

As a result, now my skill could be bound to my Amazon account from Alexa app, but:

  1. All in all, I just wanted to implement tests, NOT bind my account. My skill in production does not need this feature
  2. The binding does not work: after confirming it from Alexa app, I receive an error
  3. Yet I do not know how to collect the authentication token, unless I catch it from Cloudwatch log and use it... until it expires

At point 2, I could see the reason of the failure: oauthError (https://skills-store.amazon.it/external/link-result?success=false&errorKey=oauth-error&languageCode=it_IT&skillId=amzn1.ask.skill......&skillStage=development). The web page contains a link to RFC6749.

I am currently stuck and I can not test my skill completely, also because it is impossible to test Alexa Player, especially in Italian, unless you directly test it using a physical device.

Thanks for the help.


Solution

  • It seems you are confused between account linking and skill credentials. Account linking is for making api calls to external services on behalf of the user, E.G. I want my skill able to access user's google profile.

    Thus for your use case, skill credentials which used to make API calls to skill-related Alexa services seems good enough. Since you already got the clientId, client secrect, I would recommend you explore the Ask-Smapi-Sdk. You could follow the readme to retrieve the refreshToken through ask-cli, and build smapi client. With SmapiClient, you could use Smapi simulate apis to trigger your intents, specially the function simulateSkillV1 defined in your smapi Client.

    Hope this is what you need. ✧(•̀ω•́ )

    Thanks,
    Shen