2

I'm using the last nuget version for whatsapp: WhastApp API 1.2.2 and reading tutorials about configure my whatsapp in my application. I'm using my localhost to test and my code is:

string from = "503XXXX";
            string to = "503XXXX";
            string msg = "lorem ipsum";

            WhatsApp wa = new WhatsApp(from, "jd8eY3FXXXXXXXXXXXXXXXXXXX", "MrMins", true);

            wa.OnConnectSuccess += () =>
                                       {
                                           wa.OnLoginSuccess += (phoneNumber, data) =>
                                                                    {
                                                                        wa.SendMessage(to, msg);
                                                                    };
                                       };

            wa.OnLoginFailed += (data) =>
            {
                //Fail message
            };

            wa.Login();

            wa.OnConnectFailed += (ex) =>
            {
                //ConnectionFailed
            };

            wa.Connect();
            wa.SendMessage(to, msg);
            wa.Disconnect();

I'm getting the error:

Auth response error 

I updated my whatsapp password with WART and logged me out from my whatsapp mobile (I think is the correct behavior), but is still not working.

What is wrong with my codes?

Benjamin RD
  • 11,516
  • 14
  • 87
  • 157
  • I had similar question see this link: http://stackoverflow.com/questions/27745722/c-sharp-how-to-send-messages-with-whatsapi-net – daniel59 Jan 29 '16 at 06:51

2 Answers2

1

I guess your problem is, that you try to send a message also if the connection failed. Try this instead of your code to send a message:

WhatsApp wa = new WhatsApp("your number", "your password", "your nickname", false, false);
wa.OnConnectSuccess += () =>
{
    Response.Write("connect");
    wa.OnLoginSuccess += (phno,data) =>
    {
        wa.SendMessage("to", "msg");
    };

    wa.OnLoginFailed += (data) =>
    {
        Response.Write("login failed"+data);
    };
    wa.Login();
};
wa.OnConnectFailed+= (ex)=>
{
    Response.Write("connection failed");
}

This avoids the sending if the connection failed.

PS: If in your code the connection succeeded you would send the message twice.

daniel59
  • 906
  • 2
  • 14
  • 31
1

Imagine, your code area is: 503 and your phone number is 555555555555

WhatsApp wa = new WhatsApp("503555555555555", "get the password using WART", "your nickname", false, false);
            wa.OnConnectSuccess += () =>
            {
                Response.Write("connect");
                wa.OnLoginSuccess += (phno,data) =>
                {
                    wa.SendMessage("Destinatino number (50377777777777)", "Youre custom message");
                };

                wa.OnLoginFailed += (data) =>
                {
                    Response.Write("login failed"+data);
                };
                wa.Login();
            };
            wa.OnConnectFailed += (ex) =>
                                      {
                                          Response.Write("connection failed");
                                      }
                ;

            wa.Connect();
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157