コード例 #1
0
ファイル: TelegramBot.cs プロジェクト: lulzzz/Iris
        public async Task OnUpdateAsync(Update update)
        {
            (TelegramConfig config, MessageSender sender) = GetState();

            if (!TryGetUser(config, update.AuthorId, out User user))
            {
                _logger.LogError("User {} is not in config. Leaving.", update.AuthorId);
                return;
            }

            _logger.LogInformation("Got update {}", update);

            foreach (ChatId chatId in user.ChatIds)
            {
                try
                {
                    MessageInfo messageInfo = _messageBuilder.Build(update, user, chatId);

                    await SendChatUpdate(update, sender, messageInfo, chatId);
                }
                catch (FilterRuleSkipException)
                {
                    _logger.LogInformation("Skipping update because of filter skip rule");
                }
            }
        }
コード例 #2
0
ファイル: TelegramBot.cs プロジェクト: lulzzz/Iris
        private async Task SendChatUpdate(
            Update originalUpdate,
            MessageSender sender,
            MessageInfo message,
            ChatId chatId)
        {
            _logger.LogInformation("Sending update {} to chat id {}", originalUpdate, chatId.Username ?? chatId.Identifier.ToString());

            ActionBlock <Task> chatSender = _chatSenders
                                            .GetOrAdd(chatId, id => new ActionBlock <Task>(task => task));

            await chatSender.SendAsync(
                sender.SendAsync(message));

            _logger.LogInformation("Successfully sent update {} to chat id {}", originalUpdate, chatId.Username ?? chatId.Identifier.ToString());
        }