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)); }
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); }
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); }