SendZen API Documentation
Home
Getting StartedChangelog
Home
Getting StartedChangelog
Visit Website
Sign In
Create an account
  1. Programming Languages
  • Start Guide
    • Getting Started
    • API Reference
  • Messages
    • Template Messages
      • Send Text Message
      • Send Interactive Message
      • Send Media Message
    • Session Messages
      • Send Text Message
      • Send Image Message
      • Send Video Message
      • Send Audio Message
      • Send Document Message
      • Send Interactive Reply Message
    • Incoming Messages
      • Received Text Message
      • Received Message with Reaction
      • Received Media Message with Image
      • Received Callback from a Quick Reply Button Click
    • Other
      • Message Status & Typing Indicator
  • Template
    • List Templates
      GET
    • Create Template
      POST
    • Delete Template
      DELETE
    • Upload Media
      POST
  • Partner
    • Integration Guide
  • Project
    • Create Project
      POST
    • List Projects
      GET
    • Update Project
      PUT
    • Retrieve Project
      GET
  • WABA
    • List WABA
      GET
    • Retrieve WABA Details from Meta
      GET
    • Retrieve WhatsApp Business Profile Detail
      GET
    • Update WhatsApp Business Profile
      POST
    • Upload WhatsApp Business Profile
      POST
  • Activity Logs
    • All Event Logs
    • Incoming Message Logs
    • Message Status Logs
    • Other Event Logs
    • Multiple Event Types
  • Knowledge Base
    • Programming Languages
      • Python
      • Node.js
      • PHP
      • Laravel
      • Java
      • C# .NET
    • Product
      • Changelog
  • Schemas
    • Schemas
      • Template Message
      • 401/403 Message Response
      • AccountLoginRequest
      • APIKeyDto
      • ReadTypingIndicatorRequest
      • AccountRegisterRequest
      • TypingIndicator
      • PartnerConfigDto
      • LoginResponse
      • PartnerInfoDto
      • WABASignUp
      • OrderCheckoutDto
      • OrderDto
      • OrderStatusEnum
      • PaymentGatewayDto
    • Knowledge Base
    • Address
    • Account
    • CommonResponse
    • AccountDetailDto
    • CreateOrUpdateProjectRequest
    • Contact
    • Error
    • ContactName
    • Button
    • ErrorResponse
    • CarouselCard
    • Email
    • ClientData
    • Component
    • ProjectDetailDto
    • ProjectWABADetail
    • Interactive
    • WABADetail
    • InteractiveAction
    • WABADto
    • InteractiveBody
    • CreateTemplateRequest
    • InteractiveButton
    • InteractiveFooter
    • CreateWebhookConfigRequest
    • InteractiveHeader
    • InteractiveMedia
    • Example
    • InteractiveProductItem
    • InteractiveProductSection
    • InteractiveReply
    • InteractiveRow
    • InteractiveSection
    • Location
    • Media
    • MessageRequest
    • MessageResponse
    • MessageTemplate
    • Organization
    • LimitedTimeOffer
    • Phone
    • Reaction
    • Response
    • TemplateAction
    • NamedParameter
    • TemplateButtons
    • TemplateCarousel
    • TemplateComponent
    • TemplateCurrency
    • PaginatedWebhookLogsResponse
    • TemplateDateTime
    • PartnerClientSession
    • TemplateLimitedTimeOffer
    • PartnerClientSessionDto
    • TemplateMedia
    • TemplateParameter
    • TemplateProductItem
    • TemplateSection
    • TemplateTapTargetConfiguration
    • SupportedApp
    • Text
    • Url
    • WhatsAppBusinessProfile
    • UploadMedia
    • Webhook
    • WebhookConfigDto
    • WebhookLogDto
Home
Getting StartedChangelog
Home
Getting StartedChangelog
Visit Website
Sign In
Create an account
  1. Programming Languages

WhatsApp API with C# .NET

This guide provides everything you need to send messages, build bots, and automate communication by using the WhatsApp API in C#.
Unofficial libraries like bailey's and evolution that rely on web scraping are unreliable and will get your number banned. Using the official WhatsApp Business API C# is the only stable and scalable method for professional applications.
SendZen makes integrating the WhatsApp API into your C# applications incredibly simple. Let's dive in.
This guide covers:
Send WhatsApp message in C# - Complete API integration examples.
Receiving messages using an ASP.NET Core webhook.
Create WhatsApp bot in C# - Build interactive bots from scratch.
WhatsApp API C# GitHub - Production-ready code examples.
Best practices for production, including WhatsApp business API integration C#.

Prerequisites#

Before you start, you'll need:
1.
.NET 6.0+ or .NET 7.0+ installed.
2.
A free SendZen.io Account to get your API Key.
3.
For the webhook examples, we'll use ASP.NET Core.
Create a new project:

Part 1: How to Send a WhatsApp Message with C##

Sending a transactional message programmatically, like an order confirmation or OTP is the core use case. This guide shows you how to send WhatsApp message programmatically C# using the official WhatsApp API C#. This C# code uses HttpClient to make a simple API call to the WhatsApp Cloud API C#. This demonstrates WhatsApp API integration C# best practices.
Create a file named SendZenMessageSample.cs and add the following code.
To run this script:
1.
Replace YOUR_API_TOKEN,FromPhoneNumberand SampleRecipientPhoneNumber with your details.
2.
Create a console project and run: dotnet run.
You've just successfully sent an automated WhatsApp message using C#! This simple function demonstrates how to send WhatsApp message in C# and is the foundation for all outbound messaging. This C# code to send WhatsApp message can be easily integrated into your applications.
More template message request samples
More session message request samples

Part 2: Receiving Messages with a C# Webhook#

To build a WhatsApp bot, your application needs to listen for incoming messages using webhooks. When a user messages your number, WhatsApp sends the message data as a JSON POST request to a URL you specify.
We'll use ASP.NET Core to create a simple webhook server.
1. Create a Webhook Controller (Controllers/WhatsAppWebhookController.cs):
2. Update Program.cs or Startup.cs (for .NET 6+):
To make this work:
1.
Run the ASP.NET Core App: dotnet run. Your server is now running on localhost:5000 (or the port specified in launchSettings.json).
2.
Expose to the Web: WhatsApp can't reach localhost. Use a tool like ngrok to create a public URL for your local server:
3.
Configure the Webhook: Copy the https://....ngrok.io URL provided by ngrok, append your route (/webhooks/whatsapp), and paste it into the Webhook URL field in your SendZen dashboard.
Now, when you send a message to your WhatsApp number, you'll see the message data printed in your console.

Part 3: Building a Complete WhatsApp Bot in C##

Let's combine what we've learned to create a simple but complete WhatsApp bot. This bot will reply to specific keywords, demonstrating a full WhatsApp bot API C# implementation.
We'll modify our controller to include the SendWhatsAppMessageAsync function.
Run this updated ASP.NET Core application with ngrok again. Now, when you send "hello" or "status" to your WhatsApp number, the bot will reply automatically! This is the foundation for all WhatsApp automation with C# and demonstrates how to send WhatsApp message using C# programmatically.

Advanced Topics & Best Practices#

Scaling Up: C# WhatsApp Bulk Sender#

To send bulk WhatsApp messages programmatically in C#, such as alerts to all your users, simply loop through a list of recipient numbers and call the SendWhatsAppMessageAsync function for each. Use Task.WhenAll for parallel processing.
Important: To initiate conversations with users, WhatsApp requires you to use pre-approved Message Templates. This is a crucial policy to prevent spam. You can easily manage and send templates via the SendZen API. For bulk campaigns, use templates.

ASP.NET Core WhatsApp API Integration#

For a more robust ASP.NET Core implementation, create a service class to separate concerns and use dependency injection.
1. Create a Service Interface (Services/IWhatsAppService.cs):
2. Create a Message Request Model (Models/SendMessageRequest.cs):
3. Create a Service Implementation (Services/WhatsAppService.cs):
4. Register the Service (Program.cs):
5. Update Controller to Use Service:

Using HttpClientFactory (Recommended)#

For production applications, use IHttpClientFactory to properly manage HttpClient instances:

Webhook Security#

Add webhook signature validation for production:

Twilio WhatsApp C# Alternative#

Unlike Twilio which doesn't provide integration with your own number in free account, SendZen provides a free account to hlep you complete the WhatsApp API C# integration. Also, with Twilio you will have to spend an additional $0.0050 for each message sent on top of the Meta charges, SendZen doesnt have any extra markup and thus is the most preffered tool compared to Twilio to send WhatsApp message in C#.

Send WhatsApp Message from ASP.NET C##

For ASP.NET Core send WhatsApp message functionality, use the service pattern demonstrated in this guide.

Send WhatsApp Message from Windows Application C##

You can also use this code in Windows Forms or WPF applications. This allows you to send WhatsApp message from Windows application in C# directly from desktop applications.

Common Questions#

Here are solutions to the most frequent integration scenarios for C# developers.

Sending & Integration#

QuestionSolution
How do I send a WhatsApp message in C#?Use the HttpClient example provided in Part 1. It works for Console, Windows Forms, WPF, and Web Apps.
Can I send messages from a Desktop App (WPF/WinForms)?Yes. The code in Part 1 is standard .NET Standard 2.0+ compatible and works in any Windows desktop application.
How do I send messages in ASP.NET Core?We recommend creating a Service class (see Advanced Topics) and injecting it into your controllers for a clean architecture.
Do you have a NuGet package or SDK?While we do not have a specific SDK, our API is standard REST. You can simply copy the DTO classes from Part 1 directly into your project.

Automation & Bots#

QuestionSolution
How do I receive messages?You need to set up a Webhook. See Part 2 for the ASP.NET Core implementation.
How do I build a chatbot?A chatbot is simply a Webhook (Part 2) that triggers a Send Message function (Part 1) based on logic. See Part 3 for the full code.
Can I send bulk messages?Yes, but you must use Message Templates for marketing or unsolicited alerts. See Bulk Sending.

Alternatives & Licensing#

QuestionAnswer
Is this free to test?Yes, SendZen provides a free tier for development and testing. Sign up here.
Can I use this instead of Twilio?Yes. SendZen is often preferred for C# developers due to simplified JSON payloads and direct support for WhatsApp Cloud API features without the complexity of Twilio.
Where can I find more examples?Check our GitHub Repository for full solution files.

Start Building Now#

With SendZen's developer-first WhatsApp API C# solution, you can stop wrestling with complex setups and focus on creating amazing applications. Use this guide to integrate WhatsApp API in C#, send WhatsApp message programmatically C#, and build robust WhatsApp API integration C# solutions.
Sign Up for Free & Get Your API Key →
Modified at 2025-12-03 12:40:32
Previous
Java
Next
Changelog
Built with