コード例 #1
0
        public async Task AuthUser()
        {
            var store = new FileSessionStore();
            var client = new TelegramClient(store, "session", apiId, apiHash);

            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);
            Assert.IsTrue(client.IsUserAuthorized());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: navaei/TLSharp
        private static async Task MakeAuthentication(TLSharp.Core.TelegramClient client, string mainPhoneNumber)
        {
            var hash = await client.SendCodeRequestAsync(mainPhoneNumber);

            Console.WriteLine("waiting for code");
            var code = Console.ReadLine();
            var user = await client.MakeAuthAsync(mainPhoneNumber, hash, code);

            if (!client.IsUserAuthorized())
            {
                hash = await client.SendCodeRequestAsync(mainPhoneNumber);

                Console.WriteLine("please try again.add code");
                code = Console.ReadLine();
                user = await client.MakeAuthAsync(mainPhoneNumber, hash, code);
            }
        }
コード例 #3
0
        public async Task SignUpNewUser()
        {
            var store = new FileSessionStore();
            var client = new TelegramClient(store, "session", apiId, apiHash);
            await client.Connect();

            var hash = await client.SendCodeRequest(NotRegisteredNumberToSignUp);
            var code = "";

            var registeredUser = await client.SignUp(NotRegisteredNumberToSignUp, hash, code, "TLSharp", "User");
            Assert.IsNotNull(registeredUser);
            Assert.IsTrue(client.IsUserAuthorized());

            var loggedInUser = await client.MakeAuth(NotRegisteredNumberToSignUp, hash, code);
            Assert.IsNotNull(loggedInUser);
        }
コード例 #4
-1
ファイル: TLSharpTests.cs プロジェクト: csdsoft/TLSharp
		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);
		}
コード例 #5
-1
ファイル: TLSharpTests.cs プロジェクト: csdsoft/TLSharp
		public async Task ImportByUserNameAndSendMessage()
		{
			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);

			await client.SendMessage(res.Value, "Test message from TelegramClient");
		}
コード例 #6
-1
ファイル: TLSharpTests.cs プロジェクト: csdsoft/TLSharp
		public async Task UploadAndSendMedia()
		{
			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);
			const string testFile = "TEST";

			var file = File.ReadAllBytes("../../data/cat.jpg");

			var mediaFile = await client.UploadFile("test_file.jpg", file);

			Assert.IsNotNull(mediaFile);

			var state = await client.SendMediaMessage(res.Value, mediaFile);

			Assert.IsTrue(state);
		}
コード例 #7
-1
ファイル: TLSharpTests.cs プロジェクト: csdsoft/TLSharp
		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);
		}