//--- Methods --- public override async Task <CustomSkillResponse> HandleRequest(CustomSkillRequest customSkillRequest) { var intentSlots = customSkillRequest.Intent.Slots; var intentName = customSkillRequest.Intent.Name; // lookup song title and artist GetSongInfoRequested(intentSlots); if (IsValidRequest()) { await FindRequestedSong(); } // generate sqs body and send to the queue var generatedMessage = GenerateMessage(); var sqsReuqest = GenerateJukeboxSqsRequest(intentName, generatedMessage, ""); await SendSqsRequest(sqsReuqest, intentName); // generate alexa response var customSkillResponse = new CustomSkillResponse { Message = generatedMessage }; LambdaLogger.Log($"*** INFO: Alexa response to user: {JsonConvert.SerializeObject(customSkillResponse)}"); return(customSkillResponse); }
public static async Task Speaker_request__function() { // Arrange var intentRequest = new CustomSkillRequest { DialogState = "STARTED", Intent = new Intent { Name = "SpeakerRequest", ConfirmationStatus = "NONE", Slots = new Dictionary <string, Slot> { { "Options", new Slot { Name = "Options", Value = "on" } } } }, Type = "IntentRequest" }; Mock <ICommonDependencyProvider> provider = new Mock <ICommonDependencyProvider>(MockBehavior.Strict); Mock <IAmazonSQS> sqsClient = new Mock <IAmazonSQS>(MockBehavior.Strict); var apiGatewayRequest = new APIGatewayProxyRequest { Body = JsonConvert.SerializeObject(intentRequest) }; var function = new Function { SpeakerRequest = new SpeakerRequest(provider.Object, sqsClient.Object, "foobar") }; // Act var result = await function.ProcessProxyRequestAsync(apiGatewayRequest); // Assert Assert.Equal(200, result.StatusCode); }
public static async Task Speaker_request__handle_request() { // Arrange var customSkillRequest = new CustomSkillRequest { Intent = new Intent { Name = "SpeakerRequest", Slots = new Dictionary <string, Slot> { { "Options", new Slot { Name = "Options", Value = "on" } } } }, DialogState = "STARTED", Type = "SpeakerRequest" }; Mock <ICommonDependencyProvider> provider = new Mock <ICommonDependencyProvider>(MockBehavior.Strict); Mock <IAmazonSQS> sqsClient = new Mock <IAmazonSQS>(MockBehavior.Strict); var speakerRequest = new SpeakerRequest(provider.Object, sqsClient.Object, "foo-bar-queue") { SpeakerAction = "on" }; // Act var response = await speakerRequest.HandleRequest(customSkillRequest); // Assert Assert.Equal("Turning the jukebox speaker on", response.Message); }
public async Task Play_song_request__handle_request() { // Arrange var customSkillRequest = new CustomSkillRequest { Intent = new Intent { Name = "PlaySongTitleArtistRequest", Slots = new Dictionary <string, Slot> { { "Title", new Slot { Name = "Title", Value = "I Will Wait" } }, { "ArtistName", new Slot { Name = "ArtistName", Value = "Mumford & Sons" } } } }, DialogState = "STARTED", Type = "PlaySongTitleArtistRequest" }; // mock dependency provider common Mock <ICommonDependencyProvider> provider = new Mock <ICommonDependencyProvider>(MockBehavior.Strict); // mock dependency provider sqs var request = new JukeboxSqsRequest { Key = "328", MessageBody = "foo-bar", RequestType = "PlaySongTitleArtistRequest" }; var sendMessageRequest = new SendMessageRequest { QueueUrl = "http://foo-bar", MessageGroupId = "bat-baz", MessageDeduplicationId = "foo-date", MessageBody = JsonConvert.SerializeObject(request) }; Mock <IAmazonSQS> sqsClient = new Mock <IAmazonSQS>(MockBehavior.Strict); sqsClient.Setup(x => x.SendMessageAsync(sendMessageRequest, new CancellationToken())); // mock dependency provider dynamodb IEnumerable <SongModel.Song> foundDynamodbSongs = new List <SongModel.Song> { SongFixtures.Song1 }; Mock <IDynamodbDependencyProvider> dynamodbProvider = new Mock <IDynamodbDependencyProvider>(MockBehavior.Strict); dynamodbProvider.Setup(x => x.DynamoDbFindSongsByTitleArtistAsync("I Will Wait", "Mumford & Sons")).Returns(Task.FromResult(foundDynamodbSongs)); var playSongRequest = new PlaySongTitleArtistRequest(provider.Object, sqsClient.Object, "http://foo-bar", dynamodbProvider.Object); // Act var response = await playSongRequest.HandleRequest(customSkillRequest); // Assert Assert.Contains("Sending song number 328", response.Message); }
//--- Methods --- public override async Task <CustomSkillResponse> HandleRequest(CustomSkillRequest customSkillRequest) { var intentSlots = customSkillRequest.Intent.Slots; var intentName = customSkillRequest.Intent.Name; FoundSongs = new List <SongModel.Song>(); SongRequested = new SongModel.Song(); // lookup song title and artist GetSongInfoRequested(intentSlots); if (IsValidRequest()) { await FindRequestedSong(); } // if no songs found, top matches if (FoundSongs.ToList().Count == 0) { await FindSimilarSongs(); } // generate sqs body and send to the queue var generatedMessage = GenerateMessage(); if (FoundSongs.ToList().Count == 1) { var sqsRequest = GenerateJukeboxSqsRequest(intentName, generatedMessage, FoundSongs.ToList().FirstOrDefault().SongNumber); await SendSqsRequest(sqsRequest, intentName); } else if (FoundSongs.ToList().Count > 1) { generatedMessage += "Top 3 matches: "; generatedMessage += FoundSongs.Aggregate(" ", (current, song) => current + $"Song {song.SongNumber} {song.Title} by {song.Artist}. "); } // generate alexa response var customSkillResponse = new CustomSkillResponse { Message = generatedMessage }; LambdaLogger.Log($"*** INFO: Alexa response to user: {JsonConvert.SerializeObject(customSkillResponse)}"); return(customSkillResponse); }
//--- Methods --- public override async Task <CustomSkillResponse> HandleRequest(CustomSkillRequest intentRequest) { var intentSlots = intentRequest.Intent.Slots; var intentName = intentRequest.Intent.Name; GetSongInfoRequested(intentSlots); // generate sqs body and send to the queue var generatedMessage = GenerateMessage(); var sqsReuqest = GenerateJukeboxSqsRequest(intentName, generatedMessage, SpeakerAction); await SendSqsRequest(sqsReuqest, intentName); // generate alexa response var customSkillResponse = new CustomSkillResponse { Message = generatedMessage }; LambdaLogger.Log($"*** INFO: Alexa response to user: {JsonConvert.SerializeObject(customSkillResponse)}"); return(customSkillResponse); }
public override Task <CustomSkillResponse> HandleRequest(CustomSkillRequest customSkillRequest) { throw new System.NotImplementedException(); }
public abstract Task <CustomSkillResponse> HandleRequest(CustomSkillRequest customSkillRequest);
public override async Task <SkillResponse> ProcessMessageAsync(SkillRequest skill) { LambdaLogger.Log($"*** INFO: Request input from user: {JsonConvert.SerializeObject(skill)}"); var intentRequest = (IntentRequest)skill.Request; var intentName = intentRequest.Intent.Name; var finalResponse = ResponseBuilder.Tell("Sorry I do not understand"); string endpointPath; // create custom skill request var customSkillRequest = new CustomSkillRequest { DialogState = intentRequest.DialogState, Intent = intentRequest.Intent, Type = intentRequest.Type }; LambdaLogger.Log($"**** INFO **** customSkillRequest: {customSkillRequest}"); switch (intentName) { // //-------------------------- // SPEAKER REQUEST //-------------------------- // case "SpeakerRequest": { LambdaLogger.Log("**** INFO **** Intent: SpeakerRequest"); endpointPath = $"{_endpoint}/jukebox-alexa/speaker-request"; } break; // //-------------------------- // PLAY SONG TITLE REQUEST //-------------------------- // case "PlaySongTitleRequest": { LambdaLogger.Log("**** INFO **** Intent: PlaySongTitleRequest"); endpointPath = $"{_endpoint}/jukebox-alexa/song-title-request"; } break; // //-------------------------- // PLAY NUMBER REQUEST //-------------------------- // case "PlaySongNumberRequest": { LambdaLogger.Log("**** INFO **** Intent: PlayNumberRequest"); endpointPath = $"{_endpoint}/jukebox-alexa/song-number-request"; } break; // //-------------------------- // PLAY SONG TITLE ARTIST REQUEST //-------------------------- // case "PlaySongTitleArtistRequest": { LambdaLogger.Log("**** INFO **** Intent: PlaySongTitleArtistRequest"); endpointPath = $"{_endpoint}/jukebox-alexa/song-title-artist-request"; } break; // //-------------------------- // DEFAULT //-------------------------- // default: { LambdaLogger.Log($"**** INFO **** Intent: Unsupported"); endpointPath = null; break; } } if (!endpointPath.IsNullOrEmpty()) { LambdaLogger.Log($"*** INFO: endpointPath: {endpointPath}"); var endpointPayload = new StringContent(JsonConvert.SerializeObject(customSkillRequest)); LambdaLogger.Log($"*** INFO: endpointPayload: {await endpointPayload.ReadAsStringAsync()}"); var endpointResponse = await _httpClient.PostAsync(endpointPath, endpointPayload); LambdaLogger.Log($"*** INFO: endpointResponse: {JsonConvert.SerializeObject(endpointResponse)}"); var responseResult = await endpointResponse.Content.ReadAsStringAsync(); var customSkillResponse = JsonConvert.DeserializeObject <CustomSkillResponse>(responseResult); LambdaLogger.Log($"*** INFO: customSkillResponse: {JsonConvert.SerializeObject(customSkillResponse)}"); finalResponse = AlexaResponse.Generate("tell", customSkillResponse.Message); } LambdaLogger.Log($"*** INFO: Alexa response to user: {JsonConvert.SerializeObject(finalResponse)}"); return(finalResponse); }