WAservix · C# / .NET

WAservix C# / .NET integration

Connect WAservix to your C# / .NET app: send WhatsApp messages from your own WhatsApp number, check delivery and receive replies by webhook. Copy the examples, add your key and run.

Requirements

.NET 6+ (the raw string literals need C# 11 / .NET 7+).

Add your API key

Create a key under WAservix → Devices → API key (it starts with wpk_). Keep it on your server, in an environment variable or secret store. Never put it in a website, a mobile app or a public repository.

// appsettings.json is fine for the URL; keep the key and secret in environment variables or user-secrets
// WASERVIX_KEY=wpk_your_key
// Waservix__WebhookSecret=your_webhook_secret

Set up the client

Base URL https://tekservix.com/waservix/api. Send the key as Authorization: Bearer wpk_….

using System.Text;

var http = new HttpClient { BaseAddress = new Uri("https://tekservix.com/waservix/api/"), Timeout = TimeSpan.FromSeconds(30) };
http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("WASERVIX_KEY"));

Send a WhatsApp message

Messages are queued and sent one at a time per number, so the answer comes back at once with "status": "in_progress" and a msgId.

var json = """
        {"to": "+250788123456", "text": "Hello Aline, your order is ready"}
        """;
using var content = new StringContent(json, Encoding.UTF8, "application/json");
var res = await http.PostAsync("send-message", content);
var text = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode) throw new HttpRequestException(text);
Console.WriteLine(text);

Send a document or image

Use imageUrl, videoUrl, audioUrl or documentUrl with a public https link. Groups work too: put the group JID (…@g.us) in to.

var json = """
        {"to": "+250788123456", "text": "Your invoice", "documentUrl": "https://example.com/inv-1042.pdf", "fileName": "Invoice-1042.pdf"}
        """;
using var content = new StringContent(json, Encoding.UTF8, "application/json");
var res = await http.PostAsync("send-message", content);
var text = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode) throw new HttpRequestException(text);
Console.WriteLine(text);

Check message status

status is queued, sent, delivered, read, played or failed. Webhooks tell you without polling.

var res = await http.GetAsync("messages/58213/info");
var text = await res.Content.ReadAsStringAsync();
if (!res.IsSuccessStatusCode) throw new HttpRequestException(text);
Console.WriteLine(text);

Receive WhatsApp messages by webhook

Set a webhook URL and events for the number under WAservix → Devices. Each request carries X-Webhook-Signature, which equals that device’s webhook secret. Compare it in constant time, answer 2xx quickly and process the message after answering (we retry 3 times).

// Program.cs (ASP.NET Core minimal API)
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;

var app = WebApplication.CreateBuilder(args).Build();

app.MapPost("/webhooks/wapenda", async (HttpRequest req) =>
{
    var raw = await new StreamReader(req.Body).ReadToEndAsync();
    var secret = app.Configuration["Waservix:WebhookSecret"]!;
    var got = req.Headers["X-Webhook-Signature"].ToString();
    if (!CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(secret), Encoding.UTF8.GetBytes(got)))
        return Results.Unauthorized();
    using var doc = JsonDocument.Parse(raw);
    var e = doc.RootElement;
    if (e.GetProperty("event").GetString() == "messages.received")
    {
        var m = e.GetProperty("data").GetProperty("messages");
        Console.WriteLine($"{m.GetProperty("key").GetProperty("cleanedSenderPn")}: {m.GetProperty("messageBody")}");
    }
    return Results.Ok();
});

app.Run();

Errors, limits and retries

Every answer has success; errors add a readable message. 401 means a wrong key, 402 no active plan for this number or phone, 409 the number or phone isn’t connected, 429 too many requests (300 a minute per key): wait for the Retry-After seconds and try again. Retry 5xx and network errors with a back-off, but don’t blindly retry a send that may have worked: check its status first, or you could send twice.

Full list of endpoints and fields: WAservix API reference.

Questions

Is this the official WhatsApp Business API?

No. WAservix links your own number as a companion device, like WhatsApp Web, so there is no Meta approval. Only message people who expect to hear from you: WhatsApp can ban numbers that spam.

Can I call the API from a mobile app or browser?

Don’t. Anyone could read the key from the app or page. Call the API from your server and let your app talk to your server.

Other languages