Ejemplo n.º 1
0
        protected virtual async Task MessageReceived(IDialogContext context, IAwaitable <Message> item)
        {
            if (this.handlerByIntent == null)
            {
                this.handlerByIntent = LuisDialog.EnumerateHandlers(this).ToDictionary(kv => kv.Key, kv => kv.Value);
            }

            var message = await item;
            var luisRes = await this.service.QueryAsync(message.Text);

            var maximum = luisRes.Intents.Max(t => t.Score ?? 0);
            var intent  = luisRes.Intents.FirstOrDefault(i => { var curScore = i.Score ?? 0; return(curScore == maximum); });

            IntentHandler handler = null;

            if (intent == null || !this.handlerByIntent.TryGetValue(intent.Intent, out handler))
            {
                handler = this.handlerByIntent[string.Empty];
            }

            if (handler != null)
            {
                await handler(context, luisRes);
            }
            else
            {
                var text = $"No default intent handler found.";
                throw new Exception(text);
            }
        }
Ejemplo n.º 2
0
 protected virtual IDictionary <string, IntentActivityHandler> GetHandlersByIntent()
 {
     return(LuisDialog.EnumerateHandlers(this).ToDictionary(kv => kv.Key, kv => kv.Value));
 }