Example #1
0
        internal static IAlexaDirective ToAlexaDirective(this QnAAnswerModel qnAAnswer)
        {
            var directive = new DisplayDirective();
            if (qnAAnswer.IsFinal())
            {
                directive.Template = qnAAnswer.GenerateImageTemplate();
            }
            else
            {
                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);
                }

                directive.Template = qnAAnswer.GenerateDisplayListTemplate(listItems);
            }
            return directive;
        }
Example #2
0
            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))
            {
                qnAAnswer.Answer.Image = "https://esalcedoost.blob.core.windows.net/superhero/dc-comics-universe.jpg";
            };

            displayListTemplate.BackgroundImage = new Image()
            {
                ContentDescription = "background",
                Sources = new ImageSource[]
                    {
                        new ImageSource()
                        {
                            Url = qnAAnswer.Answer.Image
                        }
                    }
            };

            return displayListTemplate;
        }
Example #3
0
        internal static IActivity ToActivity(this QnAAnswerModel qnAAnswer)
        {
            IEnumerable <string> suggestedActions = qnAAnswer.Context?.Prompts?.Select(p => p.DisplayText);
            IMessageActivity     activity;

            if (suggestedActions != null && suggestedActions.Any())
            {
                activity = MessageFactory.SuggestedActions(suggestedActions, qnAAnswer.Answer.Text, qnAAnswer.Answer.SSML);
            }
            else
            {
                activity = MessageFactory.Text(qnAAnswer.Answer.Text, qnAAnswer.Answer.SSML);
            }

            activity.InputHint = qnAAnswer.IsFinal() ? InputHints.IgnoringInput : InputHints.ExpectingInput;

            return(activity);
        }
Example #4
0
        public 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);
        }
Example #5
0
 private static DisplayRenderBodyTemplate1 GenerateImageTemplate(this QnAAnswerModel qnAAnswer)
 {
     var displayTemplate = new DisplayRenderBodyTemplate1()
     {
         BackButton = BackButtonVisibility.HIDDEN,
         Title = string.Empty,
         Token = "string",
     };
     displayTemplate.BackgroundImage = new Image()
     {
         ContentDescription = "background",
         Sources = new ImageSource[]
             {
                 new ImageSource()
                 {
                     Url = qnAAnswer.Answer.Image
                 }
             }
     };
     return displayTemplate;
 }
Example #6
0
 internal static bool IsFinal(this QnAAnswerModel qnAAnswer)
 {
     return(!(string.IsNullOrEmpty(qnAAnswer.Answer.Image) ||
              string.Equals(qnAAnswer.Answer.Image, "https://esalcedoost.blob.core.windows.net/superhero/dc-comics-universe.jpg")));
 }