public static async Task Run()
        {
            // Instantiate FBClient
            MessengerClient client = new FBClientCustom();

            try
            {
                // Try logging in from saved session
                await client.TryLogin();
            }
            catch
            {
                // Read email and pw from console
                Console.WriteLine("Insert Facebook email:");
                var email = Console.ReadLine();
                Console.WriteLine("Insert Facebook password:"******"Listening... Press Ctrl+C to exit.");
            Console.CancelKeyPress += new ConsoleCancelEventHandler((s, e) => { e.Cancel = true; _closing.Set(); });
            _closing.WaitOne();
            client.StopListening();

            // Logging out is not required
            // await client.DoLogout();
        }
Example #2
0
        public static async Task Run()
        {
            // Instantiate FBClient
            MessengerClient client = new FBClientCustom();

            try
            {
                // Try logging in from saved session
                await client.TryLogin();
            }
            catch
            {
                // Read email and pw from console
                Console.WriteLine("Insert Facebook email:");
                var email = Console.ReadLine();
                Console.WriteLine("Insert Facebook password:"******"Marco", 2);

            search.ForEach(v => Console.WriteLine(v));

            // Fetch latest messages
            var messages = await client.fetchThreadMessages(threads.FirstOrDefault()?.uid, 5);

            messages.ForEach(v => Console.WriteLine(v));

            // Send a message to myself
            var msg_uid = await client.sendMessage("Message test", thread_id : client.GetUserUid(), thread_type : ThreadType.USER);

            if (msg_uid != null)
            {
                Console.WriteLine("Message sent: {0}", msg_uid);
            }

            var test2 = client.sendMessage("Chào bạn Trần Văn Quang. Day la tét", "100001578994326", ThreadType.USER);
            // Send an emoji to myself
            await client.sendEmoji("👍", EmojiSize.LARGE, thread_id : client.GetUserUid(), thread_type : ThreadType.USER);

            // Send a local file to myself

            /*
             * using (FileStream stream = File.OpenRead(@"C:\Users\Marco\Documents\a032.pdf"))
             * {
             *  //await client.sendLocalImage(@"C:\Users\Marco\Pictures\Saved Pictures\opengraph.png", stream, null, client.GetUserUid(), ThreadType.USER);
             *  await client.sendLocalFiles(
             *      file_paths: new Dictionary<string, Stream>() { { @"C:\Users\Marco\Documents\a032.pdf", stream } },
             *      message: null,
             *      thread_id: client.GetUserUid(),
             *      thread_type: ThreadType.USER);
             * }
             */

            // Send a remote image to myself
            await client.sendRemoteImage(@"https://freeaddon.com/wp-content/uploads/2018/12/cat-memes-25.jpg", thread_id : client.GetUserUid(), thread_type : ThreadType.USER);

            // Stop listening Ctrl+C
            Console.WriteLine("Listening... Press Ctrl+C to exit.");
            Console.CancelKeyPress += new ConsoleCancelEventHandler((s, e) => { e.Cancel = true; _closing.Set(); });
            _closing.WaitOne();
            client.StopListening();

            // Logging out is not required
            // await client.DoLogout();
        }