Created
April 23, 2017 04:59
-
-
Save anonymous/a31a6e6dbe310fa65ba759efd9309675 to your computer and use it in GitHub Desktop.
Sample Alexa skill built using Alexa sdk at https://www.nuget.org/packages/VisidsuTech.AlexaNet/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sample Alexa skill built using Alexa sdk at https://www.nuget.org/packages/VisidsuTech.AlexaNet/ | |
/// </summary> | |
class SampleAlexaSkill : IAlexaSkill | |
{ | |
private static Dictionary<string, Dictionary<string[], string>> slotValueConvertions = new Dictionary<string, Dictionary<string[], string>>() | |
{ | |
// converts (one, first) to (one) for slot named "slot1" | |
{ | |
"slot1", | |
new Dictionary<string[], string>(){{new[]{"one", "first"}, "one"} } | |
} | |
}; | |
private static Dictionary<string, Func<AlexaRequest, Task<AlexaResponse>>> actions = new Dictionary<string, Func<AlexaRequest, Task<AlexaResponse>>>() | |
{ | |
// calls the function "Intent1Action" for intent "Intent1" | |
{"Intent1", Intent1Action} | |
}; | |
private static AlexaRequestExecutor requestExecutor; | |
/// <summary> | |
/// Replace with real application Id of alexa skill. | |
/// </summary> | |
private static string alexaAppId = "<replace with Alexa appId>"; | |
/// <summary> | |
/// Initializes Alexa request executor. | |
/// </summary> | |
static SampleAlexaSkill() | |
{ | |
var alexaAuth = new AlexaServiceAuth(alexaAppId); | |
var alexaSkill = new SampleAlexaSkill(); | |
requestExecutor = new AlexaRequestExecutor(alexaAuth, alexaSkill); | |
} | |
/// <summary> | |
/// Executes a Http request with alexa payload. This function can be called from a http service (like azure function) to serve a response. | |
/// </summary> | |
/// <param name="request">Http request which contains alexa payload</param> | |
/// <returns>Http response with alexa response payload.</returns> | |
public static Task<HttpResponseMessage> ExecuteRequest(HttpRequestMessage request) | |
{ | |
return requestExecutor.Run(request); | |
} | |
/// <summary> | |
/// Contains all slot value conversions, use this to normalize slot values. | |
/// </summary> | |
public Dictionary<string, Dictionary<string[], string>> SlotValueConvertions => slotValueConvertions; | |
public Dictionary<string, Func<AlexaRequest, Task<AlexaResponse>>> Actions => throw new NotImplementedException(); | |
public Task<AlexaResponse> LaunchAction(AlexaRequest request) | |
{ | |
return Task.FromResult<AlexaResponse>( | |
new AlexaResponse() | |
{ | |
Details = new AlexaResponseDetails() | |
{ | |
OutputSpeech = new AlexaOutputSpeech() | |
{ | |
Type = AlexaOutputSpeechType.PlainText, | |
Text = "This is a sample alexa skill" | |
} | |
} | |
}); | |
} | |
private static Task<AlexaResponse> Intent1Action(AlexaRequest request) | |
{ | |
return Task.FromResult<AlexaResponse>( | |
new AlexaResponse() | |
{ | |
Details = new AlexaResponseDetails() | |
{ | |
OutputSpeech = new AlexaOutputSpeech() | |
{ | |
Type = AlexaOutputSpeechType.PlainText, | |
Text = "Intent 1 was invoked" | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment