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); }
public static SpeechletResponse BuildSpeechletResponse(SimpleIntentResponse simpleIntentResponse, bool shouldEndSession) { SpeechletResponse response = new SpeechletResponse(); response.ShouldEndSession = shouldEndSession; List <Directives> directives = new List <Directives>(); // if there's a value present for musicUrl, this then generate the directives // required for Echo to play the requested track if (simpleIntentResponse.musicUrl != "") { // figure out if we are dealing with a multi-track album // the token we send Echo is in this format if so: // <MusicId>?<Index> string[] items = simpleIntentResponse.msgId.Split('?'); int msgAlbumIndex = -1; string msgAlbumId = ""; // if there are two members of the array item[] then // we are dealing with a multi-track album if (items.Length == 2) { msgAlbumId = items[0]; msgAlbumIndex = int.Parse(items[1]); } if (msgAlbumIndex < 1 || simpleIntentResponse.musicAction == "AMAZON.NextIntent") { directives = new List <Directives>() { new Directives() { type = "AudioPlayer.Play", playBehavior = "REPLACE_ALL", audioItem = new Directives.AudioItem() { stream = new Directives.Stream() { offsetInMilliseconds = 0, token = simpleIntentResponse.msgId, url = simpleIntentResponse.musicUrl, } }, } }; // the next intent doesn't require a card to be generated if (simpleIntentResponse.musicAction == "AMAZON.NextIntent") { response.Directives = directives; return(response); } } else { int previousIndex = msgAlbumIndex - 1; string previousToken = msgAlbumId + "?" + previousIndex; directives = new List <Directives>() { new Directives() { type = "AudioPlayer.Play", playBehavior = "ENQUEUE", audioItem = new Directives.AudioItem() { stream = new Directives.Stream() { offsetInMilliseconds = 0, token = simpleIntentResponse.msgId, url = simpleIntentResponse.musicUrl, expectedPreviousToken = previousToken, } }, } }; // the enqueue intent can not have a card associated with it // otherwise, Alexa will return an error response.Directives = directives; return(response); } response.Directives = directives; } // 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 + "/", LargeImageUrl = simpleIntentResponse.largeImage, SmallImageUrl = simpleIntentResponse.smallImage }; response.Card = card; } else { SimpleCard card = new SimpleCard(); card.Title = AlexaConstants.AppName; card.Content = simpleIntentResponse.cardText; response.Card = card; } return(response); }