public async Task ConnectAsync(bool reconnect = false) { if (_session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(_transport); _session.AuthKey = result.AuthKey; _session.TimeOffset = result.TimeOffset; } _sender = new MtProtoSender(_transport, _session); //set-up layer var config = new TLRequestGetConfig(); var request = new TLRequestInitConnection() { ApiId = _apiId, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", Query = config, SystemVersion = "Win 10.0" }; var invokewithLayer = new TLRequestInvokeWithLayer() { Layer = 66, Query = request }; await _sender.Send(invokewithLayer); await _sender.Receive(invokewithLayer); dcOptions = ((TLConfig)invokewithLayer.Response).DcOptions.ToList(); }
private async Task RequestWithDcMigration(TLMethod request, CancellationToken token = default(CancellationToken)) { if (sender == null) { throw new InvalidOperationException("Not connected!"); } var completed = false; while (!completed) { try { await sender.Send(request, token).ConfigureAwait(false); await sender.Receive(request, token).ConfigureAwait(false); completed = true; } catch (DataCenterMigrationException e) { if (session.DataCenter.DataCenterId.HasValue && session.DataCenter.DataCenterId.Value == e.DC) { throw new Exception($"Telegram server replied requesting a migration to DataCenter {e.DC} when this connection was already using this DataCenter", e); } await ReconnectToDcAsync(e.DC, token).ConfigureAwait(false); // prepare the request for another try request.ConfirmReceived = false; } } }
public async Task <bool> ConnectAsync(bool reconnect = false) { if (_session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(_transport); _session.AuthKey = result.AuthKey; _session.TimeOffset = result.TimeOffset; } _sender = new MtProtoSender(_transport, _session); //set-up layer var config = new TLRequestGetConfig(); var request = new TLRequestInitConnection() { api_id = _apiId, app_version = "1.0.0", device_model = "PC", lang_code = "en", query = config, system_version = "Win 10.0" }; var invokewithLayer = new TLRequestInvokeWithLayer() { layer = 66, query = request }; await _sender.Send(invokewithLayer); await _sender.Receive(invokewithLayer); dcOptions = ((TLConfig)invokewithLayer.Response).dc_options.lists; return(true); }
public async Task ConnectAsync(bool reconnect = false, CancellationToken token = default(CancellationToken)) { token.ThrowIfCancellationRequested(); if (session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(transport, token).ConfigureAwait(false); session.AuthKey = result.AuthKey; session.TimeOffset = result.TimeOffset; } sender = new MtProtoSender(transport, session); //set-up layer var config = new TLRequestGetConfig(); var request = new TLRequestInitConnection() { ApiId = apiId, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", Query = config, SystemVersion = "Win 10.0" }; var invokewithLayer = new TLRequestInvokeWithLayer() { Layer = 66, Query = request }; await sender.Send(invokewithLayer, token).ConfigureAwait(false); await sender.Receive(invokewithLayer, token).ConfigureAwait(false); dcOptions = ((TLConfig)invokewithLayer.Response).DcOptions.ToList(); }
public async Task <bool> Connect(bool reconnect = false) { if (_session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(_transport); _session.AuthKey = result.AuthKey; _session.TimeOffset = result.TimeOffset; } _sender = new MtProtoSender(_transport, _session); if (!reconnect) { var request = new InitConnectionRequest(_apiId); await _sender.Send(request); await _sender.Receive(request); dcOptions = request.ConfigConstructor.dc_options; } return(true); }
public async Task <bool> IsPhoneRegisteredAsync(string phoneNumber) { if (_sender == null) { throw new InvalidOperationException("Not connected!"); } var authCheckPhoneRequest = new TLRequestCheckPhone() { phone_number = phoneNumber }; await _sender.Send(authCheckPhoneRequest); await _sender.Receive(authCheckPhoneRequest); return(authCheckPhoneRequest.Response.phone_registered); }
public async Task <TL.ConfigType> getConfig() { var request = new TL.HelpGetConfigRequest(); await _sender.Send(request); await _sender.Receive(request); return((TL.ConfigType)request.Result); }
public async Task <bool> IsPhoneRegisteredAsync(string phoneNumber) { if (String.IsNullOrWhiteSpace(phoneNumber)) { throw new ArgumentNullException(nameof(phoneNumber)); } if (_sender == null) { throw new InvalidOperationException("Not connected!"); } var authCheckPhoneRequest = new TLRequestCheckPhone() { phone_number = phoneNumber }; var completed = false; while (!completed) { try { await _sender.Send(authCheckPhoneRequest); await _sender.Receive(authCheckPhoneRequest); completed = true; } catch (PhoneMigrationException e) { await ReconnectToDcAsync(e.DC); } } return(authCheckPhoneRequest.Response.ToTLCheckedPhone().phone_registered); }
public async Task <ContactsContacts> GetContacts() { var request = new GetContactsRequest(string.Empty); await _sender.Send(request); var response = await _sender.Receive <ContactsContacts>(request); return(response); }
private async Task RequestWithDcMigration(TLMethod request) { var completed = false; while (!completed) { try { await _sender.Send(request); await _sender.Receive(request); completed = true; } catch (DataCenterMigrationException e) { await ReconnectToDcAsync(e.DC); // prepare the request for another try request.ConfirmReceived = false; } } }
public async Task <bool> IsPhoneRegistered(string phoneNumber) { if (_sender == null) { throw new InvalidOperationException("Not connected!"); } var authCheckPhoneRequest = new TL.AuthCheckPhoneRequest(phoneNumber); await _sender.Send(authCheckPhoneRequest); await _sender.Receive(authCheckPhoneRequest); var result = (TL.AuthCheckedPhoneType)authCheckPhoneRequest.Result; return(result.PhoneRegistered); }
private async Task ConnectInternalAsync(bool reconnect = false, CancellationToken token = default(CancellationToken)) { token.ThrowIfCancellationRequested(); Session = SessionFactory.TryLoadOrCreateNew(store, sessionUserId); transport = new TcpTransport(Session.DataCenter.Address, Session.DataCenter.Port, this.handler); if (Session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(transport, token).ConfigureAwait(false); Session.AuthKey = result.AuthKey; Session.TimeOffset = result.TimeOffset; } sender = new MtProtoSender(transport, store, Session); //set-up layer var config = new TLRequestGetConfig(); var request = new TLRequestInitConnection() { ApiId = apiId, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", Query = config, SystemVersion = "Win 10.0", SystemLangCode = "en", LangPack = "" }; var invokewithLayer = new TLRequestInvokeWithLayer() { Layer = 108, Query = request }; await sender.Send(invokewithLayer, token).ConfigureAwait(false); await sender.Receive(invokewithLayer, token).ConfigureAwait(false); dcOptions = ((TLConfig)invokewithLayer.Response).DcOptions.ToList(); }
private async Task RequestWithDcMigration(TLMethod request) { if (_sender == null) { throw new InvalidOperationException("Not connected!"); } var completed = false; while (!completed) { try { await _sender.Send(request); await _sender.Receive(request); completed = true; } catch (FileMigrationException ex) { await MakeRequestAtDataCenterWithTemporarySubClient(request, ex.DC); completed = true; } catch (DataCenterMigrationException e) { if (_session.DataCenter.DataCenterId.HasValue && _session.DataCenter.DataCenterId.Value == e.DC) { throw new Exception($"Telegram server replied requesting a migration to DataCenter {e.DC} when this connection was already using this DataCenter", e); } await ReconnectToDcAsync(e.DC); // prepare the request for another try request.ConfirmReceived = false; } } }
public async Task <Tuple <List <Dialog>, List <Message>, List <Chat>, List <User> > > getDialogs(int offset, int limit) { var request = new TL.ChannelsGetDialogsRequest(offset, limit); await _sender.Send(request); await _sender.Receive(request); if (request.Result is TL.MessagesDialogsType) { var result = (TL.MessagesDialogsType)request.Result; dialogs = result.Dialogs; messages = result.Messages; chats = result.Chats; users = result.Users; } else { var result = (TL.MessagesDialogsSliceType)request.Result; dialogs = result.Dialogs; messages = result.Messages; chats = result.Chats; users = result.Users; } return(new Tuple <List <Dialog>, List <Message>, List <Chat>, List <User> >(dialogs, messages, chats, users)); }