question

jvgough avatar image
jvgough asked

How to return to intent after In skill purchase?

Hello,

I am creating a skill with in-skill purchases. I am able to trigger my purchase intent, and then Amazon prompts me to buy the product. I say yes, and then it says congrats, you've purchased the product. BUT THEN, it says "there was a problem with the requested skill's response." I've heard I need to use the correlation token to somehow return back to my skill. Any ideas or suggestions on how to trigger another intent after I'm done purchasing?


Thanks.

alexalambdapurchasing
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jvgough avatar image
jvgough answered

Here's the answer:

After a purchase is made, a simple speechlet response is to be returned, however my problem was:

The event that normally gets passed into my Lambda function contains a Session element, and I was first assigning that to a variable. The Connections.Response does not have a session element, so I had to wrap that in a try/except statement (assign session to variable, except if no session), and in the except I added in the AfterPurchase response. I'm sure there is a better way to do this (check if session element exists), but this is my current solution.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jason@Amazon avatar image
Jason@Amazon answered

You generally use a handler to take care of the Connections.Response event which is sent after a buy or upsell occurs. Check out this sample skill with sample code on how you might implement this.

4 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ok, I will check out the link. Just some more detail - I'm not using the SDK, so I am currently returning JSON from scratch. Now, my skill accepts sessions for each intent, and so I feel like my Response token should be a whole session, that way my intent accepts the format that it usually would, otherwise I'd have to pass in a special flag that specifies if it came in via the connections response and it would have to go through a whole nother flow.. Am I making any sense?

0 Likes 0 ·

It's hard to comment on your implementation as it isn't possible to check your code, but when you send the Connections.SendRequest directive, you include the correlationToken that you will receive back in the Connections.Response event, so using this would allow you to know where the event came from.

0 Likes 0 ·

Here is the JSON i'm returning after I trigger the purchase intent. It correctly kicks off the purchase of the product, however on return after purchase, it errors, saying that the response is NULL. I've double checked and it's not to do with the escape characters around the quotes. I don't know. I'm at a total loss.

{
  "version": "1.0",
  "sessionAttributes": {},
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>Purchasing Unlimited.</speak>"
    },
    "card": {
      "type": "Simple",
      "title": "SessionSpeechlet - PurchaseIntent",
      "content": "SessionSpeechlet - "
    },
    "reprompt": {
      "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>Purchase Unlimited .</speak>"
      }
    },
    "shouldEndSession": true,
    "directives": [
      {
        "type": "Connections.SendRequest",
        "name": "Buy",
        "payload": {
          "InSkillProduct": {
            "productId": "xxxproductidxxx"
          }
        },
        "token": "{\"user\": {\"userId\": \"xxxuserID\"}}"
      }
    ]
  }
}


0 Likes 0 ·
Show more comments
jvgough avatar image
jvgough answered

Here is the response: @Jason@amazon

    "request": {
        "type": "SessionEndedRequest",
        "requestId": "amzn1.echo-api.request.9bc1d6f1-e690-4756-b434-6b8bcc88f842",
        "timestamp": "2019-02-16T02:24:03Z",
        "locale": "en-US",
        "reason": "ERROR",
        "error": {
            "type": "INVALID_RESPONSE",
            "message": "An exception occurred while dispatching the request to the skill."
        }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.