private static DisplayRenderListTemplate1 GenerateDisplayListTemplate(this QnAAnswerModel qnAAnswer, List <ListItem> listItems) { var displayListTemplate = new DisplayRenderListTemplate1() { BackButton = BackButtonVisibility.HIDDEN, Title = string.Empty, Token = "string", }; if (listItems.Count > 0) { displayListTemplate.ListItems = listItems; } if (!string.IsNullOrEmpty(qnAAnswer.Answer.Image)) { displayListTemplate.BackgroundImage = new Image() { ContentDescription = "background", Sources = new ImageSource[] { new ImageSource() { Url = qnAAnswer.Answer.Image } } }; } ; return(displayListTemplate); }
internal static IAlexaDirective ToAlexaDirective(this QnAAnswerModel qnAAnswer) { List <ListItem> listItems = new List <ListItem>(); ListItem listItem; IEnumerable <string> choices = qnAAnswer.Context?.Prompts?.Select(p => p.DisplayText) ?? Enumerable.Empty <string>(); foreach (string choice in choices) { listItem = new ListItem() { Token = choice, TextContent = new TextContent() { PrimaryText = new InnerTextContent() { Text = choice, Type = TextContentType.RichText } } }; listItems.Add(listItem); } var directive = new DisplayDirective() { Template = qnAAnswer.GenerateDisplayListTemplate(listItems) }; return(directive); }
internal static IAlexaDirective ToVideoDirective(this QnAAnswerModel qnAAnswer) { return(string.IsNullOrEmpty(qnAAnswer.Answer.Video) ? null : new VideoDirective() { VideoItem = new VideoItem() { Source = new Uri(qnAAnswer.Answer.Video), Metadata = new Metadata() { Title = qnAAnswer.Answer.Text, Subtitle = qnAAnswer.Answer.Text } } }); }
internal static IActivity ToActivity(this QnAAnswerModel qnAAnswer) { IEnumerable <string> suggestedActions = qnAAnswer.Context?.Prompts?.Select(p => p.DisplayText); IMessageActivity activity; if (suggestedActions != null) { activity = MessageFactory.SuggestedActions(suggestedActions, qnAAnswer.Answer.Text, qnAAnswer.Answer.SSML); } else { activity = MessageFactory.Text(qnAAnswer.Answer.Text, qnAAnswer.Answer.SSML); } activity.InputHint = InputHints.ExpectingInput; return(activity); }
internal async Task <QnAAnswerModel> GenerateAnswer(string message, string lang) { QnAAnswerModel qnAResponse = null; string route = $"generateAnswer"; var requestBody = JsonConvert.SerializeObject(new { question = message }); HttpContent httpContent = new StringContent(requestBody, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(route, httpContent); if (response.IsSuccessStatusCode) { qnAResponse = (await response.Content.ReadAsAsync <QnaResponse>()).Answers.FirstOrDefault(); } return(qnAResponse); }
internal static IActivity ToVideoActivity(this QnAAnswerModel qnAAnswer) { VideoCard videoCard = new VideoCard() { Title = "Video", Subtitle = string.Empty, Image = new ThumbnailUrl { Url = qnAAnswer.Answer.Video, }, Media = new List <MediaUrl> { new MediaUrl() { Url = qnAAnswer.Answer.Video, }, } }; IMessageActivity activity = MessageFactory.Attachment(videoCard.ToAttachment()); activity.InputHint = InputHints.AcceptingInput; return(activity); }