July 6, 2020
Whatsapp Business API Integration NodeJs

Whatsapp Business API Integration In C#

Whatsapp Business API Integration in C# is actually an exhaustive process for any developer solely because with the latest norms you cannot move onto the development process till you have verified business account for Facebook and hence, Whatsapp and verification could take from 2 days to 14 days. So, practically you have to wait 14 days to even start with the development and then, figure out how the messages would go and so on. Because of this limitation, there is some third-party software that allow to use the sandbox model and integrate the code before even you have verified the code. Blessing right. Here, we are using one such third party namely Twilio. One needs to install the NuGet package, and then can start using the sandbox model immediately. Though it has limitations as you can only test with one phone number and very few messages before you verify the business account. But still, that’s the best thing available. So, let’s dive straight into the tutorial.

1.Install NuGet Package

First step for Whatsapp business API integration in C# is to Open nuGet Package Console and type the below command to download the nuGet package.

install-Package twilio

Whatsapp Business API Integration In C#

2.Make Twilio Account

For Whatsapp business API integration in C# you need to have tokens. Next step is to sign up to twilio account and get twilio accountSID and AuthToken

Go to site:https://www.twilio.com/

Signup, enter your phone number and other basic details and you would get credentials on the console screen

Whatsapp Business API Integration In C#

3. Write the Code

Now, let’s begin coding! Add the packages and paste the code where you require and replace your credentials obtained on the previous step.

using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

//add the code into the function

try
{
   ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
   TwilioClient.Init(“Account SID”, “AUTH TOKEN”);
    MessageResource.Create(
    from: new Twilio.Types.PhoneNumber(“whatsapp:+14155238886”),
    body: “Hello,!”,// link code
    // Convert.ToString(dsProfile.Tables[0].Rows[0]       [HealNTService.DOCUMENT_SERVER_URL]);

to: new Twilio.Types.PhoneNumber(“whatsapp:+919999999999”)
);

//replace your number here
}
catch (Exception ex)
{
 console.Write(ex);

}

Note for Sandbox model from would remain to be twilio number, and also write phone number with the international code as above otherwise it would throw exception. So, you go to replace three things above, authsid, auth token and your registered number with twilio. And it would send Whatsapp message onto the number.

4.Testing the Code on Whatsapp

Whatsapp Business API Integration In C#

On twilio you can customize the way the message would appear and layout stuffs are cool. The output should be similar to this.

5.Verifying Business Account

And, verifying business account is the last step how cool is that. Though you can’t use sandbox on production also just a few test messages are allowed.So, you go to verify the business account following the official link

https://www.facebook.com/business/help/2058515294227817?id=180505742745347

That was a short and complete guide on the Whatsapp business API integration in C#. You should be good to go 🤓

 

admin

Engineer Diaries started with the need to bridge the huge gap in what we are taught vs what the industry demands. We are based in Delhi, India but our blog is for everyone, in and outside tech industry❤ Feel free to reach out to us at engineerdiaries@gmail.com for any business/personal query.

View all posts by admin →

Leave a Reply