From sgcWebSockets 2022.6.0 WhatsApp Cloud API is supported for .NET.
Send and receive messages using a cloud-hosted version of the WhatsApp Business Platform. The Cloud API allows you to implement WhatsApp Business APIs without the cost of hosting of your own servers and also allows you to more easily scale your business messaging. The Cloud API supports up to 80 messages per second of combined sending and receiving (inclusive of text and media messages).
The WhatsApp Business API allows medium and large businesses to communicate with their customers at scale. Using the API, businesses can build systems that connect thousands of customers with agents or bots, enabling both programmatic and manual communication. Additionally, you can integrate the API with numerous backend systems, such as CRM and marketing platforms.
Businesses will get all the new features faster on Cloud API. Right now, WhatsApp Business Cloud API comes with all the features that are available with WhatsApp Business API.
Useful features of WhatsApp Cloud API:
To send and receive a first message using a test number, complete the following steps:
1. Set up Developer Assets and Platform Access
From the App Dashboard, click on the app you would like to connect to WhatsApp. Scroll down to find the "WhatsApp" product and click Set up.
Next, you will see the option to select an existing Business Manager (if you have one) or, if you would like, the onboarding process can create one automatically for you (you can customize your business later, if needed). Make a selection and click Continue.
When you click Continue, the onboarding process performs the following actions:
2. Send a Test Message
Now, you can open your IDE and create a new project. Drop a TsgcWhatsapp_Client component and fill the following properties:
Once those 2 properties have been property configured, call the method SendTest to send your First message to a phone number using the Whatsapp Business Platform.
TsgcWhatsapp_Client oClient = new TsgcWhatsapp_Client(); oClient.WhatsappOptions.PhoneNumberId = "107809351952205"; oClient.WhatsappOptions.Token = "EAAO4OpgZAs98BAGj3nCFGr...ZB2t8mmLB2LRXJkte2Y5PMNh2"; oClient.SendTest("34605889421");
3. Configure a Webhook
To get alerted when you receive a message or when a message's status has changed, you need to set up a Webhooks endpoint for your app. Setting up Webhooks doesn't affect the status of your phone number and does interfere with you sending or receiving messages.
To get started, first you need to create the endpoint, so first configure the ServerOptions property of WhatsApp Client component and configure the following properties:
After configuring the server, you can use the method StartServer to start the server and accept the incoming requests.
TsgcWhatsapp_Client oClient = TsgcWhatsapp_Client.Create(); oClient.ServerOptions.WebhookOptions.Endpoint = "/webhook"; oClient.ServerOptions.WebhookOptions.Token = "MySecretToken"; oClient.StartServer();
Once your endpoint is ready, go to your App Dashboard.
In your App Dashboard, find the WhatsApp product and click Configuration. Then, find the webhooks section and click Configure a webhook. After the click, a dialog appears on your screen and asks you for two items:
After adding the information, click Verify and Save.
Back in the App Dashboard, click WhatsApp > Configuration in the left-side panel. Under Webhooks, click Manage. A dialog box will open with all the objects you can get notified about. To receive messages from your users, click Subscribe for messages.
4. Receive a test message
Every time a new message is received, the client event OnMessageReceived will be called.
void OnWhatsAppMessageReceived(TsgcWhatsApp_Client Sender, TsgcWhatsApp_Receive_Message Message, ref bool MarkAsRead) { DoLog("Message Received: [" + Message.From + "] " + Message.Text); MarkAsRead = true; }
Now that your Webhook is set up, send a message to the test number you have used. You should immediately get a Webhooks notification with the content of your message!
Find below a public online WhatsApp Bot Demo, just send any text message to start.
Find below the compiled WhatsApp Demo for Windows.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.