public async Task OnProcessRequest(ITurnContext context, MiddlewareSet.NextDelegate next)
        {
            if (context.Activity.Type == ActivityTypes.Message)
            {
                var messageActivity = context.Activity.AsMessageActivity();
                if (!string.IsNullOrEmpty(messageActivity.Text))
                {
                    var results = await _qnaMaker.GetAnswers(messageActivity.Text.Trim()).ConfigureAwait(false);

                    if (results.Any())
                    {
                        if (!string.IsNullOrEmpty(_options.DefaultAnswerPrefixMessage))
                        {
                            await context.SendActivity(_options.DefaultAnswerPrefixMessage);
                        }

                        await context.SendActivity(results.First().Answer);

                        if (_options.EndActivityRoutingOnAnswer)
                        {
                            //Question is answered, don't keep routing
                            return;
                        }
                    }
                }
            }

            await next().ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task ReceiveActivity(IBotContext context, MiddlewareSet.NextDelegate next)
        {
            if (context.Request.Type == ActivityTypes.Message)
            {
                var messageActivity = context.Request.AsMessageActivity();
                if (!string.IsNullOrEmpty(messageActivity.Text))
                {
                    var results = await _qnaMaker.GetAnswers(messageActivity.Text.Trim()).ConfigureAwait(false);

                    if (results.Any())
                    {
                        context.Reply(results.First().Answer);
                    }
                }
            }

            await next().ConfigureAwait(false);
        }