async Task <TelegramContact> GetTelegramContact(int userId) { if (_userList.TryGetValue(userId, out var contact)) { return(contact); } //var user2 = await _client.ExecuteAsync(new TdApi.GetUserFullInfo() { UserId = userId }); var user = await _client.ExecuteAsync(new TdApi.GetUser { UserId = userId }); contact = new TelegramContact(userId, user.PhoneNumber) { FirstName = user.FirstName, LastName = user.LastName, Username = user.Username }; _userList.TryAdd(userId, contact); _contactList.TryAdd(user.PhoneNumber, contact); return(contact); }
public TelegramChat() { Members = new TelegramContact[] { }; }
public async Task CreateGroup(TelegramContact serviceContact, TelegramContact clientContact, string title) { try { string prefix = "Covario - "; if (!title.StartsWith(prefix)) { title = prefix + title; } TelegramChat tc = _chats.Values.FirstOrDefault(c => c.Title == title); if (tc == null) { var basicGroup = await _client.ExecuteAsync(new TdApi.CreateNewBasicGroupChat() { Title = title, UserIds = new[] { _serviceUserId, serviceContact.UserId, clientContact.UserId } }); tc = new TelegramChat() { ChatId = basicGroup.Id, BasicGroupId = (basicGroup.Type as TdApi.ChatType.ChatTypeBasicGroup)?.BasicGroupId ?? 0, Title = title, Members = new[] { serviceContact, clientContact } }; _chats.TryAdd(tc.ChatId, tc); } await _client.ExecuteAsync(new TdApi.SetChatPermissions() { ChatId = tc.ChatId, Permissions = new TdApi.ChatPermissions { CanSendMessages = true, CanSendMediaMessages = false, CanSendPolls = false, CanSendOtherMessages = false, CanAddWebPagePreviews = true, CanChangeInfo = false, CanInviteUsers = false, CanPinMessages = false } }); await _client.ExecuteAsync(new TdApi.SetChatDescription() { ChatId = tc.ChatId, Description = "Covar.io Client Support Chat" }); await _client.ExecuteAsync(new TdApi.SetChatDescription() { ChatId = tc.ChatId, Description = "Covar.io Client Support Chat" }); var parts = new[] { @"All communication in this conversation is logged by our systems for auditing and compliance mandates, as per our Terms of Service: ", @"https://messenger.covar.io/terms", @". Communicating here acknowledges your acceptance of these terms." }; var tosMessage = await _client.ExecuteAsync(new TdApi.SendMessage() { ChatId = tc.ChatId, Options = new TdApi.SendMessageOptions { FromBackground = false, DisableNotification = true }, InputMessageContent = new TdApi.InputMessageContent.InputMessageText() { Text = new TdApi.FormattedText() { Text = string.Join("", parts), Entities = new TdApi.TextEntity[] { new TdApi.TextEntity() { Type = new TdApi.TextEntityType.TextEntityTypeUrl(), Offset = parts[0].Length, Length = parts[1].Length }, } }, } }); _pendingPins.Add(tosMessage.Id); } catch (Exception ex) { throw new TelegramCreateGroupException(ex.Message, ex); } }
public async Task CreateGroup(TelegramContact serviceContact, TelegramContact clientContact, string groupName) { await _telegramSession.CreateGroup(serviceContact, clientContact, groupName); }