Whats app messages programmatically in android/.Net
This time I am here with a very small article about sending WhatsApp Message from your .Net application.
You need following things for that.
1-WART(WhatsApp Registration Tool)
This a tool with which you can get the password to be used in API.
2-WhatsApp Api for C#(Highly Unstable Currently and Without any proper documentation)
3- Any mobile number on which you are not using WhatsApp currently and You will not be using it in future for WhatApp(As your number may be blocked if you send multiple messages. Again the blocking criteria is uncertain and my number was blocked after 3-5 messages !!):-(
So first thing first. Download the WhatsApp Api for C# via nuget package manager. If you see a reference of the API in your reference,that’s good. Otherwise download the API manually and add the reference.
Now we are all set for creating our application. So create the UI like following(I used WinForms):-
Use string nickname = “Mani”;
- string senderp = “your number with country code”;
- string password = “your password”; // Obtain it with WART or Yowsup
- WhatsApp wa = new WhatsApp(senderp, password, nickname, true);
- wa.OnConnectSuccess += () =>
- {
- Console.WriteLine(“Connected”);
- wa.OnLoginSuccess += (phoneNumber, data) =>
- {
- MessageBox.Show(“Connection success!”);
- wa.SendMessage(txtNo.Text/* Number */, txtMsg.Text);
- MessageBox.Show(“Message sent!”);
- };
- wa.OnLoginFailed += (data) =>
- {
- MessageBox.Show(“Login failed: {0}”, data);
- };
- wa.Login();
- };
- wa.OnConnectFailed += (ex) =>
- {
- MessageBox.Show(“Connect failed: {0}”, ex.StackTrace);
- };
- wa.Connect();
- MessageBox.Show(“END”);
Where “nickname” is the name you want to appear on behalf of the mobile number(yours) which is defined in “senderp”.
The “password” is the password which we get using the “WART” tool which I’ll be telling later.
txtNo is the the textbox in the UI to which the message is to be sent. You need to add “91” while entering the number(For India) or you can add a dropdown with multiple country codes,the choice is yours.
I don’t think I need to tell you about txtMsg
Now you are ready to send the message but you need the password.So open the WART.exe. You’ll see the user interface something like following:-
You’ll get the password in the “Step 3” block.
Copy the number and paste it in the place of “your number” in the code written above.
Similarly copy the password and place it in the place of “your password” in the code written above.
Now you are done with coding part. Run the application and enjoy sending the messages from you .net application.
There are some limitation of current version of C# API.
So Please take them into account while creating the application.(I found them while creating this demo application)
1-There is almost no documentation of this API for development. All you can do is hours of searching for any new requirement. The PHP API is better.
2-Highly unstable. You may get into endless loop of connection errors even if you’ve done everything right from your end or you may get it right in first attempt.
3-Sending 5 or more message to a mobile number (in my case sending 3 messages overall) may block your number(Criteria me differ as I’ve seen some people saying that they’ve sent thousands of messages without getting blocked). There is an idea to check that you number is blocked or not. Just put your mobile number in the WART tool and click “Check Existing”. This will tell you if you number is blocked. I couldn’t find any idea to unblock it though.
4-With that said,please do not use your actual WhatsApp number as you may face blocking of the same. That’s why I recommended many sim cards.
So this was the idea of sending WhatsApp message with .NET. Will update you If I find anything useful. Till then try trying this example by keeping 4 points in your mind.:-)