Esempio n. 1
0
        public async Task Handle(TokenChangedIntegrationEvent @event)
        {
            var commands = await _repository.GetCommandsByTokenAsync(@event.OldToken);

            foreach (var command in commands)
            {
                await UpdateTokenInCommandAsync(@event.OldToken, @event.NewToken, command);
            }
        }
Esempio n. 2
0
        public async Task <string> GenerateResponseTextAsync(string command, string botToken, int chatId)
        {
            string result = "";

            if (command == "/help")
            {
                StringBuilder sb          = new StringBuilder();
                var           botCommands = await _commandRepository.GetCommandsByTokenAsync(botToken);

                foreach (Command cmd in botCommands)
                {
                    sb.Append($"{cmd.Request} - {cmd.Description}\n");
                }
                result = sb.ToString();
            }
            else if (command == "/start")
            {
                var subscribeEvent = new SubscribeIntegrationEvent(botToken, chatId);

                await _telegramIntegrationEventService.SaveEventAsync(subscribeEvent, Guid.NewGuid());

                await _telegramIntegrationEventService.PublishThroughEventBusAsync(subscribeEvent);

                result = "Hello!";
            }
            else
            {
                var botCommand = await _commandRepository.GetCommandByTokenAndRequestAsync(botToken, command);

                if (botCommand != null)
                {
                    result = botCommand.Response;
                }
            }
            return(result);
        }