public static AdaptiveCard GetAdaptiveCard(QnAMakerResult result)
        {
            AdaptiveCard card = new AdaptiveCard()
            {
                // Defining the Body contents of the card
                Body = new List <AdaptiveElement>()
                {
                    new AdaptiveContainer()
                    {
                        Items = new List <AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                Text   = result.Questions[0],
                                Weight = AdaptiveTextWeight.Bolder,
                                Size   = AdaptiveTextSize.Medium,
                                Wrap   = true
                            },
                            new AdaptiveTextBlock()
                            {
                                Text   = result.Answer,
                                Weight = AdaptiveTextWeight.Normal,
                                Size   = AdaptiveTextSize.Normal,
                                Wrap   = true
                            }
                        }
                    }
                },
            };

            return(card);
        }
示例#2
0
        //Added By Sumit
        protected static IMessageActivity ProcessResultAndCreateMessageActivity(IDialogContext context, ref QnAMakerResult result)
        {
            var message = context.MakeMessage();

            //var attachmentsItemRegex = new Regex("((&lt;attachment){1}((?:\\s+)|(?:(contentType=&quot;[\\w\\/]+&quot;))(?:\\s+)|(?:(contentUrl=&quot;[\\w:/.]+&quot;))(?:\\s+)|(?:(name=&quot;[\\w\\s]+&quot;))(?:\\s+)|(?:(thumbnailUrl=&quot;[\\w:/.]+&quot;))(?:\\s+))+(/&gt;))", RegexOptions.IgnoreCase);
            var attachmentsItemRegex = new Regex("((&lt;attachment){1}((?:\\s+)|(?:(contentType=&quot;[\\w\\/-]+&quot;))(?:\\s+)|(?:(contentUrl=&quot;[\\w:/.=?-]+&quot;))(?:\\s+)|(?:(name=&quot;[\\w\\s&?\\-.@%$!£\\(\\)]+&quot;))(?:\\s+)|(?:(thumbnailUrl=&quot;[\\w:/.=?-]+&quot;))(?:\\s+))+(/&gt;))", RegexOptions.IgnoreCase);
            var matches = attachmentsItemRegex.Matches(result.Answer);

            foreach (var attachmentMatch in matches)
            {
                result.Answer = result.Answer.Replace(attachmentMatch.ToString(), string.Empty);

                var    match        = attachmentsItemRegex.Match(attachmentMatch.ToString());
                string contentType  = string.Empty;
                string name         = string.Empty;
                string contentUrl   = string.Empty;
                string thumbnailUrl = string.Empty;

                foreach (var group in match.Groups)
                {
                    if (group.ToString().ToLower().Contains("contenttype="))
                    {
                        contentType = group.ToString().ToLower().Replace(@"contenttype=&quot;", string.Empty).Replace("&quot;", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("contenturl="))
                    {
                        contentUrl = group.ToString().ToLower().Replace(@"contenturl=&quot;", string.Empty).Replace("&quot;", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("name="))
                    {
                        name = group.ToString().ToLower().Replace(@"name=&quot;", string.Empty).Replace("&quot;", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("thumbnailurl="))
                    {
                        thumbnailUrl = group.ToString().ToLower().Replace(@"thumbnailurl=&quot;", string.Empty).Replace("&quot;", string.Empty);
                    }
                }

                var attachment = new Attachment(contentType, contentUrl, name: !string.IsNullOrEmpty(name) ? name : null, thumbnailUrl: !string.IsNullOrEmpty(thumbnailUrl) ? thumbnailUrl : null);
                message.Attachments.Add(attachment);
            }

            return(message);
        }
        protected virtual async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResult result)
        {
            result.Score /= 100;
            var answer = result.Score >= result.ServiceCfg.ScoreThreshold ? result.Answer : result.ServiceCfg.DefaultMessage;

            await context.PostAsync(HttpUtility.HtmlDecode(answer));
        }
 protected virtual async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResult result)
 {
     context.Wait(MessageReceivedAsync);
 }