Monday 28 September 2015

Send Video and Image and Text Msg in Whatsapp

 WhatsUserManager manager = new WhatsUserManager();
            user = manager.CreateUser(txtphonenumber.Text, "Bhavdip Tala");
            var thread = new Thread(ThreadState =>
            {
                UpdateTextBox textbox = UpdateDataTextBox;

                WhatSocket.Create(txtphonenumber.Text, textBoxPass.Text, textBoxNick.Text, true);

                WhatSocket.Instance.OnConnectSuccess += () =>
                {
                    if (txtstatus.InvokeRequired)
                    {
                        Invoke(textbox, txtstatus, "connected...");
                    }

                    WhatSocket.Instance.OnLoginSuccess += (phone, data) =>
                    {
                        Invoke(textbox, txtstatus, "Login Success...");

                        //WhatSocket.Instance.SendDeleteAccount();
                        while (WhatSocket.Instance != null)
                        {
                            WhatSocket.Instance.pollMessage();
                            Thread.Sleep(200);
                            continue;
                        }

                    };

                    WhatSocket.Instance.OnGetMessage += (node, from, id, name, message, receipt_sent) =>
                    {
                        if (txtstatus.InvokeRequired)
                        {
                            string[] words = from.Split('@');

                            if (WhatSocket.Instance.ConnectionStatus == ApiBase.CONNECTION_STATUS.LOGGEDIN)
                            {
                                if (message.ToString().ToUpper().Contains("IMG"))
                                {
                                    byte[] img = File.ReadAllBytes(@"D:\P1.Jpg");
                                    WhatSocket.Instance.SendMessageImage(words[0] + "@s.whatsapp.net", img, ApiBase.ImageType.JPEG);
                                }
                                else if (message.ToString().ToUpper().Contains("VID"))
                                {
                                    byte[] img = File.ReadAllBytes(@"D:\EMERALD.mp4");
                                    WhatSocket.Instance.SendMessageVideo(words[0] + "@s.whatsapp.net", img, ApiBase.VideoType.MP4);
                                }
                                else
                                 {
                                    Invoke(textbox, txtstatus, string.Format("\r\n {0}:{1}", name + " : " + words[0], message));
                                }
                            }
                        }
                    };
                    WhatSocket.Instance.OnLoginFailed += (data) =>
                    {
                        if (txtstatus.InvokeRequired)
                        {
                            Invoke(textbox, txtstatus, string.Format("\r\n Login Failed : {0}", data));
                        }
                    };
                    WhatSocket.Instance.Login();
                };
                WhatSocket.Instance.OnConnectFailed += (ex) =>
                {
                    if (txtstatus.InvokeRequired)
                    {
                        Invoke(textbox, txtstatus, string.Format("\r\n Connect Failed : {0}", ex.StackTrace));
                    }
                };
                WhatSocket.Instance.Connect();
            }) { IsBackground = true };
            thread.Start();

9 comments:

  1. HI
    I also tried the code as mentioned in your blog but still the images are not going.below is the code what i have used. can you tell me whats is wrong in the code. Please help me


    WhatsApp wa;
    wa = new WhatsApp(mobileno, pwd, "demo");
    wa.Connect();
    wa.Login();
    byte[] img = File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
    wa.SendMessageImage(txtto.text & '@s.whatsapp.net",img,ApiBase.ImageType.JPEG);


    Please help me.

    ReplyDelete
    Replies
    1. wa = new WhatsApp(mobileno, pwd, "demo");

      Change as like below

      wa = new WhatsApp(91978xxxx49, WART Generated Password, "User Name");

      Delete
    2. i have put link,demo code plz check it

      Delete
  2. Kindly provide vb.net Version ...

    I have used converter but i'm strucked.

    ReplyDelete
  3. I tried to upload video but video is sent to target number and when user try to download it gives error The download was unable to complete. Please try again later.

    Kindly guide.

    ReplyDelete
    Replies
    1. http://bhavdiptala.blogspot.in/2015/10/demo-code-send-video-in-whatsapp-using-c.html

      Delete
    2. Thank you very much. It is working very fine with mp4 and mov files but in avi files video not able to download. Getting error "The download was unable to complete. Please try again later."

      Delete
  4. Can someone please share their application with me?

    ReplyDelete

SqlDataBaseLibrary

using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using AOS.Repository.Infrastructure; using S...