public void DirectiveResponse() { AlexaResponse resp = new AlexaResponse { Version = "1.0", Response = new AlexaResponseAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("You are hearing me talk."), Card = CardBuilder.GetSimpleCardResponse("Card Title", "This is some card text."), }, }; DisplayDirectiveResponse displayResp = new DisplayDirectiveResponse(); displayResp.Template = new DisplayTemplate(); displayResp.Template.Type = DisplayTemplateTypeEnum.BodyTemplate3; displayResp.Template.Token = "user_email"; displayResp.Template.Title = "Display Title"; displayResp.Template.TextContent = new DisplayTextContent(); displayResp.Template.TextContent.PrimaryText = new DisplayTextField(); displayResp.Template.TextContent.PrimaryText.Type = DisplayTextTypeEnum.RichText; displayResp.Template.TextContent.PrimaryText.Text = "<b><font size=\"6\">Some bold text</font></b>"; displayResp.Template.Image = new DisplayDirectiveImage("small image", "http://pathtosomeimage"); displayResp.Template.BackgroundImage = new DisplayDirectiveImage("background image", "http://pathtosomebackgroundimage"); resp.Response.Directives = new List <DirectiveResponse>(); resp.Response.Directives.Add(displayResp); string textResp = JsonConvert.SerializeObject(resp, Formatting.Indented); // The text should serialize to empty brackets. }
private AlexaResponse MergeNodeResponses(AdventureNode parentNode, AdventureNode subNode, string voiceId) { AlexaResponse resp = new AlexaResponse(); resp.Version = "1.0"; resp.Response = new AlexaResponseAttributes(); List <SpeechFragement> outFragments = new List <SpeechFragement>(); outFragments.AddRange(parentNode.OutputSpeech); if (subNode != null) { outFragments.AddRange(subNode.Reprompt); } resp.Response.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech( AdventureNode.GetSpeechText(outFragments, _linkProcessor, voiceId)); if ((subNode?.Reprompt?.Any()).GetValueOrDefault(false)) { resp.Response.Reprompt = new RepromptAttributes(); resp.Response.Reprompt.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech( AdventureNode.GetSpeechText(subNode.Reprompt, _linkProcessor, voiceId)); } return(resp); }
private async Task <AlexaResponse> GetLaunchResponseAsync(AlexaRequest request) { Adventure adv = await _adventureRep.GetAdventureAsync(); AdventureNode curNode = await _curNodeRep.GetCurrentNodeAsync(request, adv.Nodes); // If there is a current node that has choices, then let the user resume. bool nodeHasChoices = (curNode?.NodeRoutes?.Any()).GetValueOrDefault(false); AlexaResponse resp; if (!nodeHasChoices) { string welcomeText = "Welcome to the Adventure Sample. When you are ready to start the adventure, say begin"; resp = new AlexaResponse { Version = "1.0", Response = new AlexaResponseAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech(welcomeText), Card = CardBuilder.GetSimpleCardResponse("Welcome to the Adventure", welcomeText), Reprompt = new RepromptAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("Say begin when you're ready to begin") } } }; } else { string resumeText = "Welcome back! You have an adventure in progress. Would you like to resume or restart?"; resp = new AlexaResponse { Version = "1.0", Response = new AlexaResponseAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech(resumeText), Card = CardBuilder.GetSimpleCardResponse("Welcome Back to the Adventure", resumeText), Reprompt = new RepromptAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("You can resume or restart.") } } }; } return(resp); }
internal AlexaResponse ToAlexaResponse(IMediaLinkProcessor linkProcessor, string voiceId) { AlexaResponse resp = new AlexaResponse() { Version = "1.0", Response = new AlexaResponseAttributes() { OutputSpeech = new OutputSpeechAttributes() } }; resp.Response.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(GetSpeechText(this.OutputSpeech, linkProcessor, voiceId)); string repromptText = GetSpeechText(this.Reprompt, linkProcessor, voiceId); if (!string.IsNullOrWhiteSpace(repromptText)) { resp.Response.Reprompt = new RepromptAttributes() { OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(repromptText) }; } if (this.Card != null) { if (!string.IsNullOrWhiteSpace(this.Card.LargeImage) || !string.IsNullOrWhiteSpace(this.Card.SmallImage)) { resp.Response.Card = CardBuilder.GetStandardCardResponse(this.Card.Title, this.Card.Text, linkProcessor.GetImageUrl(this.Card.SmallImage), linkProcessor.GetImageUrl(this.Card.LargeImage)); } else { resp.Response.Card = CardBuilder.GetSimpleCardResponse(this.Card.Title, this.Card.Text); } } if ((NodeRoutes?.Any()).GetValueOrDefault(false)) { resp.Response.ShouldEndSession = false; } else { // there are no choices available. End the session. resp.Response.ShouldEndSession = true; } return(resp); }
public void SimpleResponse() { string textResp = "You are following a path in forest and have come to a fork. Would you like to go left or right?"; StringBuilder ssmlSample = new StringBuilder(); ssmlSample.Append("<speak><audio src='https://dev-sbsstoryengine.s3.amazonaws.com/stories/animalfarmpi/audio/Act1-OpeningMusic-alexa.mp3'/> "); ssmlSample.Append("It was a dark and stormy night. <break time='500ms'/>"); ssmlSample.Append("<say-as interpret-as='interjection'>no way!</say-as> "); ssmlSample.Append("I'm not doing this. That doesn’t make any sense! That music didn’t sound dark and stormy at "); ssmlSample.Append("<prosody volume='x-loud' pitch='+10%'>all!</prosody>"); ssmlSample.Append(" It sounds to me more like a bright and chipper morning! Should we go with dark and stormy, or bright and chipper?"); ssmlSample.Append("</speak>"); StringBuilder librarySample = new StringBuilder(); librarySample.Append("<speak>"); librarySample.Append(Office.ELEVATOR_BELL_1X_01); librarySample.Append("Your hotel is booked!"); librarySample.Append("</speak>"); AlexaResponse resp = new AlexaResponse { Version = "1.0", Response = new AlexaResponseAttributes { // OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech(textResp), OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(ssmlSample.ToString()), Card = CardBuilder.GetStandardCardResponse("Fork in the Road", textResp, "https://dev-custom.s3.amazonaws.com/adventuregame/images/forkintheroad_1200x600.png", "https://dev-custom.s3.amazonaws.com/adventuregame/images/forkintheroad_1200x600.png" ), Reprompt = new RepromptAttributes { OutputSpeech = OutputSpeechBuilder.GetPlainTextSpeech("Left or right?"), }, ShouldEndSession = false }, }; string textSer = JsonConvert.SerializeObject(resp, Formatting.Indented); // The text should serialize to empty brackets. }