コード例 #1
0
        public async Task <Chat> GetChatFromAdminAsync()
        {
            bool IsMatch(Update u) => (
                u.Message.Type == MessageType.Contact ||
                u.Message.ForwardFrom?.Id != null
                );

            var update = await UpdateReceiver
                         .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message)
                         .ContinueWith(t => t.Result.Single());

            await UpdateReceiver.DiscardNewUpdatesAsync();

            int userId = update.Message.Type == MessageType.Contact
                ? update.Message.Contact.UserId
                : update.Message.ForwardFrom.Id;

            return(await BotClient.GetChatAsync(userId));
        }
コード例 #2
0
        public async Task <Chat> GetChatFromTesterAsync(ChatType chatType)
        {
            bool IsMatch(Update u) => (
                u.Message.Chat.Type == chatType &&
                u.Message.Text?.StartsWith("/test", StringComparison.OrdinalIgnoreCase) == true
                ) || (
                ChatType.Channel == chatType &&
                ChatType.Channel == u.Message.ForwardFromChat?.Type
                );

            var update = await UpdateReceiver
                         .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message)
                         .ContinueWith(t => t.Result.Single());

            await UpdateReceiver.DiscardNewUpdatesAsync();

            return(chatType == ChatType.Channel
                ? update.Message.ForwardFromChat
                : update.Message.Chat);
        }
コード例 #3
0
        public async Task <Chat> GetChatFromTesterAsync(ChatType chatType, CancellationToken cancellationToken = default)
        {
            bool IsMatch(Update u) =>
            (
                u.Message.Chat.Type == chatType &&
                u.Message.Text?.StartsWith("/test", StringComparison.OrdinalIgnoreCase) == true
            ) || (
                ChatType.Channel == chatType &&
                ChatType.Channel == u.Message.ForwardFromChat?.Type
                );

            var updates = await UpdateReceiver
                          .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message, cancellationToken : cancellationToken);

            var update = updates.Single();

            await UpdateReceiver.DiscardNewUpdatesAsync(cancellationToken);

            return(chatType == ChatType.Channel
                ? update.Message.ForwardFromChat
                : update.Message.Chat);
        }