예제 #1
0
        // Estabelece comunicacao entre o usuario e o SimpleBotUser
        private async Task HandleActivityAsync(Activity activity)
        {
            string text         = activity.Text;
            string userFromId   = activity.From.Id;
            string userFromName = activity.From.Name;

            var user = new SimpleBotUser {
                Id = userFromId, Username = userFromName
            };

            var message = new SimpleMessage(userFromId, userFromName, text);

            if (message.Text.ToLowerInvariant().Contains("delete my messages"))
            {
                unitOfWork.MessageRepository.DeleteUserMessages(user.Username);
            }
            else
            {
                unitOfWork.MessageRepository.Save(message);

                var simpleBotUser = unitOfWork.UserRepository.GetProfile(user.Id);
                unitOfWork.UserRepository.SetProfile(simpleBotUser);
            }

            string response = g_bot.Reply(message);

            await ReplyUserAsync(activity, response);
        }
 public MessagesController()
 {
     // Pattern: singleton
     if (g_bot == null)
     {
         g_bot = new SimpleBotUser();
     }
 }
        // Estabelece comunicação entre o usuário e o SimpleBotUser
        async Task HandleActivityAsync(Activity activity)
        {
            string text         = activity.Text;
            string userFromId   = activity.From.Id;
            string userFromName = activity.From.Name;

            var message = new Message(userFromId, userFromName, text);

            string response = SimpleBotUser.Reply(message);

            await ReplyUserAsync(activity, response);
        }
        public MessagesController()
        {
            // Pattern: singleton teste
            if (g_bot == null)
            {
                g_bot = new SimpleBotUser();
            }

            if (_message == null)
            {
                _message = new MessageRepository();
            }
        }
        // Estabelece comunicação entre o usuário e o SimpleBotUser
        async Task HandleActivityAsync(Activity activity)
        {
            string text         = activity.Text;
            string userFromId   = activity.From.Id;
            string userFromName = activity.From.Name;

            var message = new Message(userFromId, userFromName, text);

            string response = await SimpleBotUser.ReplyAsync(message);

            var tasks = new Task[]
            {
                MessageRepo.SalvarMensagemAsync(message),
                ReplyUserAsync(activity, response)
            };

            Task.WaitAll(tasks);
        }