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 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); }