public async Task <Chat> GetChatAsync(long chatId) { try { var chat = await BotClient.GetChatAsync(chatId); if (string.IsNullOrEmpty(chat.Title)) { chat.Title = ChatResources.DefaultChatName; } return(chat); } catch (ChatNotFoundException) { return(new Chat() { Id = chatId, Title = ChatResources.ChatNotFoundTitle }); } catch (Exception exception) { Logger.LogError(exception.Message); return(new Chat() { Id = chatId, Title = ChatResources.ChatUnknown }); } }
public bool TryGetSessionByTelegramId(int id, out ISession session) { bool chatIsFound = BotClient.GetChatAsync(id).ContinueWith((chatTask) => chatTask.IsCompletedSuccessfully).Result; if (chatIsFound) { session = GetSessionByTelegramId(id); } else { session = null; } return(chatIsFound); }
private async Task <Chat> FindSupergroupTestChatAsync() { Chat supergroupChat; string supergroupChatId = ConfigurationProvider.TestConfigurations.SuperGroupChatId; if (string.IsNullOrWhiteSpace(supergroupChatId)) { supergroupChat = null; // ToDo Find supergroup from a message command /test // await UpdateReceiver.DiscardNewUpdatesAsync(CancellationToken); // supergroupChat = await GetChatFromTesterAsync(ChatType.Supergroup, CancellationToken); } else { supergroupChat = await BotClient.GetChatAsync(supergroupChatId, CancellationToken); } return(supergroupChat); }
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)); }