public async Task ConnectAsync() { var store = new FileSessionStore(); TelegramClient = new TelegramClient(store, "session", ApiId, ApiHash); await TelegramClient.Connect(); }
public async Task AuthUser() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var hash = await client.SendCodeRequest("375257307554"); var code = "70342"; // you can change code in debugger var t = Console.ReadLine(); code = t; var user = await client.MakeAuth("375257307554", hash, code); Console.WriteLine("fdfdfdfd"); var userByPhoneId = await client.ImportContactByPhoneNumber("375293088998"); await client.SendMessage(userByPhoneId.Value, "Hello Habr!"); Assert.IsNotNull(user); var hist = await client.GetMessagesHistoryForContact(userByPhoneId.Value, 0, 1000); hist.Count(); }
public async Task CheckPhones() { var store = new FileSessionStore(); var client = new Core.TelegramClient(store, "session"); await client.Connect(); var phoneList = new string[] { RegisteredNumber, NumberToAuthenticate }; var rand = new Random(); foreach (var phone in phoneList) { var result = await client.IsPhoneRegistered(phone); Thread.Sleep(rand.Next(9) * 1000); if (result) { Console.WriteLine($"{phone} - OK"); } } }
//Redirect to LogIn public Main() { InitializeComponent(); var store = new FileSessionStore(); var apiId = 434408; var apiHash = "0bdea67547ee00f2e164a5522174d7dc"; var client = new TelegramClient(apiId, apiHash); if (client.IsUserAuthorized() == false) { Auth auth = new Auth(); auth.ShowDialog(); } if (client.IsUserAuthorized() == true) { GetUnReadMassages(); if (System.IO.File.Exists(@".\profileimg")) { Bitmap image = new Bitmap(@".\profileimg"); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox1.Image = image; label2.Text = Properties.Settings.Default.Name; } else { pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; label2.Text = Properties.Settings.Default.Name; } } }
public TelegramWorker() { TelSesStore = new FileSessionStore(); TelClient = new TelegramClient(api_id, api_hash, TelSesStore); TelBotClient = new TelegramBotClient(botkey); TelBotClient.OnMessage += TelBotClient_OnMessage; }
protected async Task Connect() { m_SessionStore = new FileSessionStore(); TcpClientConnectionHandler handler = null; if (ProxyType != ProxyType.None) { handler = ProxyHandler; } client = new TelegramClient(m_ApiID, m_ApiHash, m_SessionStore, m_PhoneNumber, handler: handler); await client.ConnectAsync(); if (!TestClient()) { var hash = await client.SendCodeRequestAsync(m_PhoneNumber); if (!String.IsNullOrEmpty(hash)) { var arg = new AuthEventArgs { hash = hash }; AuthCodeHandler?.Invoke(this, arg); await client.MakeAuthAsync(m_PhoneNumber, hash, arg.code); } } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { FileSessionStore session = new FileSessionStore(); client = NewClient(session); await client.ConnectAsync(); }
public async System.Threading.Tasks.Task GetChennals() { var store = new FileSessionStore(); var apiId = 434408; var apiHash = "0bdea67547ee00f2e164a5522174d7dc"; var client = new TelegramClient(apiId, apiHash); await client.ConnectAsync(); var dialogs = (TLDialogs)await client.GetUserDialogsAsync(); foreach (var element in dialogs.Chats) { if (element is TLChannel) { TLChannel chat = element as TLChannel; metroComboBox1.Items.Add(chat.Title); } } for (int a = 0; a < metroComboBox1.Items.Count; a++) { if (metroComboBox1.Items[a].ToString() == Settings.Default.ChanelTo) { metroComboBox1.SelectedIndex = a; } } bunifuMaterialTextbox1.Text = Properties.Settings.Default.BitlyAPI; }
public TLAArchiver(Config config) { m_config = config; m_store = new FileSessionStore(); m_webProxy = CreateWebProxy(config); m_client = new TelegramClient(m_config.ApiId, m_config.ApiHash, m_store, "session", ConnectViaHttpProxy); }
public async Task Reconnect() { Authorized = false; store = null; await this.ConnectClient(); }
private static void Main(string[] args) { StreamReader reader = new StreamReader("phones.txt"); store = new FileSessionStore(); client = new TelegramClient(API_ID, API_HASH, store, "session"); ConnectToAPI().Wait(); while (reader.EndOfStream == false) { string number = string.Empty; try { number = string.Format("+7{0}", reader.ReadLine()); CheckPhone(number).Wait(); } catch (Exception e) { Console.WriteLine("Number {0}: {1}", number, e.Message); continue; } finally { Thread.Sleep(TimeSpan.FromSeconds(5)); } } }
private async Task <bool> AuthWithFile() { this.store = (new FileSessionStore());// "session.dat" this.client = new TelegramClient(apiId, apiHash, this.store, this.Number); await this.client.ConnectAsync(); return(this.client.IsUserAuthorized() && this.client.IsConnected); }
public static async Task CreateClientbyLogIn(int api_id, string api_hash) { string fullPathToDat = Directory.GetCurrentDirectory() + "\\session"; var store = new FileSessionStore(); _client = new TelegramClient(api_id, api_hash, store, fullPathToDat); await _client.ConnectAsync(true); }
public async Task CheckPhones() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var result = await client.IsPhoneRegistered(NumberToAuthenticate); Assert.IsTrue(result); }
public TelegramCollector() { bot = new TelegramBotClient("1614127935:AAGWfaa6RwOrrUGH2V0AR9phluns7ScvpFk"); //bot.SendTextMessageAsync(new ChatId(-1001266511682), "Just setting khbrdnn."); var me = bot.GetMeAsync().Result; //bot.SendTextMessageAsync(new ChatId(-1001479837640), "Hello word.!"); //keepconnected_timer.Elapsed += OnkeepAlive; _Bot = new ContentSenderTelegramBot(bot); bot.OnMessage += OnTelegramMessage; int app_id = 2372991; string api_hash = "c7f27d96d2b3409d0b48d9682a3314a4"; var store = new FileSessionStore(); client = new TelegramClient(app_id, api_hash, store); TelegramClientManager._client = client; //await TelegramClientManager.CreateClientbyAuthorize(app_id, api_hash); //client = TelegramClientManager._client; while (true) { try { //send message client.ConnectAsync(false).Wait(); break; } catch (Exception e) { Console.WriteLine(e); Console.WriteLine("/n /n any key to retying..."); Console.ReadKey(); //countinue } } OnkeepAlive(null, null); keepconnected_timer.Enabled = true; //var client = new TelegramClient(app_id,api_hash); //Console.Write("Enter numberphone:"); //var numberphone = Console.ReadLine(); Console.WriteLine("Is connected: " + client.IsConnected); Console.WriteLine("Is user authorized: " + client.IsUserAuthorized()); this._Context = new NewsConcentratorDbContext(); Thread t = new Thread(GetNewses); t.Start(); }
//Логика рассылки сообщений private async void Btn_BeginSpam_Click(object sender, RoutedEventArgs e) { try { Txb_Waiting.IsEnabled = false; // получаем текущую сессию var session = new FileSessionStore(); //Создаем клиента var cl = new TelegramClient(MainWindow.API_ID, MainWindow.API_HASH, session, "session"); //переопределяем клиента client = cl; int time_to_sleep; int.TryParse(Txb_Waiting.Text, out time_to_sleep); //подключаем клиента await client.ConnectAsync(); int imax = users.Count; foreach (string username in users) { //ищем пользователя по его Никнейму var found = await client.SearchUserAsync(username, 1); if (found.Users.Count > 0) { //получаем пользователя var u = found.Users.lists.OfType <TLUser>().First(); if (!u.Bot) { //отправляем ему сообщение await client.SendMessageAsync(new TLInputPeerUser() { UserId = u.Id, AccessHash = (long)u.AccessHash }, Txb_Message.Text); Thread.Sleep(time_to_sleep); } } } Progr_Spam.Value = 100; Txb_Waiting.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static TelegramClient NewClient(FileSessionStore session) { try { return(new TelegramClient(235585, "2c9039610774b160a14c9c3aa64bbf8c", session, "session")); } catch (MissingApiConfigurationException ex) { throw new Exception($"Please add your API settings to the `app.config` file. (More info: {MissingApiConfigurationException.InfoUrl})", ex); } }
public void RestoreData(SerializedAccount data) { // this.id = data.AccountId; this.Name = data.Data; string sessionKey = Name; var store = new FileSessionStore(); client = new TelegramClient(153480, "b4fe99e13f7820911ad3cd6c12514e7f", store, sessionKey); //var session = store.Load(sessionKey); //user = session.TLUser; }
public async Task ImportByUserName() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportByUserName(UserNameToSendMessage); Assert.IsNotNull(res); }
private async void MainForm_Load(object sender, EventArgs e) { //mtxtPhoneNumber.Text = "972524880330"; Text = Assembly.GetExecutingAssembly().GetName().Name; mSessionStore = new FileSessionStore(); mClient = new TelegramClient(mSessionStore, "session"); await mClient.Connect(); if (mClient.IsUserAuthorized()) { await Login(); } }
public async Task ImportContactByPhoneNumber() { // User should be already authenticated! var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToSendMessage); Assert.IsNotNull(res); }
public static TelegramClient NewClient(FileSessionStore session) { try { DotEnv.AutoConfig(); //loads environment variables int API_ID = Int32.Parse(Environment.GetEnvironmentVariable("API_ID")); string API_HASH = Environment.GetEnvironmentVariable("API_HASH"); return(new TelegramClient(API_ID, API_HASH, session, "session")); } catch (MissingApiConfigurationException ex) { throw new Exception($"Please add your API settings to the `app.config` file. (More info: {MissingApiConfigurationException.InfoUrl})", ex); } }
public async Task AuthUser() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); var hash = await client.SendCodeRequest(NumberToAuthenticate); var code = "93463"; // you can change code in debugger var user = await client.MakeAuth(NumberToAuthenticate, hash, code); Assert.IsNotNull(user); }
public async Task ImportContact() { // User should be already authenticated! var store = new FileSessionStore(); var client = new Core.TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContact(RegisteredNumber); Assert.IsNotNull(res); }
public async Task ImportByUserNameAndSendMessage() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session", apiId, apiHash); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportByUserName(UserNameToSendMessage); Assert.IsNotNull(res); await client.SendMessage(res.Value, "Test message from TelegramClient"); }
//метод для аутентификации public async Task AuthUser() { //создаем сессию var store = new FileSessionStore(); //подключаемся к телеграм await client.ConnectAsync(); //отправляем код потверждения на наш номер var hash = await client.SendCodeRequestAsync("79807545992"); //следует поменять на код присланный телеграмом в дебаге var code = "80173"; //потверждаем нашу учетную запись var user = await client.MakeAuthAsync("79807545992", hash, code); }
public async Task GetHistory() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session"); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToSendMessage); Assert.IsNotNull(res); var hist = await client.GetMessagesHistoryForContact(res.Value, 0, 5); Assert.IsNotNull(hist); }
private void App_Startup(object sender, StartupEventArgs e) { FileSessionStore session = new FileSessionStore(); TelegramClient client = Login.NewClient(session); if (client.IsUserAuthorized()) //if user authorised than open main window { MainWindow mainWindow = new MainWindow(); // Inicialize main window mainWindow.Show(); } else { Login loginWindow = new Login(); // Inicialize login window loginWindow.Show(); } }
public async Task GetUserFullRequest() { var store = new FileSessionStore(); var client = new TelegramClient(store, "session", apiId, apiHash); await client.Connect(); Assert.IsTrue(client.IsUserAuthorized()); var res = await client.ImportContactByPhoneNumber(NumberToGetUserFull); Assert.IsNotNull(res); var userFull = await client.GetUserFull(res.Value); Assert.IsNotNull(userFull); }
public async System.Threading.Tasks.Task AuthAsync() { var store = new FileSessionStore(); var apiId = 434408; var apiHash = "0bdea67547ee00f2e164a5522174d7dc"; var client = new TelegramClient(apiId, apiHash); await client.ConnectAsync(); if (client.IsUserAuthorized() == false) { var phone = metroComboBox1.Text + metroTextBox1.Text; var hash = await client.SendCodeRequestAsync(phone); var code = Microsoft.VisualBasic.Interaction.InputBox("Введите код полученый в СМС:"); var user = await client.MakeAuthAsync(phone, hash, code); var photo = ((TLUserProfilePhoto)user.Photo); var photoLocation = (TLFileLocation)photo.PhotoBig; TLFile file = await client.GetFile(new TLInputFileLocation() { LocalId = photoLocation.LocalId, Secret = photoLocation.Secret, VolumeId = photoLocation.VolumeId }, 1024 * 256); using (var m = new MemoryStream(file.Bytes)) { var img = Image.FromStream(m); img.Save("profileimg", System.Drawing.Imaging.ImageFormat.Jpeg); } var rq = new TeleSharp.TL.Users.TLRequestGetFullUser { Id = new TLInputUserSelf() }; TLUserFull rUserSelf = await client.SendRequestAsync <TeleSharp.TL.TLUserFull>(rq); TLUser userSelf = (TLUser)rUserSelf.User; Properties.Settings.Default.Name = userSelf.Username; Properties.Settings.Default.Save(); this.Hide(); Main main = new Main(); main.ShowDialog(); } }