public static bool RequestAccountReset(Service service, TelegramSettings settings) { try { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { var result = TelegramUtils.RunSynchronously(client.Methods.AccountDeleteAccountAsync(new AccountDeleteAccountArgs { Reason = "Forgot Password" })); return(result); } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; return(false); } } } catch (Exception ex) { service.DebugPrint("Error in VerifyPassword: " + ex); return(false); } }
public static AuthPasswordRecovery RequestPasswordRecovery(Service service, TelegramSettings settings) { try { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { var result = (AuthPasswordRecovery)TelegramUtils.RunSynchronously(client.Methods.AuthRequestPasswordRecoveryAsync(new AuthRequestPasswordRecoveryArgs { })); Thread.Sleep(100); return(result); } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; return(null); } } } catch (Exception ex) { service.DebugPrint("Error in VerifyPassword: " + ex); return(null); } }
public static TelegramSettings GenerateAuthentication(Service service) { try { service.DebugPrint("Fetching nearest DC..."); var settings = new TelegramSettings(); var authInfo = TelegramUtils.RunSynchronously(FetchNewAuthentication(DefaultTransportConfig)); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var nearestDcId = (NearestDc)TelegramUtils.RunSynchronously(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs{})); var config = (Config)TelegramUtils.RunSynchronously(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs{ })); var dcOption = config.DcOptions.OfType<DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); settings.NearestDcId = nearestDcId.NearestDcProperty; settings.NearestDcIp = dcOption.IpAddress; settings.NearestDcPort = (int)dcOption.Port; } service.DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = TelegramUtils.RunSynchronously(FetchNewAuthentication( new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort))); settings.AuthKey = authInfo2.AuthKey; settings.Salt = authInfo2.Salt; service.DebugPrint("Great! Ready for the service to start."); return settings; } catch (Exception ex) { service.DebugPrint("Error in GenerateAuthentication: " + ex); } return null; }
public static TelegramSettings GenerateAuthentication(Service service) { try { service.DebugPrint("Fetching nearest DC..."); var settings = new TelegramSettings(); var authInfo = TelegramUtils.RunSynchronously(FetchNewAuthentication(DefaultTransportConfig)); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var nearestDcId = (NearestDc)TelegramUtils.RunSynchronously(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs { })); var config = (Config)TelegramUtils.RunSynchronously(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs { })); var dcOption = config.DcOptions.OfType <DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); settings.NearestDcId = nearestDcId.NearestDcProperty; settings.NearestDcIp = dcOption.IpAddress; settings.NearestDcPort = (int)dcOption.Port; } service.DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = TelegramUtils.RunSynchronously(FetchNewAuthentication( new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort))); settings.AuthKey = authInfo2.AuthKey; settings.Salt = authInfo2.Salt; service.DebugPrint("Great! Ready for the service to start."); return(settings); } catch (Exception ex) { service.DebugPrint("Error in GenerateAuthentication: " + ex); } return(null); }
public static DcOption GetDcConfig(int migrateId, TelegramSettings settings) { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var config = (Config)TelegramUtils.RunSynchronously(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs { })); var dcOption = config.DcOptions.OfType <DcOption>().FirstOrDefault(x => x.Id == migrateId); return(dcOption); } }
public static AuthExportedAuthorization GenerateExportedAuth(int migrateId, TelegramSettings settings) { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var exportedAuth = (AuthExportedAuthorization)TelegramUtils.RunSynchronously(client.Methods.AuthExportAuthorizationAsync( new SharpTelegram.Schema.AuthExportAuthorizationArgs { DcId = (uint)migrateId, })); return(exportedAuth); } }
public static CodeRegister VerifyPassword(Service service, TelegramSettings settings, byte[] passwordHash) { try { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { var iresult = TelegramUtils.RunSynchronously(client.Methods.AuthCheckPasswordAsync(new AuthCheckPasswordArgs { PasswordHash = passwordHash })); var result = (AuthAuthorization)iresult; Thread.Sleep(100); //wait until the other response comes in. return(new CodeRegister { AccountId = (result.User as User).Id, Response = CodeRegister.Type.Success }); } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; var cr = new CodeRegister(); if (error.ErrorMessage == "PASSWORD_HASH_INVALID") { cr.Response = CodeRegister.Type.InvalidPassword; } return(cr); } } } catch (Exception ex) { service.DebugPrint("Error in VerifyPassword: " + ex); return(null); } }
public static TelegramClient GetNewClient(int migrateId, TelegramSettings settings, out TelegramSettings newSettings) { var dcConfig = GetDcConfig(migrateId, settings); var transportConfig = new TcpClientTransportConfig(dcConfig.IpAddress, (int)dcConfig.Port); var authInfo = TelegramUtils.RunSynchronously(FetchNewAuthentication(transportConfig)); var newClient = new TelegramClient(transportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo); newSettings = new TelegramSettings(); newSettings.AccountId = settings.AccountId; newSettings.AuthKey = authInfo.AuthKey; newSettings.Salt = authInfo.Salt; newSettings.NearestDcId = (uint)migrateId; newSettings.NearestDcIp = dcConfig.IpAddress; newSettings.NearestDcPort = (int)dcConfig.Port; return(newClient); }
public static CodeRegister VerifyCode(Service service, TelegramSettings settings, string code) { try { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { var iresult = TelegramUtils.RunSynchronously(client.Methods.AuthRecoverPasswordAsync(new AuthRecoverPasswordArgs { Code = code })); var result = (AuthAuthorization)iresult; Thread.Sleep(100); //wait until the other response comes in. return(new CodeRegister { AccountId = (result.User as User).Id, Response = CodeRegister.Type.Success }); } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; var cr = new CodeRegister(); cr.Response = CodeRegister.Type.Failure; return(cr); } } } catch (Exception ex) { service.DebugPrint("Error in VerifyPassword: " + ex); return(null); } }
public static CodeRequest RequestCode(Service service, string number, string codeHash, TelegramSettings settings, bool reVerify) { try { service.DebugPrint("Requesting code..."); var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { AuthSentCode result; if (reVerify) { result = TelegramUtils.RunSynchronously(client.Methods.AuthResendCodeAsync(new AuthResendCodeArgs { PhoneNumber = number, PhoneCodeHash = codeHash })) as AuthSentCode; } else { result = TelegramUtils.RunSynchronously(client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", })) as AuthSentCode; } return(new CodeRequest { Registered = result.PhoneRegistered != null ? true : false, CodeHash = result.PhoneCodeHash, CurrentType = GetAuthSentType(result.Type), NextType = GetAuthType(result.NextType) }); } catch (RpcErrorException ex) { Utils.DebugPrint(">>>> Send code failure " + ObjectDumper.Dump(ex)); var error = (RpcError)ex.Error; var cr = new CodeRequest(); var response = CodeRequest.Type.Failure; switch (error.ErrorCode) { case 400: cr.Response = CodeRequest.Type.NumberInvalid; break; case 303: var newDcId = GetDcId(error.ErrorMessage); cr.Response = CodeRequest.Type.Migrate; cr.MigrateId = newDcId; break; default: cr.Response = CodeRequest.Type.Failure; break; } return(cr); } return(new CodeRequest { Response = CodeRequest.Type.Success }); } } catch (Exception ex) { service.DebugPrint("Error in CodeRequest: " + ex); } return(null); }
public static CodeRegister RegisterCode(Service service, TelegramSettings settings, string number, string codeHash, string code, string firstName, string lastName, bool signIn) { try { service.DebugPrint("Registering code..."); var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { IAuthAuthorization iresult = null; if (signIn) { iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = codeHash, PhoneCode = code, })); } else { iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = codeHash, PhoneCode = code, FirstName = firstName, LastName = lastName, })); } var result = (AuthAuthorization)iresult; Thread.Sleep(100); //wait until the other response comes in, if it has to. return(new CodeRegister { AccountId = (result.User as User).Id, Response = CodeRegister.Type.Success, }); } catch (RpcErrorException ex) { Utils.DebugPrint(">>>>>> Failed to sign in " + ex); var error = (RpcError)ex.Error; var cr = new CodeRegister(); switch (error.ErrorMessage) { case "PHONE_NUMBER_INVALID": cr.Response = CodeRegister.Type.NumberInvalid; break; case "PHONE_CODE_EMPTY": cr.Response = CodeRegister.Type.CodeEmpty; break; case "PHONE_CODE_EXPIRED": cr.Response = CodeRegister.Type.CodeExpired; break; case "PHONE_CODE_INVALID": cr.Response = CodeRegister.Type.CodeInvalid; break; case "FIRSTNAME_INVALID": cr.Response = CodeRegister.Type.FirstNameInvalid; break; case "LASTNAME_INVALID": cr.Response = CodeRegister.Type.LastNameInvalid; break; case "SESSION_PASSWORD_NEEDED": cr.Response = CodeRegister.Type.PasswordNeeded; GetPasswordDetails(client, cr); break; default: cr.Response = CodeRegister.Type.Failure; break; } return(cr); } } } catch (Exception ex) { service.DebugPrint("Error in CodeRequest: " + ex); } return(null); }
public static DcOption GetDcConfig(int migrateId, TelegramSettings settings) { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var config = (Config)TelegramUtils.RunSynchronously(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs { })); var dcOption = config.DcOptions.OfType<DcOption>().FirstOrDefault(x => x.Id == migrateId); return dcOption; } }
public static AuthExportedAuthorization GenerateExportedAuth(int migrateId, TelegramSettings settings) { var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); var exportedAuth = (AuthExportedAuthorization)TelegramUtils.RunSynchronously(client.Methods.AuthExportAuthorizationAsync( new SharpTelegram.Schema.AuthExportAuthorizationArgs { DcId = (uint)migrateId, })); return exportedAuth; } }
public static CodeRegister RegisterCode(Service service, TelegramSettings settings, string number, string codeHash, string code, string firstName, string lastName, bool signIn) { try { service.DebugPrint("Registering code..."); var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); try { IAuthAuthorization iresult = null; if (signIn) { iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = codeHash, PhoneCode = code, })); } else { iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = codeHash, PhoneCode = code, FirstName = firstName, LastName = lastName, })); } var result = (AuthAuthorization)iresult; return new CodeRegister { AccountId = (result.User as UserSelf).Id, Expires = result.Expires, Response = CodeRegister.Type.Success, }; } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; var cr = new CodeRegister(); var response = CodeRegister.Type.Failure; switch (error.ErrorMessage) { case "PHONE_NUMBER_INVALID": cr.Response = CodeRegister.Type.NumberInvalid; break; case "PHONE_CODE_EMPTY": cr.Response = CodeRegister.Type.CodeEmpty; break; case "PHONE_CODE_EXPIRED": cr.Response = CodeRegister.Type.CodeExpired; break; case "PHONE_CODE_INVALID": cr.Response = CodeRegister.Type.CodeInvalid; break; case "FIRSTNAME_INVALID": cr.Response = CodeRegister.Type.FirstNameInvalid; break; case "LASTNAME_INVALID": cr.Response = CodeRegister.Type.LastNameInvalid; break; default: cr.Response = CodeRegister.Type.Failure; break; } return cr; } } } catch (Exception ex) { service.DebugPrint("Error in CodeRequest: " + ex); } return null; }
public static CodeRequest RequestCode(Service service, string number, string codeHash, TelegramSettings settings, bool call) { try { service.DebugPrint("Requesting code..."); var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); if (!call) { try { var result = TelegramUtils.RunSynchronously(client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, SmsType = 0, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", LangCode = PhoneBook.Language })) as AuthSentCode; return new CodeRequest { Registered = result.PhoneRegistered, CodeHash = result.PhoneCodeHash, }; } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; var cr = new CodeRequest(); var response = CodeRequest.Type.Failure; switch (error.ErrorCode) { case 400: cr.Response = CodeRequest.Type.NumberInvalid; break; default: cr.Response = CodeRequest.Type.Failure; break; } return cr; } } var result2 = (bool)TelegramUtils.RunSynchronously(client.Methods.AuthSendCallAsync(new AuthSendCallArgs { PhoneNumber = number, PhoneCodeHash = codeHash, })); return new CodeRequest { Response = result2 ? CodeRequest.Type.Success : CodeRequest.Type.Failure }; } } catch (Exception ex) { service.DebugPrint("Error in CodeRequest: " + ex); } return null; }
public async void DoCommand(string[] args) { var command = args[0].ToLower(); switch (command) { case "setup": { DebugPrint("Fetching nearest DC..."); var telegramSettings = new TelegramSettings(); var authInfo = await FetchNewAuthentication(DefaultTransportConfig); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { await client.Connect(); var nearestDcId = (NearestDc)await(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs{})); var config = (Config)await(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs{ })); var dcOption = config.DcOptions.OfType<DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); telegramSettings.NearestDcId = nearestDcId.NearestDcProperty; telegramSettings.NearestDcIp = dcOption.IpAddress; telegramSettings.NearestDcPort = (int)dcOption.Port; } DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = await FetchNewAuthentication( new TcpClientTransportConfig(telegramSettings.NearestDcIp, telegramSettings.NearestDcPort)); telegramSettings.AuthKey = authInfo2.AuthKey; telegramSettings.Salt = authInfo2.Salt; SettingsManager.Save(this, telegramSettings); DebugPrint("Great! Ready for the service to start."); } break; case "sendcode": { var number = args[1]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = await client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, SmsType = 0, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", LangCode = PhoneBook.Language }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signin": { var number = args[1]; var hash = args[2]; var code = args[3]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signup": { var number = args[1]; var hash = args[2]; var code = args[3]; var firstName = args[4]; var lastName = args[5]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, FirstName = firstName, LastName = lastName, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "getcontacts": { var result = await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); DebugPrint(ObjectDumper.Dump(result)); } break; case "sendhello": { var contacts = (ContactsContacts)await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); var counter = 0; Console.WriteLine("Pick a contact:"); foreach (var icontact in contacts.Users) { var contact = icontact as UserContact; if (contact == null) continue; Console.WriteLine(counter++ + ") " + contact.FirstName + " " + contact.LastName); } var choice = int.Parse(Console.ReadLine()); var chosenContact = (UserContact)contacts.Users[choice]; var result = await _fullClient.Methods.MessagesSendMessageAsync(new MessagesSendMessageArgs { Peer = new InputPeerContact { UserId = chosenContact.Id, }, Message = "Hello from Disa!", RandomId = (ulong)Time.GetNowUnixTimestamp(), }); Console.WriteLine(ObjectDumper.Dump(result)); } break; } }
public static TelegramClient GetNewClient(int migrateId, TelegramSettings settings, out TelegramSettings newSettings) { var dcConfig = GetDcConfig(migrateId, settings); var transportConfig = new TcpClientTransportConfig(dcConfig.IpAddress, (int)dcConfig.Port); var authInfo = TelegramUtils.RunSynchronously(FetchNewAuthentication(transportConfig)); var newClient = new TelegramClient(transportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo); newSettings = new TelegramSettings(); newSettings.AccountId = settings.AccountId; newSettings.AuthKey = authInfo.AuthKey; newSettings.Salt = authInfo.Salt; newSettings.NearestDcId = (uint)migrateId; newSettings.NearestDcIp = dcConfig.IpAddress; newSettings.NearestDcPort = (int)dcConfig.Port; return newClient; }
public override bool Initialize(DisaSettings settings) { _settings = settings as TelegramSettings; _mutableSettings = MutableSettingsManager.Load<TelegramMutableSettings>(); if (_settings.AuthKey == null) { return false; } return true; }
public async void DoCommand(string[] args) { var command = args[0].ToLower(); switch (command) { case "setup": { DebugPrint("Fetching nearest DC..."); var telegramSettings = new TelegramSettings(); var authInfo = await FetchNewAuthentication(DefaultTransportConfig); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { await client.Connect(); var nearestDcId = (NearestDc)await(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs { })); var config = (Config)await(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs { })); var dcOption = config.DcOptions.OfType <DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); telegramSettings.NearestDcId = nearestDcId.NearestDcProperty; telegramSettings.NearestDcIp = dcOption.IpAddress; telegramSettings.NearestDcPort = (int)dcOption.Port; } DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = await FetchNewAuthentication( new TcpClientTransportConfig(telegramSettings.NearestDcIp, telegramSettings.NearestDcPort)); telegramSettings.AuthKey = authInfo2.AuthKey; telegramSettings.Salt = authInfo2.Salt; SettingsManager.Save(this, telegramSettings); DebugPrint("Great! Ready for the service to start."); } break; case "sendcode": { var number = args[1]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = await client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, SmsType = 0, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", LangCode = PhoneBook.Language }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signin": { var number = args[1]; var hash = args[2]; var code = args[3]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signup": { var number = args[1]; var hash = args[2]; var code = args[3]; var firstName = args[4]; var lastName = args[5]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, FirstName = firstName, LastName = lastName, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "getcontacts": { var result = await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); DebugPrint(ObjectDumper.Dump(result)); } break; case "sendhello": { var contacts = (ContactsContacts)await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); var counter = 0; Console.WriteLine("Pick a contact:"); foreach (var icontact in contacts.Users) { var contact = icontact as UserContact; if (contact == null) { continue; } Console.WriteLine(counter++ + ") " + contact.FirstName + " " + contact.LastName); } var choice = int.Parse(Console.ReadLine()); var chosenContact = (UserContact)contacts.Users[choice]; var result = await _fullClient.Methods.MessagesSendMessageAsync(new MessagesSendMessageArgs { Peer = new InputPeerContact { UserId = chosenContact.Id, }, Message = "Hello from Disa!", RandomId = (ulong)Time.GetNowUnixTimestamp(), }); Console.WriteLine(ObjectDumper.Dump(result)); } break; } }
public async void DoCommand(string[] args) { var command = args[0].ToLower(); switch (command) { case "decrypt": { try { var bytes = Convert.FromBase64String("+MW7Btpz31b0gt9WN5d5vAEAAAAVxLUcCwAAAMzG2AUAAAAAAQAAAA4xNDkuMTU0LjE3NS41MAC7AQAAzMbYBQEAAAABAAAAJzIwMDE6MGIyODpmMjNkOmYwMDE6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADMxtgFAAAAAAIAAAAOMTQ5LjE1NC4xNjcuNTEAuwEAAMzG2AUBAAAAAgAAACcyMDAxOjA2N2M6MDRlODpmMDAyOjAwMDA6MDAwMDowMDAwOjAwMGG7AQAAzMbYBQAAAAADAAAADzE0OS4xNTQuMTc1LjEwMLsBAADMxtgFAQAAAAMAAAAnMjAwMTowYjI4OmYyM2Q6ZjAwMzowMDAwOjAwMDA6MDAwMDowMDBhuwEAAMzG2AUAAAAABAAAAA4xNDkuMTU0LjE2Ny45MQC7AQAAzMbYBQEAAAAEAAAAJzIwMDE6MDY3YzowNGU4OmYwMDQ6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADMxtgFAgAAAAQAAAAPMTQ5LjE1NC4xNjUuMTIwuwEAAMzG2AUAAAAABQAAAA05MS4xMDguNTYuMTgwAAC7AQAAzMbYBQEAAAAFAAAAJzIwMDE6MGIyODpmMjNmOmYwMDU6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADIAAAA6AMAAGQAAADA1AEAiBMAADB1AADgkwQAMHUAANwFAAAKAAAAYOoAAAIAAADIAAAAFcS1HAAAAAA="); TLRig.Default.PrepareSerializersForAllTLObjectsInAssembly(typeof(IMTProtoAsyncMethods).Assembly); using (var streamer = new TLStreamer(bytes)) { var newResult = TLRig.Default.Deserialize(streamer); int hi = 5; } } catch (Exception ex) { Console.WriteLine(ex); } } break; case "setup": { DebugPrint("Fetching nearest DC..."); var telegramSettings = new TelegramSettings(); var authInfo = await FetchNewAuthentication(DefaultTransportConfig); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { await client.Connect(); var nearestDcId = (NearestDc)await(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs { })); var config = (Config)await(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs { })); var dcOption = config.DcOptions.OfType <DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); telegramSettings.NearestDcId = nearestDcId.NearestDcProperty; telegramSettings.NearestDcIp = dcOption.IpAddress; telegramSettings.NearestDcPort = (int)dcOption.Port; } DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = await FetchNewAuthentication( new TcpClientTransportConfig(telegramSettings.NearestDcIp, telegramSettings.NearestDcPort)); telegramSettings.AuthKey = authInfo2.AuthKey; telegramSettings.Salt = authInfo2.Salt; SettingsManager.Save(this, telegramSettings); DebugPrint("Great! Ready for the service to start."); } break; case "sendcode": { var number = args[1]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = await client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signin": { var number = args[1]; var hash = args[2]; var code = args[3]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signup": { var number = args[1]; var hash = args[2]; var code = args[3]; var firstName = args[4]; var lastName = args[5]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, FirstName = firstName, LastName = lastName, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "getcontacts": { var result = await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); DebugPrint(ObjectDumper.Dump(result)); } break; // case "sendhello": // { // var contacts = (ContactsContacts)await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs // { // Hash = string.Empty // }); // var counter = 0; // Console.WriteLine("Pick a contact:"); // foreach (var icontact in contacts.Users) // { // var contact = icontact as UserContact; // if (contact == null) // continue; // Console.WriteLine(counter++ + ") " + contact.FirstName + " " + contact.LastName); // } // var choice = int.Parse(Console.ReadLine()); // var chosenContact = (UserContact)contacts.Users[choice]; // var result = await _fullClient.Methods.MessagesSendMessageAsync(new MessagesSendMessageArgs // { // Peer = new InputPeerContact // { // UserId = chosenContact.Id, // }, // Message = "Hello from Disa!", // RandomId = (ulong)Time.GetNowUnixTimestamp(), // }); // Console.WriteLine(ObjectDumper.Dump(result)); // } // break; } }
public async void DoCommand(string[] args) { var command = args[0].ToLower(); switch (command) { case "decrypt": { try { var bytes = Convert.FromBase64String("+MW7Btpz31b0gt9WN5d5vAEAAAAVxLUcCwAAAMzG2AUAAAAAAQAAAA4xNDkuMTU0LjE3NS41MAC7AQAAzMbYBQEAAAABAAAAJzIwMDE6MGIyODpmMjNkOmYwMDE6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADMxtgFAAAAAAIAAAAOMTQ5LjE1NC4xNjcuNTEAuwEAAMzG2AUBAAAAAgAAACcyMDAxOjA2N2M6MDRlODpmMDAyOjAwMDA6MDAwMDowMDAwOjAwMGG7AQAAzMbYBQAAAAADAAAADzE0OS4xNTQuMTc1LjEwMLsBAADMxtgFAQAAAAMAAAAnMjAwMTowYjI4OmYyM2Q6ZjAwMzowMDAwOjAwMDA6MDAwMDowMDBhuwEAAMzG2AUAAAAABAAAAA4xNDkuMTU0LjE2Ny45MQC7AQAAzMbYBQEAAAAEAAAAJzIwMDE6MDY3YzowNGU4OmYwMDQ6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADMxtgFAgAAAAQAAAAPMTQ5LjE1NC4xNjUuMTIwuwEAAMzG2AUAAAAABQAAAA05MS4xMDguNTYuMTgwAAC7AQAAzMbYBQEAAAAFAAAAJzIwMDE6MGIyODpmMjNmOmYwMDU6MDAwMDowMDAwOjAwMDA6MDAwYbsBAADIAAAA6AMAAGQAAADA1AEAiBMAADB1AADgkwQAMHUAANwFAAAKAAAAYOoAAAIAAADIAAAAFcS1HAAAAAA="); TLRig.Default.PrepareSerializersForAllTLObjectsInAssembly(typeof (IMTProtoAsyncMethods).Assembly); using (var streamer = new TLStreamer(bytes)) { var newResult = TLRig.Default.Deserialize(streamer); int hi = 5; } } catch (Exception ex) { Console.WriteLine(ex); } } break; case "setup": { DebugPrint("Fetching nearest DC..."); var telegramSettings = new TelegramSettings(); var authInfo = await FetchNewAuthentication(DefaultTransportConfig); using (var client = new TelegramClient(DefaultTransportConfig, new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo)) { await client.Connect(); var nearestDcId = (NearestDc)await(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs{})); var config = (Config)await(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs{ })); var dcOption = config.DcOptions.OfType<DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty); telegramSettings.NearestDcId = nearestDcId.NearestDcProperty; telegramSettings.NearestDcIp = dcOption.IpAddress; telegramSettings.NearestDcPort = (int)dcOption.Port; } DebugPrint("Generating authentication on nearest DC..."); var authInfo2 = await FetchNewAuthentication( new TcpClientTransportConfig(telegramSettings.NearestDcIp, telegramSettings.NearestDcPort)); telegramSettings.AuthKey = authInfo2.AuthKey; telegramSettings.Salt = authInfo2.Salt; SettingsManager.Save(this, telegramSettings); DebugPrint("Great! Ready for the service to start."); } break; case "sendcode": { var number = args[1]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = await client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signin": { var number = args[1]; var hash = args[2]; var code = args[3]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignInAsync(new AuthSignInArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "signup": { var number = args[1]; var hash = args[2]; var code = args[3]; var firstName = args[4]; var lastName = args[5]; var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { await client.Connect(); var result = (AuthAuthorization)await client.Methods.AuthSignUpAsync(new AuthSignUpArgs { PhoneNumber = number, PhoneCodeHash = hash, PhoneCode = code, FirstName = firstName, LastName = lastName, }); DebugPrint(ObjectDumper.Dump(result)); } } break; case "getcontacts": { var result = await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs { Hash = string.Empty }); DebugPrint(ObjectDumper.Dump(result)); } break; // case "sendhello": // { // var contacts = (ContactsContacts)await _fullClient.Methods.ContactsGetContactsAsync(new ContactsGetContactsArgs // { // Hash = string.Empty // }); // var counter = 0; // Console.WriteLine("Pick a contact:"); // foreach (var icontact in contacts.Users) // { // var contact = icontact as UserContact; // if (contact == null) // continue; // Console.WriteLine(counter++ + ") " + contact.FirstName + " " + contact.LastName); // } // var choice = int.Parse(Console.ReadLine()); // var chosenContact = (UserContact)contacts.Users[choice]; // var result = await _fullClient.Methods.MessagesSendMessageAsync(new MessagesSendMessageArgs // { // Peer = new InputPeerContact // { // UserId = chosenContact.Id, // }, // Message = "Hello from Disa!", // RandomId = (ulong)Time.GetNowUnixTimestamp(), // }); // Console.WriteLine(ObjectDumper.Dump(result)); // } // break; } }
public static CodeRequest RequestCode(Service service, string number, string codeHash, TelegramSettings settings, bool call) { try { service.DebugPrint("Requesting code..."); var transportConfig = new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo)) { TelegramUtils.RunSynchronously(client.Connect()); if (!call) { try { var result = TelegramUtils.RunSynchronously(client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs { PhoneNumber = number, SmsType = 0, ApiId = AppInfo.ApiId, ApiHash = "f8f2562579817ddcec76a8aae4cd86f6", LangCode = PhoneBook.Language })) as AuthSentCode; return(new CodeRequest { Registered = result.PhoneRegistered, CodeHash = result.PhoneCodeHash, }); } catch (RpcErrorException ex) { var error = (RpcError)ex.Error; var cr = new CodeRequest(); var response = CodeRequest.Type.Failure; switch (error.ErrorCode) { case 400: cr.Response = CodeRequest.Type.NumberInvalid; break; default: cr.Response = CodeRequest.Type.Failure; break; } return(cr); } } var result2 = (bool)TelegramUtils.RunSynchronously(client.Methods.AuthSendCallAsync(new AuthSendCallArgs { PhoneNumber = number, PhoneCodeHash = codeHash, })); return(new CodeRequest { Response = result2 ? CodeRequest.Type.Success : CodeRequest.Type.Failure }); } } catch (Exception ex) { service.DebugPrint("Error in CodeRequest: " + ex); } return(null); }