Exemple #1
0
        public virtual async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
        {
            var messageActivity = ProcessResultAndCreateMessageActivity(context, ref result);

            messageActivity.Text = result.Answer;
            await context.PostAsync(messageActivity);

            context.Wait(MessageReceived);
        }
Exemple #2
0
        protected static IMessageActivity ProcessResultAndCreateMessageActivity(IDialogContext context, ref QnAMakerResult result)
        {
            var message = context.MakeMessage();

            //var attachmentsItemRegex = new Regex("((<attachment){1}((?:\\s+)|(?:(contentType="[\\w\\/]+"))(?:\\s+)|(?:(contentUrl="[\\w:/.]+"))(?:\\s+)|(?:(name="[\\w\\s]+"))(?:\\s+)|(?:(thumbnailUrl="[\\w:/.]+"))(?:\\s+))+(/>))", RegexOptions.IgnoreCase);
            var attachmentsItemRegex = new Regex("((<attachment){1}((?:\\s+)|(?:(contentType="[\\w\\/-]+"))(?:\\s+)|(?:(contentUrl="[\\w:/.=?-]+"))(?:\\s+)|(?:(name="[\\w\\s&?\\-.@%$!£\\(\\)]+"))(?:\\s+)|(?:(thumbnailUrl="[\\w:/.=?-]+"))(?:\\s+))+(/>))", 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="", string.Empty).Replace(""", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("contenturl="))
                    {
                        contentUrl = group.ToString().ToLower().Replace(@"contenturl="", string.Empty).Replace(""", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("name="))
                    {
                        name = group.ToString().ToLower().Replace(@"name="", string.Empty).Replace(""", string.Empty);
                    }
                    if (group.ToString().ToLower().Contains("thumbnailurl="))
                    {
                        thumbnailUrl = group.ToString().ToLower().Replace(@"thumbnailurl="", string.Empty).Replace(""", 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);
        }
Exemple #3
0
        public virtual async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
        {
            await context.PostAsync(result.Answer);

            context.Wait(MessageReceived);
        }