How To Send Whats App Messages Programmatically in android/.Net

Image result for How can you send whatsapp messages programmatically in android

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):-

alt text
Fig 1-The User Interface
On the click event of the button write following code:-

Use string nickname = “Mani”;

  1. string senderp = “your number with country code”;
  2. string password = “your password”; // Obtain it with WART or Yowsup
  3. WhatsApp wa = new WhatsApp(senderp, password, nickname, true);
  4. wa.OnConnectSuccess += () =>
  5. {
  6. Console.WriteLine(“Connected”);
  7. wa.OnLoginSuccess += (phoneNumber, data) =>
  8. {
  9. MessageBox.Show(“Connection success!”);
  10. wa.SendMessage(txtNo.Text/* Number */, txtMsg.Text);
  11. MessageBox.Show(“Message sent!”);
  12. };
  13. wa.OnLoginFailed += (data) =>
  14. {
  15. MessageBox.Show(“Login failed: {0}”, data);
  16. };
  17. wa.Login();
  18. };
  19. wa.OnConnectFailed += (ex) =>
  20. {
  21. MessageBox.Show(“Connect failed: {0}”, ex.StackTrace);
  22. };
  23. wa.Connect();
  24. 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:-

alt text
Fig 2-WART Screen
Put you mobile number with country code in the textbox. And press “Check Existing”. If you see the following screen,you’re good to go:-

alt text
Fig 2-WART Response for Mobile Number
Now click “Request Code” button and one OTP(One Time Password) will be sent to your mobile. Put that OTP in the ” Confirm Code TextBox of Step 2″ and “Confirm Code” button.
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.:-)

Bhardwaj Brothers
Founder
Hey Readers, Welcome to my blog ByNext. I'm Akash Bhardwaj, a professional-blogger from New Delhi, India.

I started ByNext as a passion and now it's empowering more than 500,00+ readers globally and helping them to make money with their blog.

Here at ByNext I write about Starting & managing a blog, WordPress, Social-media, SEO and Making Money online.

Leave a Reply

Your email address will not be published. Required fields are marked *