Send messages to WhatsApp Channels using C# (.NET)

Learn how to send automated and scheduled messages to your WhatsApp Channels to keep your audience engaged and updated using C# (.NET) in simple steps with ready-to-use code examples.

Wassenger
6 min readOct 28, 2024

--

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes!

This will allow us to perform the following deliveries

  • Send text messages
  • Send scheduled text messages
  • Send images
  • Send videos
  • Send polls
  • Send Scheduled polls

Requirements

  • Have a WhatsApp number already linked to the platform and online.
  • Channel WhatsApp ID (WID) that you can find in two ways:
  1. On your WhatsApp number’s management panel, go to “Groups”. From there you will see the channels your number has access to.
  2. By using the API, query the available channels in your device for this endpoint.

API endpoint

In this tutorial we will use the following API endpoint:

Explore how to use the code in your browser without installing any software.

Also, you can find different languages you can test on Replit.com:

# Send text messages using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"{{channel}}\",\"message\":\"This is a sample message sent to a channel\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send text messages using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"{{channel}}\",\"message\":\"This is a sample message sent to a channel\"}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

# Send scheduled text messages using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"{{channel}}\",\"message\":\"This is a sample message sent to a channel\",\"deliverAt\":\"2024-10-08T16:51:52.830Z\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send scheduled text messages using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"{{channel}}\",\"message\":\"This is a sample message sent to a channel\",\"deliverAt\":\"2024-10-08T16:51:52.830Z\"}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

# Send an image to channels using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"$channel_ID@newsletter\",\"message\":\"This is a caption for an image message\",\"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\",\"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send an image to channels using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"$channel_ID@newsletter\",\"message\":\"This is a caption for an image message\",\"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\",\"viewOnce\":false}}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

# Send a video to channels using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"$channel_ID@newsletter\",\"message\":\"This is a caption for a video message\",\"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\",\"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send a video to channels using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"$channel_ID@newsletter\",\"message\":\"This is a caption for a video message\",\"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\",\"viewOnce\":false}}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

# Send a polls using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"$channel_ID@newsletter\",\"poll\":{\"name\":\"Vote for your favorite color\",\"options\":[\"Red\",\"Green\",\"Blue\",\"Yellow\",\"Grey\",\"Black\",\"Orange\",\"Purple\",\"White\"]}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send a poll using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"$channel_ID@newsletter\",\"poll\":{\"name\":\"Vote for your favorite color\",\"options\":[\"Red\",\"Green\",\"Blue\",\"Yellow\",\"Grey\",\"Black\",\"Orange\",\"Purple\",\"White\"]}}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

# Send a scheduled poll using C# (RestClient)

// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "ENTER API KEY HERE");
request.AddParameter("application/json", "{\"channel\":\"$channel_ID@newsletter\",\"deliverAt\":\"2024-10-23T13:26:35.176Z\",\"poll\":{\"name\":\"Vote for your favorite color\",\"options\":[\"Red\",\"Green\",\"Blue\",\"Yellow\",\"Grey\",\"Black\",\"Orange\",\"Purple\",\"White\"]}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

# Send a scheduled poll using C# (HttpClient)

// This code uses the built-in HttpClient package in the .NET framework.
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.wassenger.com/v1/messages"),
Headers =
{
{ "Token", "ENTER API KEY HERE" },
},
Content = new StringContent("{\"channel\":\"$channel_ID@newsletter\",\"deliverAt\":\"2024-10-23T13:26:35.176Z\",\"poll\":{\"name\":\"Vote for your favorite color\",\"options\":[\"Red\",\"Green\",\"Blue\",\"Yellow\",\"Grey\",\"Black\",\"Orange\",\"Purple\",\"White\"]}}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}

Live API testing

You can live-test and play with the API directly from your browser.

Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.

Try our API-Live tester now

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes!

FAQs

How do I send messages to multiple channels?

You have to send multiple API requests, one per target channel.

For instance, if you want to send a message to 10 channels, you should send 10 independent HTTPS requests to the API.

There is no option to send multiple messages in a single API request.

What type of messages can be sent?

You can only send different types of text and image messages for channels.

Check out other tutorials for more information.

Looking for more answers? Check out the extended FAQs.

Further useful resources

API Documentation

For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages.

https://app.wassenger.com/docs/#operation/createMessage

--

--

Wassenger
Wassenger

Written by Wassenger

WhatsApp API + Team Chat + CRM + AI Assistant Solution for smart Businesses and Teams. Automate and work more productively with your clients on WhatsApp!

No responses yet