public IActionResult HandleSkillRequest([FromBody] SkillRequest skillRequest) { try{ // Security check if (skillRequest.Session.Application.ApplicationId != _appid) { return(BadRequest()); } var requestType = skillRequest.GetRequestType(); if (requestType == typeof(IntentRequest)) { var response = HandleIntents(skillRequest); return(Ok(response)); } else if (requestType == typeof(LaunchRequest)) { var response = HandleIntents(skillRequest); return(Ok(response)); } else if (requestType == typeof(AudioPlayerRequest)) { var speech = new SsmlOutputSpeech(); speech.Ssml = "<speak>Audio player repsonse</speak>"; var finalResponse = ResponseBuilder.Tell(speech); return(Ok(finalResponse)); } return(Ok(ErrorResponse())); } catch (Exception) { return(Ok(ErrorResponse())); } }
private SkillResponse MakeSkillResponse(string outputSpeech, bool shouldEndSession = false, AttributesDto triviaAttributes = null) { var speech = new SsmlOutputSpeech { Ssml = $"<speak>{outputSpeech}</speak>" }; var response = new ResponseBody { OutputSpeech = speech, ShouldEndSession = shouldEndSession }; var skillResponse = new SkillResponse { Response = response, Version = AlexaConstants.AlexaVersion }; if (triviaAttributes != null) { var sessionAttributesTemp = new Dictionary <string, object> { { "AttributesDto", JsonConvert.SerializeObject(triviaAttributes) } }; skillResponse.SessionAttributes = sessionAttributesTemp; skillResponse.Response.Directives.Add(new DialogElicitSlot(AlexaConstants.SlotName)); skillResponse.Response.Reprompt = new Reprompt { OutputSpeech = speech }; } return(skillResponse); }
private SkillResponse ErrorResponse() { var speech = new SsmlOutputSpeech(); speech.Ssml = "<speak>I'm sorry, something went wrong.</speak>"; return(ResponseBuilder.Tell(speech)); }
/// <summary> /// This method will handle the different intents /// </summary> /// <param name="input"></param> /// <returns>Ready-to-send SkillResponse</returns> private async Task <SkillResponse> HandleIntents(SkillRequest input) { var intentRequest = input.Request as IntentRequest; var speech = new SsmlOutputSpeech(); // check the name to determine what you should do if (intentRequest.Intent.Name.Equals("CatchAllIntent")) { var phrase = intentRequest.Intent.Slots["phrase"].Value; string answer = string.Empty; // get an answer from QnA Maker using (var client = new QnaMakerClient(_config.GetValue <string>("QnAMakerSubscriptionKey"))) { var result = await client.GenerateAnswer(new Guid(_config.GetValue <string>("QnAMakerKnowledgeBaseId")), phrase); answer = result.Answers[0].Answer; } speech.Ssml = $"<speak>{answer}</speak>"; var response = ResponseBuilder.Tell(speech); return(response); } else { return(ErrorResponse()); } }
public override void Handle(string input) { var skillRequest = JsonConvert.DeserializeObject <SkillRequest>(input); SkillResponse response = null; if (skillRequest.Request.Type == "LaunchRequest") { response = ResponseBuilder.Tell("Willkommen zum Tech-Weekly."); } else if (skillRequest.Request.Type == "IntentRequest") { var date = DateTime.Now.Date; var anwser = new SsmlOutputSpeech { Ssml = $"<speak>Heute ist<say-as interpret-as=\"date\">{date:dddd}</say-as></speak>" //Ssml = "<speak>Morgen ist <break> <amazon:effect name = \"whispered\"> Freitag</amazon:effect></speak>" //Ssml = "<speak>Anderer Text<amazon:effect name = \"whispered\"> Text ganz leise.</amazon:effect>.Weiterer Text</speak>" }; response = ResponseBuilder.Tell(anwser); } Context.WriteContent(JsonConvert.SerializeObject(response, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() })); }
/* HELPER FUNCTIONS */ //This function will help to create message response with response and repromt message public static SkillResponse CreateResponse(string responseMessage, string reprompt) { var speech = new SsmlOutputSpeech(); speech.Ssml = "<speak>" + responseMessage + "</speak>"; var repromptMessage = new SsmlOutputSpeech(); repromptMessage.Ssml = "<speak>" + reprompt + "</speak>"; var repromptBody = new Reprompt(); repromptBody.OutputSpeech = repromptMessage; var responseBody = new ResponseBody(); responseBody.OutputSpeech = speech; responseBody.ShouldEndSession = false; responseBody.Reprompt = repromptBody; var skillResponse = new SkillResponse(); skillResponse.Response = responseBody; skillResponse.Version = "1.0"; return(skillResponse); }
private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession, LaunchRequest launchRequest, IntentRequest intentRequest, Session session) { _logService.LogRequest(intentRequest, session, output); // Create the Simple card content. SimpleCard card = new SimpleCard(); card.Title = title; card.Content = output; SsmlOutputSpeech ssml = new SsmlOutputSpeech() { Ssml = "<speak>" + output + " </speak>" }; // Create the speechlet response. SpeechletResponse response = new SpeechletResponse() { ShouldEndSession = shouldEndSession, OutputSpeech = ssml, Card = card }; //response.Card = card; return(response); }
public async Task <SkillResponse> GetNextRaceIntent() { var speech = new SsmlOutputSpeech(); var request = new ErgastApi.Requests.RaceListRequest() { Season = ErgastApi.Requests.Seasons.Current, Round = ErgastApi.Requests.Rounds.Next }; var response = await _client.GetResponseAsync(request); //var nextrace = response.Races.FirstOrDefault(); string nextrace = null; if (nextrace != null) { speech.Ssml = $"<speak>Der nächste Tag</speak>"; } else { speech.Ssml = "<speak>Diese Saison gibt es kein Rennen mehr.</speak>"; } // create the response using the ResponseBuilder var finalResponse = ResponseBuilder.Tell(speech); return(finalResponse); }
private SpeechletResponse BuildSpeechletResponse(string title, string output, bool shouldEndSession, LaunchRequest launchRequest, IntentRequest intentRequest, Session session) { _logService.LogRequest(launchRequest, session, output); _logService.LogRequest(intentRequest, session, output); // Create the Simple card content. SimpleCard card = new SimpleCard() { Title = title, Content = output }; // Create the plain text output. SsmlOutputSpeech speech = new SsmlOutputSpeech(); speech.Ssml = "<speak>" + output + " </speak>"; // Create the speechlet response. SpeechletResponse response = new SpeechletResponse(); response.ShouldEndSession = shouldEndSession; response.OutputSpeech = speech; if (String.IsNullOrWhiteSpace(output)) { //response.Card = card; } return(response); }
public async Task <SkillResponse> GetStoreFrontSpeachResponse(int take = 5) { var storeFrontItems = await _storeFrontService.GetStorefront(take) .ConfigureAwait(false); var speechResponse = new SsmlOutputSpeech(); var builder = new StringBuilder($"<speak>Today's top {take} deals on Jane are:"); for (int i = 0; i < storeFrontItems.Count; i++) { StorefrontItem item = storeFrontItems[i]; string andFinal = ""; if (i == storeFrontItems.Count - 1) { andFinal = "and "; } builder.Append($" {andFinal}{item.Title}<break time=\"{phraseBreaktime}\"/> "); } //close the speech builder.Append("</speak>"); speechResponse.Ssml = builder.ToString(); var response = ResponseBuilder.Tell(speechResponse); return(response); }
public override SkillResponse Process(IntentRequest request) { var responseText = new StringBuilder(); //We will use SSML as reponse format //https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html responseText.Append("<speak>"); var helper = new QueueHelper <Appointment>( System.Environment.GetEnvironmentVariable("AppointmentQueueConnection", System.EnvironmentVariableTarget.Process)); var appointment = helper.Receive(); if (appointment != null) { responseText.Append("<audio src = 'https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_positive_response_01.mp3'/>"); responseText.Append(Ssml.SayAs(appointment.Subject, "interjection")); responseText.Append(Ssml.SayAs(appointment.Start, true)); responseText.Append("<break/>"); } else { responseText.Append("<audio src='soundbank://soundlibrary/cartoon/amzn_sfx_boing_long_1x_01'/>"); responseText.Append(Ssml.SayAs("You got all appointments! Get to work!", "interjection")); responseText.Append("<break/>"); } responseText.Append("</speak>"); SsmlOutputSpeech speech = new SsmlOutputSpeech(); speech.Ssml = responseText.ToString(); return(ResponseBuilder.Tell(speech)); }
public void SsmlTextConstructorSetsText() { var output = new Speech(new PlainText("testing output")).ToXml(); var ssmlText = new SsmlOutputSpeech(output); Assert.Equal(output, ssmlText.Ssml); }
public SkillResponse Handle(IntentRequest intentRequest, ILambdaContext context, Session session) { if (IsDialogIntentRequest(intentRequest)) { if (IsDialogSequenceComplete(intentRequest) == false) { return(ResponseBuilder.DialogDelegate(session)); } } var intent = intentRequest.Intent; var dateSlotValue = intent.Slots["date"].Value; var clubNameSlotValue = intent.Slots["clubName"].Value; var classNameSlotValue = intent.Slots["className"].Value; var date = NodaTime.AmazonDate.AmazonDateParser.Parse(dateSlotValue); var dateFrom = date.From.ToDateTimeUnspecified(); var dateTo = date.To.ToDateTimeUnspecified(); if (dateFrom == dateTo) { dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0); dateTo = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); } var goApiClient = new GoApiClient(); var result = goApiClient.UpcomingClasses(classNameSlotValue, clubNameSlotValue, dateFrom, dateTo).Result; if (result.Errors.Any()) { return(ResponseBuilder.Tell($"{result.Errors.First().Message}")); } var bookingsResponse = string.Join(',', result.Data.OrderBy(x => x.StartDate). Select(x => { var startDate = x.StartDate.ToString("dddd dd MMMM hh:mm tt", CultureInfo.CreateSpecificCulture("en-US")); return($" {x.ClassName} on {startDate}"); })); var speech = new SsmlOutputSpeech { Ssml = $"<speak>{ GetFirstPartResponse(result.Data.Count())}{ bookingsResponse}</speak>" }; var repromptMessage = new PlainTextOutputSpeech { Text = "Would you like to book one ?" }; var repromptBody = new Reprompt(); repromptBody.OutputSpeech = repromptMessage; var finalResponse = ResponseBuilder.Ask(speech, repromptBody); return(finalResponse); //return ResponseBuilder.Ask($"{GetFirstPartResponse(result.Data.Count())}{bookingsResponse}", // new Reprompt("Whould you like to book one? ")); }
public static void Abstract_intent_request__generate_alexa_ask_response() { // Arrange var speech = new SsmlOutputSpeech { Ssml = "foo-bar" }; var repromptMessage = new Reprompt { OutputSpeech = speech }; var expectedResponse = ResponseBuilder.Ask("foo-bar", repromptMessage); expectedResponse.SessionAttributes = new Dictionary <string, object>(); expectedResponse.Response.ShouldEndSession = true; // Act var response = AlexaResponse.GenerateAlexaAskResponse("foo-bar", new Dictionary <string, object>(), true); // Assert var expectedOutputSpeech = (PlainTextOutputSpeech)expectedResponse.Response.OutputSpeech; var responseOutputSpeech = (PlainTextOutputSpeech)response.Response.OutputSpeech; Assert.Equal(expectedOutputSpeech.Text, responseOutputSpeech.Text); Assert.Equal(expectedOutputSpeech.Type, responseOutputSpeech.Type); Assert.Equal(expectedResponse.SessionAttributes, response.SessionAttributes); }
public async Task <IActionResult> HandleSkillRequest([FromBody] SkillRequest input) { // Security check if (input.Session.Application.ApplicationId != _appid) { return(BadRequest()); } var requestType = input.GetRequestType(); if (requestType == typeof(IntentRequest)) { var response = await HandleIntentsAsync(input); return(Ok(response)); } if (requestType == typeof(LaunchRequest)) { var headlines = await GetHeadlinesAsync(); var speech = new SsmlOutputSpeech { Ssml = headlines.ToString() }; var finalResponse = ResponseBuilder.Tell(speech); return(Ok(finalResponse)); } return(Ok(ErrorResponse())); }
public static SkillResponse GetFinishedShoppingIntentResponse() { var speech = new SsmlOutputSpeech(); speech.Ssml = "<speak><amazon:emotion name=\"excited\" intensity=\"medium\">I've updated your board. Way to go!</amazon:emotion></speak>"; return(ResponseBuilder.Tell(speech)); }
private async Task <IActionResult> ProcessRequest(SkillRequest skillRequest) { var requestType = skillRequest.GetRequestType(); SkillResponse response = null; if (requestType == typeof(LaunchRequest)) { response = ResponseBuilder.Tell("Welcome a Dotnet Marraia temperature. Create By Fernando Mendes"); response.Response.ShouldEndSession = false; } else if (requestType == typeof(IntentRequest)) { var intentRequest = skillRequest.Request as IntentRequest; if (intentRequest.Intent.Name == "AddIntent") { var speech = new SsmlOutputSpeech(); var result = await GetTemperature(); speech.Ssml = $"<speak>The temperature in jundiaí at this moment is { result} degrees</speak>"; response = ResponseBuilder.TellWithCard(speech, "The answer is", $"The answer is: {result}"); response.Response.ShouldEndSession = false; } } else if (requestType == typeof(SessionEndedRequest)) { var speech = new SsmlOutputSpeech(); speech.Ssml = $"<speak>Bye Bye Marraia!!</speak>"; response = ResponseBuilder.TellWithCard(speech, "Bye Bye Marraia", "Marraia"); response.Response.ShouldEndSession = true; } return(new OkObjectResult(response)); }
public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context) { string accessKey = Environment.GetEnvironmentVariable("ACCESS_KEY"); string secretKey = Environment.GetEnvironmentVariable("SECRET_KEY"); string bucketStories = Environment.GetEnvironmentVariable("BUCKET_STORIES"); StoriesS3Service storiesService = new StoriesS3Service(accessKey, secretKey, bucketStories); string audioUrl; string audioToken; SsmlOutputSpeech ssmlResponse = new SsmlOutputSpeech(); if (input.GetRequestType() == typeof(LaunchRequest)) { ssmlResponse.Ssml = "<speak>You can't open this skill.</speak>"; } else if (input.GetRequestType() == typeof(IntentRequest)) { IntentRequest intentRequest = (IntentRequest)input.Request; switch (intentRequest.Intent.Name) { case "TellRandomStory": string randomStoryName = storiesService.GetRandomStoryName(await storiesService.ListStories()); audioUrl = storiesService.GetStoryUrl(randomStoryName); audioToken = "A story."; return(ResponseBuilder.AudioPlayerPlay(PlayBehavior.ReplaceAll, audioUrl, audioToken)); default: ssmlResponse.Ssml = $"<speak>An error has occurred!</speak>"; break; } } return(ResponseBuilder.Tell(ssmlResponse)); }
private SkillResponse createRoboterRequest(String answer, String endpointID, String nsName, dynamic data, Session _session) { //Befehl erstellen SendDirective directive = new SendDirective(endpointID, "Custom.Mindstorms.Gadget", nsName, data); // create the speech response var speech = new SsmlOutputSpeech(); speech.Ssml = $"<speak>{answer}</speak>"; //ResponseBody vorbereiten ResponseBody responseBody = new ResponseBody(); responseBody.OutputSpeech = speech; responseBody.ShouldEndSession = false; responseBody.Reprompt = new Reprompt("Was möchtest du tun?"); responseBody.Card = new SimpleCard { Title = "Debugging", Content = "Move Robot" }; responseBody.Directives.Add(directive); //Antwort vorbereiten var skillResponse = new SkillResponse(); skillResponse.SessionAttributes = _session.Attributes; skillResponse.Version = "1.0"; skillResponse.Response = responseBody; return(skillResponse); }
/// <summary> /// Handles different intents of the Alexa skill. /// </summary> /// <param name="input">current skill request</param> /// <returns></returns> private async Task <SkillResponse> HandleIntentsAsync(SkillRequest input) { if (!(input.Request is IntentRequest intentRequest)) { return(ErrorResponse()); } var speech = new SsmlOutputSpeech(); // check the name to determine what you should do var intentName = intentRequest.Intent.Name; if (intentName.Equals("Headlines")) { var headlines = await GetHeadlinesAsync(); speech.Ssml = headlines.ToString(); // create the response using the ResponseBuilder var finalResponse = ResponseBuilder.Tell(speech); return(finalResponse); } if (intentName.Equals("LatestPost")) { var sb = await GetLatestPostAsync(); speech.Ssml = sb.ToString(); var finalResponse = ResponseBuilder.Tell(speech); return(finalResponse); } return(ErrorResponse()); }
private async Task <SpeechletResponse> BuildSpeechletResponse(string title, string output, bool shouldEndSession) { // Create the Simple card content. SimpleCard card = new SimpleCard(); card.Title = String.Format("SessionSpeechlet - {0}", title); card.Subtitle = String.Format("SessionSpeechlet - Sub Title"); card.Content = String.Format("SessionSpeechlet - {0}", output); // Create the plain text output. //PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); SsmlOutputSpeech speech = new SsmlOutputSpeech(); speech.Ssml = string.Format("<speak>{0}</speak>", output); // Create the speechlet response. SpeechletResponse response = new SpeechletResponse(); response.ShouldEndSession = shouldEndSession; response.OutputSpeech = speech; response.Card = card; return(response); }
private async Task <SkillResponse> HandleStartQuizIntentRequestAsync(SkillRequest request, IntentRequest intentRequest) { var topic = intentRequest.Intent.Slots["topic"]?.Value; IQuiz quiz; if (topic != null) { quiz = await _db.RandomQuizAsync(topic) ?? await _db.RandomQuizAsync(); } else { quiz = await _db.RandomQuizAsync(); } var state = new State(quiz.Id, questionsAsked: 1); var session = request.Session; state.WriteTo(session); var speech = new SsmlOutputSpeech { Ssml = quiz.Stages[0].AskedQuestionSsml() }; return(ResponseBuilder.Ask(speech, new Reprompt { OutputSpeech = speech }, session)); }
public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context) { try { var response = new StringBuilder(); var intentRequest = input.Request as IntentRequest; if (!(intentRequest is null)) { context.Logger.LogLine($"{intentRequest.Intent.Name} recognized."); var conditions = new List <ScanCondition>(); switch (intentRequest.Intent.Name) { case "nexteventByCityIntent": var citySlot = intentRequest.Intent.Slots["city"]; context.Logger.LogLine($"city = {citySlot.Value}"); conditions.Add(new ScanCondition("Date", ScanOperator.GreaterThanOrEqual, DateTime.Now)); conditions.Add(new ScanCondition("City", ScanOperator.Equal, citySlot.Value)); break; default: break; } var devdayEvents = await new DataManager().GetAllAsync <DevdayEvent>(conditions); if (devdayEvents.Count == 0) { response.Append("Al momento non sono previsti nuovi eventi."); } else { response.Append("I prossimi eventi sono: "); foreach (var item in devdayEvents.OrderBy(e => e.Date)) { var itaDate = item.Date.ToString("dddd, d MMMM yyyy", new CultureInfo("it-IT")); var itaHour = item.Date.ToString("H:mm", new CultureInfo("it-IT")); response.Append($"{item.Title} per {itaDate} alle {itaHour}, "); } } } else { response.Append("Mi dispiace, non ho capito."); } var speech = new SsmlOutputSpeech { Ssml = $"<speak>{response.ToString()}</speak>" }; return(ResponseBuilder.Tell(speech)); }
public void SerializesSsmlOutputSpeechWithPlayBehaviorToJson() { var ssmlOutputSpeech = new SsmlOutputSpeech { Ssml = "ssml content", PlayBehavior = PlayBehavior.ReplaceEnqueued }; Assert.True(Utility.CompareJson(ssmlOutputSpeech, "SsmlOutputSpeechWithPlayBehavior.json")); }
public void SerializesSsmlOutputSpeechToJson() { var ssmlOutputSpeech = new SsmlOutputSpeech { Ssml = "ssml content" }; Assert.True(Utility.CompareJson(ssmlOutputSpeech, "SsmlOutputSpeech.json")); }
/// <summary> /// Creates an error skill response. /// </summary> /// <returns></returns> private static SkillResponse ErrorResponse() { var speech = new SsmlOutputSpeech { Ssml = "<speak>An error has occurred, please try again.</speak>" }; return(ResponseBuilder.Tell(speech)); }
public static SkillResponse handleSpeech(int firstnumber, int secondnumber, string oper, int result) { var speech = new SsmlOutputSpeech(); speech.Ssml = $"<speak>{firstnumber} {oper} {secondnumber} equals {result}</speak>"; return(ResponseBuilder.Tell(speech)); }
public SpeechletResponse Say(SsmlOutputSpeech speechOutput, bool shouldEndSession = true) { return(new SpeechletResponse() { OutputSpeech = speechOutput, ShouldEndSession = shouldEndSession }); }
/// <summary> /// Creates an error skill response. /// </summary> /// <returns></returns> private static SkillResponse ErrorResponse() { var speech = new SsmlOutputSpeech { Ssml = "<speak>Irgendwas ist schiefgelaufen.</speak>" }; return(ResponseBuilder.Tell(speech)); }
public static SpeechletResponse BuildSpeechletResponse(SimpleIntentResponse simpleIntentResponse, bool shouldEndSession) { SpeechletResponse response = new SpeechletResponse(); response.ShouldEndSession = shouldEndSession; // Create the speechlet response from SimpleIntentResponse. // If there's an ssmlString use that as the spoken reply // If ssmlString is empty, speak cardText if (simpleIntentResponse.ssmlString != "") { SsmlOutputSpeech speech = new SsmlOutputSpeech(); speech.Ssml = simpleIntentResponse.ssmlString; response.OutputSpeech = speech; } else { PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); speech.Text = simpleIntentResponse.cardText; response.OutputSpeech = speech; } // if images are passed, then assume a standard card is wanted // images should be stored in the ~/Images/ folder and follow these requirements // JPEG or PNG supported, no larger than 2MB // 720x480 - small size recommendation // 1200x800 - large size recommendation if (simpleIntentResponse.smallImage != "" && simpleIntentResponse.largeImage != "") { StandardCard card = new StandardCard(); card.Title = AlexaConstants.AppName; card.Text = simpleIntentResponse.cardText; // The trailing slash after the image name is required because we're serving off the image through a Web API controller and // don't want to change the default web project settings card.Image = new Image() { LargeImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.largeImage + "/", SmallImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.smallImage + "/", }; response.Card = card; } else { SimpleCard card = new SimpleCard(); card.Title = AlexaConstants.AppName; card.Content = simpleIntentResponse.cardText; response.Card = card; } return(response); }