/// <summary>
        /// Send a reply with the template
        /// </summary>
        /// <param name="context"></param>
        /// <param name="language"></param>
        /// <param name="templateId"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task ReplyWith(ITurnContext context, string templateId, object data = null)
        {
            BotAssertSlack.ContextNotNull(context);

            // apply template
            Activity boundActivity = await this.RenderTemplate(context, context.Activity?.AsMessageActivity()?.Locale, templateId, data).ConfigureAwait(false);

            if (boundActivity != null)
            {
                await context.SendActivity(boundActivity);

                return;
            }
            return;
        }
Esempio n. 2
0
        public async Task <IList <Intent> > Recognize(ITurnContext context)
        {
            BotAssertSlack.ContextNotNull(context);

            bool isEnabled = await IsRecognizerEnabled(context).ConfigureAwait(false);

            if (isEnabled)
            {
                var allRecognizedIntents = await RunRecognizer(context).ConfigureAwait(false);
                await RunFilters(context, allRecognizedIntents);

                return(allRecognizedIntents);
            }
            else
            {
                return(new List <Intent>());
            }
        }
        protected async Task RunPipeline(ICommandContext context, Func <ICommandContext, Task> callback = null, CancellationTokenSource cancelToken = null)
        {
            BotAssertSlack.ContextNotNull(context);

            // Call any registered Middleware Components looking for ReceiveActivity()
            if (context.Command != null)
            {
                await _middlewareSet.ReceiveActivityWithStatus(context, callback).ConfigureAwait(false);
            }
            else
            {
                // call back to caller on proactive case
                if (callback != null)
                {
                    await callback(context).ConfigureAwait(false);
                }
            }
        }
Esempio n. 4
0
        public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
        {
            BotAssertSlack.ContextNotNull(context);

            var intents = await this.Recognize(context);

            var result = new IntentRecognition();

            if (intents.Count != 0)
            {
                result.Intents = intents;
                var topIntent = FindTopIntent(intents);
                if (topIntent.Score > 0.0)
                {
                    result.TopIntent = topIntent;
                }
            }
            context.Services.Add((IRecognizedIntents)result);
            await next().ConfigureAwait(false);
        }