private void AddClientInCombaBox(BotEventArgs e)
        {
            var coutClientList = 0;
            var addClientList  = new ClientInfo()
            {
                FirstName  = e.Message.FirstName,
                LastName   = e.Message.LastName,
                TelegramId = e.Message.Id,
                Username   = e.Message.UserName,
            };

            if (_clientsChat.Count == 0)
            {
                _clientsChat.Add(addClientList);
            }

            foreach (var item in _clientsChat)
            {
                if (item.TelegramId.Equals(e.Message.Id))
                {
                    break;
                }
                else if (!item.TelegramId.Equals(e.Message.Id))
                {
                    coutClientList++;
                }

                if (coutClientList == _clientsChat.Count())
                {
                    _clientsChat.Add(addClientList);
                    break;
                }
            }
        }
Example #2
0
 private async void Assistant_OnResponseReceived(object sender, BotEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         WaitingRing.Visibility    = Visibility.Collapsed;
         BotResponse.Text          = e.Text;
         ResponseBubble.Visibility = Visibility.Visible;
     });
 }
Example #3
0
        public Result <CommandArgumentContainer> ParseCommand(BotEventArgs botArguments)
        {
            string commandName = botArguments.FindCommandName();

            if (string.IsNullOrWhiteSpace(commandName))
            {
                return(Result.Fail($"[{nameof(CommandParser)}]: Message do not contains command name."));
            }

            return(Result.Ok(new CommandArgumentContainer(commandName, botArguments.Sender, botArguments.GetCommandArguments(), botArguments.GetMediaFiles())));
        }
Example #4
0
        public CommandContainer ParseCommand(BotEventArgs botArguments)
        {
            string commandName = botArguments.FindCommandName();

            if (string.IsNullOrWhiteSpace(commandName))
            {
                throw new CommandNotFoundException($"[{nameof(CommandParser)}]: Message do not contains command name.");
            }

            return(new CommandContainer(commandName, botArguments.GetCommandArguments(), botArguments.GetMediaFiles(),
                                        botArguments.SenderInfo));
        }
        private void BotLogicLogStart(object sender, BotEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                AddClientInBdAndDTO(e);
                AddClientInCombaBox(e);

                var message = new DisBotMessage()
                {
                    Content   = e.Message.Content,
                    Date      = e.Message.Date,
                    LastName  = e.Message.LastName,
                    FirstName = e.Message.FirstName,
                    UserName  = e.Message.UserName,
                    FullName  = e.Message.FirstName,
                    Type      = DisBotMessage.MessageType.OutMessage,
                };

                Messages.Add(message);
                _mainListBox.ScrollIntoView(message);

                _clients  = _modelClientService.GetClients();
                var tmpId = 0;
                foreach (var item in _clients)
                {
                    if (item.TelegramId.Equals(e.Message.Id))
                    {
                        tmpId = item.Id;
                        break;
                    }
                }

                var messageDB = new ClientMessageInfo()
                {
                    MessageClient = e.Message.Content,
                    TimeMassage   = e.Message.Date,
                    UserId        = User.Id,
                    ClientId      = tmpId
                };

                _modelClientMessageService.Add(messageDB);

                if (_clients.Count != 0)
                {
                    IsSendMessage = true;
                }
            });
        }
Example #6
0
        public async Task OnRaise_BotEvent_TestAsync()
        {
            var x = new BotPublisher();

            Update[] updates = { new Update(23), new Update(56), new Update(12) };
            var      arg     = new BotEventArgs(updates);

            var evt = await Assert.RaisesAnyAsync <BotEventArgs>(
                h => x.BotEvent += h,
                h => x.BotEvent -= h,
                () => Task.Run(() => x.OnRaiseBotEvent(arg)));

            Assert.NotNull(evt);
            Assert.Equal(x, evt.Sender);
            Assert.Equal(arg, evt.Arguments);
        }
        private void AddClientInBdAndDTO(BotEventArgs e)
        {
            var countClientDB = 0;

            if (_clients.Count == 0)
            {
                var addClient = new ClientInfo()
                {
                    FirstName  = e.Message.FirstName,
                    LastName   = e.Message.LastName,
                    TelegramId = e.Message.Id,
                    Username   = e.Message.UserName,
                };

                _modelClientService.Add(addClient);
                _clients.Add(addClient);
                _clientsChat.Add(addClient);
            }
            foreach (var client in _clients)
            {
                if (client.TelegramId.Equals(_botLogic.Messages.Id))
                {
                    break;
                }
                else if (!string.IsNullOrEmpty(client.TelegramId))
                {
                    countClientDB++;
                }

                if (_clients.Count == countClientDB)
                {
                    var addClient = new ClientInfo()
                    {
                        FirstName  = e.Message.FirstName,
                        LastName   = e.Message.LastName,
                        TelegramId = e.Message.Id,
                        Username   = e.Message.UserName,
                    };
                    _modelClientService.Add(addClient);
                    _clients.Add(addClient);
                    _clientsChat.Add(addClient);
                    break;
                }
            }
        }