Beispiel #1
0
 public BaseRepository()
 {
     _context = _context ?? new HiBotDbContext();
 }
Beispiel #2
0
        public async Task None(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            var userName = String.Empty;

            context.UserData.TryGetValue <string>("Name", out userName);
            if (userName == string.Empty)
            {
                context.Call(new GreetingDialog(), Callback);
            }
            var msg = await activity;
            // check history xem
            var db = new HiBotDbContext();
            var ex = db.HistoryMissUnderstand.Where(t => t.Sentences.Equals(msg.Text.ToLower())).FirstOrDefault();

            if (ex != null)
            {
                if (!string.IsNullOrWhiteSpace(ex.Intent))
                {
                    if (string.IsNullOrEmpty(ex.Reply))
                    {
                        string message = $"Sorry {userName}, I know you want to talk about {ex.Intent}, But I can't say anything to reply now!";
                        await context.PostAsync(message);
                    }
                    else
                    {
                        string message = ex.Reply;
                        await context.PostAsync(message);
                    }
                }
            }
            else
            {
                var stateOfWaitForTeaching = false;
                context.UserData.TryGetValue <bool>("is_waiting_for_teaching", out stateOfWaitForTeaching);
                var missUnderstandUtterance = string.Empty;
                context.UserData.TryGetValue <string>("miss_understand_sentences", out missUnderstandUtterance);

                if (stateOfWaitForTeaching && !string.IsNullOrWhiteSpace(missUnderstandUtterance))
                {
                    // insert into inmemory db to learn

                    db.HistoryMissUnderstand.Add(new Entities.HistoryMissUnderstand
                    {
                        Sentences = missUnderstandUtterance.ToLower(),
                        TimeZone  = DateTime.Now,
                        Intent    = msg.Text
                    });

                    string message = $"Thanks {userName} very much, No one can perfect and I need learning every day.";
                    context.UserData.SetValue <bool>("is_waiting_for_teaching", false);
                    context.UserData.SetValue <string>("miss_understand_sentences", string.Empty);
                    await context.PostAsync(message);
                }
                else
                {
                    string message = $"Sorry {userName}, I don't understand now. However, I hope I can learn more from you ";
                    await context.PostAsync(message);

                    message = $" Can you give me a intent of your sentences ?";
                    await context.PostAsync(message);

                    context.UserData.SetValue <bool>("is_waiting_for_teaching", true);
                    context.UserData.SetValue <string>("miss_understand_sentences", msg.Text);
                }
            }

            context.Wait(this.MessageReceived);
        }