コード例 #1
0
        private static Socks5ProxyConfig FillProxyConfig()
        {
            Socks5ProxyConfig proxyConfig = null;
            var server = Configuration["ProxyServer"];

            if (!string.IsNullOrEmpty(server))
            {
                var port     = Configuration["ProxyPort"];
                var password = Configuration["ProxyPassword"];
                var username = Configuration["ProxyUsername"];
                proxyConfig = new Socks5ProxyConfig
                {
                    Endpoint = new IPEndPoint(IPAddress.Parse(server), int.Parse(port)),
                    Password = string.IsNullOrEmpty(password) ? null: password,
                    Username = string.IsNullOrEmpty(username) ? null: username,
                };
            }

            return(proxyConfig);
        }
コード例 #2
0
        public static async Task <IClientApi> CreateTelegramClient()
        {
            Socks5ProxyConfig ProxyCreate(string ip, int port, string user = null, string pass = null)
            {
                Socks5ProxyConfig proxyConfig = null;

                if (!string.IsNullOrEmpty(ip))
                {
                    proxyConfig = new Socks5ProxyConfig
                    {
                        Endpoint = new IPEndPoint(IPAddress.Parse(ip), port),
                        Password = string.IsNullOrEmpty(pass) ? null : pass,
                        Username = string.IsNullOrEmpty(user) ? null : user,
                    };
                }

                return(proxyConfig);
            }

            var settings = new FactorySettings
            {
                AppHash         = "",
                AppId           = 23838383,
                ServerAddress   = "149.154.167.50",
                ServerPublicKey = @"-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6
lyDONS789shrhrVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcifefexlEKzwKENj1Yz/s7daS
an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7ajtht+XYl9sluzHRyVVaTTveB2GazTw
Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+
8hdlLmAjfefbCVfaigxX0CDqWeRhrhr1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n
Slv8kg9qv1m6XHVfefeQY3PnEw+QQtqSIXklHwIDAQAB
-----END RSA PUBLIC KEY-----",
                ServerPort      = 443,
                //ProxyConfig = ProxyCreate("127.0.0.1",1080),
                SessionTag = "session",
                Properties = new ApplicationProperties
                {
                    AppVersion     = "1.0.0",
                    DeviceModel    = "PC",
                    LangCode       = "en",
                    LangPack       = "tdesktop",
                    SystemLangCode = "en",
                    SystemVersion  = "Win 10 Pro"
                }
            };

            IClientApi clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);

            if (!clientApi.AuthService.CurrentUserId.HasValue)
            {
                Console.WriteLine("Please Enter Your Telegram Account Number To Signin:");
                var phone = Console.ReadLine();

                var sentCode = await clientApi.AuthService.SendCodeAsync(phone).ConfigureAwait(false);

                Console.WriteLine("\nEnter Telegram Verification Code:");
                var code = Console.ReadLine();

                TUser user;
                try
                {
                    user = await clientApi.AuthService.SignInAsync(phone, sentCode, code).ConfigureAwait(false);
                }
                catch (PhoneCodeInvalidException)
                {
                    Console.WriteLine("\nTelegram Communication Account is Invalid!!!");
                }
                catch (CloudPasswordNeededException)
                {
                    Console.WriteLine("\nYou Have Telegram Two-Step Auth Password And This App Cant Handle That!!! Please Turn Of Your Telegram Cloud Password To Use This App And After That you Can Turn it On again!");
                }
            }
            clientApi.KeepAliveConnection();

            return(clientApi);
        }