public async Task <IActionResult> Post([FromBody] Update update)
        {
            if (update == null)
            {
                return(Ok());
            }
            if (update.Type == UpdateType.Message)
            {
                var message = update.Message;
                var chatId  = message.Chat.Id;
                //_jobClient.Enqueue(()=> new NotificationJob().Send(message));
                if (_db.UtcTimes.FirstOrDefault(x => x.ChatId == chatId) == null)
                {
                    await new StartCommand().Execute(message, _telegramBotClient, _db);
                    return(Ok());
                }

                if (message.Text != "/start")
                {
                    if (_db.States.FirstOrDefault(x => x.ChatId == chatId) != null &&
                        _db.States.FirstOrDefault(x => x.ChatId == chatId).States != null)
                    {
                        foreach (var state in _stateService.Get())
                        {
                            _stateName = _db.States.FirstOrDefault(x => x.ChatId == chatId).States;
                            if (_stateName == state.Name)
                            {
                                await state.Execute(message, _telegramBotClient, _db, update, _jobClient, _stateService);

                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var command in _commandService.Get().Where(command => command.Contains(message)))
                        {
                            await command.Execute(message, _telegramBotClient, _db);

                            break;
                        }
                    }
                }
                else
                {
                    foreach (var command in _commandService.Get().Where(command => command.Contains(message)))
                    {
                        await command.Execute(message, _telegramBotClient, _db);

                        break;
                    }
                }
                return(Ok());
            }
            return(Ok());
        }
Exemple #2
0
        private async Task ExecuteCommandAsync(Message message)
        {
            foreach (var command in _commandService.Get())
            {
                if (command.Contains(message.Text))
                {
                    await command.ExecuteAsync(message);

                    break;
                }
            }
        }
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            if (update == null)
            {
                return(NoContent());
            }

            var message = update.Message;

            // (!) NOTICE: Use this code only for debug
            Console.WriteLine(
                string.Format(
                    Common.Message,
                    message.Chat.Id,
                    message.Text));

            foreach (var command in _commandService.Get())
            {
                if (command.Contains(message))
                {
                    await command.Execute(message, _telegramBotClient);

                    break;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> Post(Update update)
        {
            if (update == null)
            {
                return(NoContent());
            }

            var message = update.Message;

            switch (update.Type)
            {
            case UpdateType.Message:
            {
                foreach (var command in _commandService.Get())
                {
                    if (command.Contains(message))
                    {
                        await command.Execute(message, _telegramBotClient);

                        break;
                    }
                }
                break;
            }
            }

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            try
            {
                if (update == null)
                {
                    _logger.LogWarning("update is null");
                    return(Ok());
                }
                var message = update.Message;
                foreach (var command in _commandService.Get())
                {
                    if (command.Contains(message))
                    {
                        await command.Execute(message, _telegramBotClient);

                        break;
                    }
                }
                _logger.LogInformation("worked with {e}", update.Message.Chat.Id);
                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogWarning("exception with command", e);
                return(Ok());
            }
        }
Exemple #6
0
        public void Load()
        {
            var cmdCustomer = _command.Get(() => _docs.OpenDocument(typeof(ListCustomerViewModel)), () => true);

            _menu.RegisterMenu("data", "customer", "Customer",
                               cmdCustomer,
                               _icons.GetIcon("icons/Customer"));

            var cmdCountry = _command.Get(() => _docs.OpenDocument(typeof(ListCountryViewModel)), () => true);

            _menu.RegisterMenu("data", "country", "Country",
                               cmdCountry,
                               _icons.GetIcon("icons/Country"));

            var cmdIcon = _command.Get(() => _docs.OpenDocument(typeof(ListIconViewModel)), () => true);

            _menu.RegisterMenu("tools", "icons", "Icons",
                               cmdIcon,
                               _icons.GetIcon("icons/Icon"));
        }
Exemple #7
0
        private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            var message = messageEventArgs.Message;

            if (message?.Type == MessageType.Text)
            {
                var command = _commandService.Get(message);
                if (command == null)
                {
                    await _client.SendTextMessageAsync(message.Chat.Id, "Command not found");
                }
                else
                {
                    await command.Execute(message);
                }
            }
        }
Exemple #8
0
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            if (update == null)
            {
                return(Ok());
            }
            var message = update.Message;

            foreach (var command in _command.Get())
            {
                if (command.Contains(message))
                {
                    await command.Execute(message, _client);

                    break;
                }
            }
            return(Ok());
        }
Exemple #9
0
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            if (update == null)
            {
                return(NoContent());
            }

            var message = update.Message;

            Console.WriteLine(string.Format($"Принято сообщение: {message.Text}", message.Chat.Id, message.Text));

            foreach (var command in _commandService.Get())
            {
                if (command.Contains(message))
                {
                    await command.Execute(message, _telegramBotClient);

                    break;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            if (update == null)
            {
                return(NoContent());
            }

            switch (update.Type)
            {
            case UpdateType.Message:
            {
                var message = update.Message;
                Console.WriteLine(string.Format("---> Message was recieved {0}, text:{1}  User Id:{2}, message type:{3}", message.Chat.Username, message.Text, message.From.Id, message.Type));

                foreach (var command in _commandService.Get())
                {
                    if (command.Contains(message))
                    {
                        await command.Execute(message, _telegramBotClient, _userManager);

                        break;
                    }
                }
            }
            break;

            case UpdateType.CallbackQuery:
            {
                var callbackQuery = update.CallbackQuery;
                await _callbackHandler.Execute(callbackQuery, _telegramBotClient, _userManager);
            }
            break;
            }

            return(Ok());
        }
Exemple #11
0
 public IActionResult Update(int CommandID)
 {
     return(View(_CommandService.Get(CommandID)));
 }