private async void button2_Click(object sender, RoutedEventArgs e)
         {
 
             await client.ConnectAsync();       
 
             // Here is the code that will add a new contact and send a test message
             TeleSharp.TL.Contacts.TLRequestImportContacts requestImportContacts = new TeleSharp.TL.Contacts.TLRequestImportContacts();
             requestImportContacts.Contacts = new TLVector<TLInputPhoneContact>();
             requestImportContacts.Contacts.Add(new TLInputPhoneContact()
             {
                 Phone = "new Number in global format example : 98916*******",
                 FirstName = "new Number's FirstName",
                 LastName = "new Number's LastName"
             });
             var o = await client.SendRequestAsync<TeleSharp.TL.Contacts.TLImportedContacts>((TLMethod)requestImportContacts);
             var NewUserId = (o.Users.First() as TLUser).Id;
             var d = await client.SendMessageAsync(new TLInputPeerUser() { UserId = NewUserId }, "test message text");
 
 
 
             //find recipient in contacts and send a message to it
             var result = await client.GetContactsAsync();           
             var user = result.Users
                 .Where(x => x.GetType() == typeof(TLUser))
                 .Cast<TLUser>()
                 .FirstOrDefault(x => x.Phone == "recipient Number in global format example : 98916*******");
             MessageBox.Show((user.LastName).ToString());
 
             //send message
             await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, "hi test message");
         }
示例#2
0
        static async void a()
        {
            var store  = new FileSessionStore();
            var client = new TelegramClient(apiId, apiHash, store, "session");// or C:\\Temp\\mySession
            await client.ConnectAsync();

            if (!client.IsUserAuthorized())
            {
                var hash = await client.SendCodeRequestAsync(phoneNumber);      //отсылаем запрос на создании сессии

                var code = Console.ReadLine();                                  // код который придет от Telegram

                var user = await client.MakeAuthAsync(phoneNumber, hash, code); // создаем сессию
            }

            //var userByPhoneId = await client.("791812312323"); // импорт по номеру телефона
            //var userByUserNameId = await await client.ImportByUserName("userName"); // импорт по юзернейму

            var s = await client.IsPhoneRegisteredAsync("xxxxxxxxxxx");//WHO WRITE//WHO WRITE

            var f = await client.GetContactsAsync();

            Console.WriteLine("контакты");
            f.contacts.lists.ForEach(_ => { Console.WriteLine(_.user_id); });

            TeleSharp.TL.Contacts.TLRequestImportContacts requestImportContacts = new TeleSharp.TL.Contacts.TLRequestImportContacts();
            requestImportContacts.contacts = new TLVector <TLInputPhoneContact>();
            requestImportContacts.contacts.lists.Add(new TLInputPhoneContact()
            {
                phone      = "xxxxxxxxxxx",//WHO WRITE//WHO WRITE//WHO WRITE//WHO WRITE//WHO WRITE?
                first_name = "",
                last_name  = ""
            });
            var o = await client.SendRequestAsync <TeleSharp.TL.Contacts.TLImportedContacts>((TLMethod)requestImportContacts);

            var NewUserId = (o.users.lists.First() as TLUser).id;
            var d         = await client.SendMessageAsync(new TLInputPeerUser()
            {
                user_id = NewUserId
            }, "text xxx");

            //return true;
        }