timheuer / alexa-skills-dotnet

An Amazon Alexa Skills SDK for .NET
MIT License
547 stars 108 forks source link

Add Pin Confirmation helpers #239

Closed stoiveyp closed 2 years ago

stoiveyp commented 2 years ago

PIN Verification is now a generally available option for skill developers, but it relies on being able to send StartConnection Directives and SessionResumedRequests sending back the result.

Although we've made this scenario extensible, this is functionality that shouldn't be difficult to implement as it's invaluable for anyone dealing with more sensitive user information.

This PR provides the model available so that asking for a pin request is a small addition to a response

skillResponse.Response.Directives.Add(
    new StartConnectionDirective(new PinConfirmation(),"token")
);`

and when the user receives their token back as a SessionResumedRequest we help them get the result

if (skillRequest.Request is SessionResumedRequest resumed && resumed.Cause.Token == "token")
{
    var pinConfirmationResult = PinConfirmationConverter.ResultFromSessionResumed(resumed);
}

Amazon Document: https://developer.amazon.com/en-US/docs/alexa/custom-skills/pin-confirmation-for-alexa-skills.html