{"id":814,"date":"2026-10-29T13:33:13","date_gmt":"2026-10-29T13:33:13","guid":{"rendered":"https:\/\/vectalk.com.br\/blog\/whatsapp-cloud-api-csharp-dotnet\/"},"modified":"2026-10-29T13:33:16","modified_gmt":"2026-10-29T13:33:16","slug":"whatsapp-cloud-api-csharp-dotnet","status":"publish","type":"post","link":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/","title":{"rendered":"WhatsApp Cloud API with C"},"content":{"rendered":"\n<p><em>Updated on October 29, 2026<\/em><\/p>\n\n\n\n<p>To use the WhatsApp API with C#, you need an <code>HttpClient<\/code> that calls <code>POST \/&lt;PHONE_NUMBER_ID&gt;\/messages<\/code> on the Cloud API and a webhook endpoint that answers Meta&#8217;s verification challenge, validates the <code>X-Hub-Signature-256<\/code> signature and returns <code>200<\/code> before doing any processing. In ASP.NET Core, all of that fits in a minimal API with a <code>Channel&lt;T&gt;<\/code> queue and a <code>BackgroundService<\/code> that consumes the events, with no WhatsApp package at all.<\/p>\n\n\n\n<p>This tutorial builds the project from scratch in five files: sending text, template messages and buttons, a complete webhook, background processing and testing with <code>curl<\/code>. The code runs directly against Meta or through Vectalk by changing two environment variables. The same bot is also available in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-bot-python-fastapi\/\">Python<\/a>, <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-bot-nodejs-express\/\">Node.js<\/a> and <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-java-spring-boot\/\">Java with Spring Boot<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bot architecture<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A customer sends a message to your number.<\/li>\n\n\n<li>Meta sends a <code>POST<\/code> with the event to your webhook.<\/li>\n\n\n<li>The endpoint reads the raw body, validates the HMAC, writes the event to a <code>Channel&lt;byte[]&gt;<\/code> and returns <code>200<\/code>.<\/li>\n\n\n<li>A <code>BackgroundService<\/code> reads the queue, decides on the reply and calls the Cloud API.<\/li>\n\n<\/ol>\n\n\n\n<p>Separating receiving from processing is what keeps the webhook fast. Meta retries events that don&#8217;t get a <code>200<\/code>, immediately and then with decreasing frequency for up to 7 days, so a slow endpoint produces duplicates. To understand the platform before diving into code, see the guide to the <a href=\"https:\/\/vectalk.com.br\/blog\/en\/official-whatsapp-api\/\">official WhatsApp API<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Variable<\/th><th>What it is<\/th><th>Where to find it<\/th><\/tr><\/thead><tbody><tr><td><code>PHONE_NUMBER_ID<\/code><\/td><td>The number&#8217;s ID in the Cloud API<\/td><td>App Dashboard, WhatsApp section<\/td><\/tr><tr><td><code>ACCESS_TOKEN<\/code><\/td><td>Token with the <code>whatsapp_business_messaging<\/code> permission<\/td><td><a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-permanent-access-token\/\">Permanent system user token<\/a><\/td><\/tr><tr><td><code>APP_SECRET<\/code><\/td><td>The app secret, used for the signature<\/td><td>App settings &gt; Basic<\/td><\/tr><tr><td><code>VERIFY_TOKEN<\/code><\/td><td>A string of your choice<\/td><td>You define it and repeat it in the dashboard<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>On your machine: .NET 8 SDK or later. The code uses primary constructors, from C# 12.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">dotnet new web -n WhatsAppBot\ncd WhatsAppBot<\/code><\/pre>\n\n\n\n<p>The <code>web<\/code> template creates an empty ASP.NET Core project with a <code>Program.cs<\/code>. No extra NuGet package is needed: <code>System.Text.Json<\/code>, <code>System.Threading.Channels<\/code> and <code>IHttpClientFactory<\/code> ship with the framework.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Program.cs: webhook and dependency injection<\/h2>\n\n\n\n<p>Replace the contents of <code>Program.cs<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-csharp\">using System.Net.Http.Headers;\nusing System.Threading.Channels;\n\nvar builder = WebApplication.CreateBuilder(args);\nvar cfg = builder.Configuration;\nvar verifyToken = cfg[\"VERIFY_TOKEN\"] ?? throw new InvalidOperationException(\"VERIFY_TOKEN\");\nvar appSecret = cfg[\"APP_SECRET\"] ?? \"\";\nvar webhookKey = cfg[\"WEBHOOK_KEY\"] ?? \"\";\n\nbuilder.Services.AddSingleton(Channel.CreateBounded&lt;byte[]&gt;(\n    new BoundedChannelOptions(1000) { SingleReader = true }));\nbuilder.Services.AddHttpClient(\"whatsapp\", c =&gt;\n    c.DefaultRequestHeaders.Authorization =\n        new AuthenticationHeaderValue(\"Bearer\", cfg[\"ACCESS_TOKEN\"]));\nbuilder.Services.AddSingleton&lt;WhatsAppClient&gt;();\nbuilder.Services.AddHostedService&lt;WebhookWorker&gt;();\n\nvar app = builder.Build();\n\napp.MapGet(\"\/webhook\", (HttpRequest req) =&gt;\n{\n    var q = req.Query;\n    return q[\"hub.mode\"] == \"subscribe\" &amp;&amp; q[\"hub.verify_token\"] == verifyToken\n        ? Results.Text(q[\"hub.challenge\"].ToString())\n        : Results.StatusCode(403);\n});\n\napp.MapPost(\"\/webhook\", async (HttpRequest req, Channel&lt;byte[]&gt; queue) =&gt;\n{\n    if (webhookKey != \"\" &amp;&amp; req.Query[\"key\"] != webhookKey)\n        return Results.StatusCode(403);\n\n    using var ms = new MemoryStream();\n    await req.Body.CopyToAsync(ms);\n    var body = ms.ToArray();\n\n    if (!Signature.IsValid(appSecret, body, req.Headers[\"X-Hub-Signature-256\"]))\n        return Results.Unauthorized();\n\n    \/\/ Queue full: return 503 and Meta will retry later\n    return queue.Writer.TryWrite(body) ? Results.Ok() : Results.StatusCode(503);\n});\n\napp.Run();<\/code><\/pre>\n\n\n\n<p>What each part does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>GET \/webhook<\/code><\/strong> handles verification. When you save the URL in the dashboard, Meta sends <code>hub.mode=subscribe<\/code>, <code>hub.verify_token<\/code> and <code>hub.challenge<\/code>. If the token matches, the response is <code>200<\/code> with <code>hub.challenge<\/code> as plain text, which is exactly what <code>Results.Text<\/code> produces. Any other response leaves the webhook unverified.<\/li>\n\n\n<li><strong><code>POST \/webhook<\/code><\/strong> reads the body as bytes, validates the signature and enqueues it. There is no deserialization here: the JSON is only parsed in the worker.<\/li>\n\n\n<li><strong><code>Channel.CreateBounded<\/code><\/strong> caps the queue at 1,000 events. With <code>TryWrite<\/code>, a spike beyond that returns <code>503<\/code> instead of blowing up the process&#8217;s memory, and Meta retries later.<\/li>\n\n\n<li><strong><code>AddHttpClient(\"whatsapp\")<\/code><\/strong> registers a named client in <code>IHttpClientFactory<\/code>, which manages the connection lifecycle. Creating <code>new HttpClient()<\/code> on every send exhausts sockets under load.<\/li>\n\n<\/ul>\n\n\n\n<p><code>WEBHOOK_KEY<\/code> is optional and is meant for the Vectalk scenario, explained further down.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Signature.cs: validating X-Hub-Signature-256<\/h2>\n\n\n\n<p>Every <code>POST<\/code> from Meta carries the header <code>X-Hub-Signature-256: sha256=&lt;hash&gt;<\/code>, where the hash is an HMAC-SHA256 of the raw body computed with the app secret. Create <code>Signature.cs<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-csharp\">using System.Security.Cryptography;\nusing System.Text;\n\nstatic class Signature\n{\n    public static bool IsValid(string secret, byte[] body, string? header)\n    {\n        if (secret.Length == 0) return true; \/\/ no secret (e.g. via Vectalk, protected by WEBHOOK_KEY)\n        if (string.IsNullOrEmpty(header) || !header.StartsWith(\"sha256=\")) return false;\n\n        byte[] received;\n        try { received = Convert.FromHexString(header.AsSpan(7)); }\n        catch (FormatException) { return false; }\n\n        var expected = HMACSHA256.HashData(Encoding.UTF8.GetBytes(secret), body);\n        return CryptographicOperations.FixedTimeEquals(expected, received);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Two details matter:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The HMAC is computed over the bytes that arrived<\/strong>, not over an object that was deserialized and serialized again. A single space or a different field order changes the hash. That&#8217;s why the endpoint copies <code>req.Body<\/code> into a <code>MemoryStream<\/code> instead of binding a type as a parameter.<\/li>\n\n\n<li><strong><code>CryptographicOperations.FixedTimeEquals<\/code><\/strong> compares in constant time, so the response time doesn&#8217;t reveal how many bytes matched. Comparing strings with <code>==<\/code> works, but it&#8217;s the wrong choice here.<\/li>\n\n<\/ul>\n\n\n\n<p>The article on <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-signature-validation\/\">how to validate the webhook signature<\/a> lists the most common mistakes, such as proxies that modify the body.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. WhatsAppClient.cs: sending with HttpClient<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-csharp\">using System.Net.Http.Json;\n\npublic class WhatsAppClient(IHttpClientFactory factory, IConfiguration cfg, ILogger&lt;WhatsAppClient&gt; log)\n{\n    private readonly string _url = cfg[\"API_URL\"]\n        ?? $\"https:\/\/graph.facebook.com\/v26.0\/{cfg[\"PHONE_NUMBER_ID\"]}\/messages\";\n\n    public async Task&lt;string&gt; SendAsync(IDictionary&lt;string, string&gt; dest, string type, object content,\n                                        CancellationToken ct = default)\n    {\n        var payload = dest.ToDictionary(d =&gt; d.Key, d =&gt; (object)d.Value);\n        payload[\"messaging_product\"] = \"whatsapp\";\n        payload[\"type\"] = type;\n        payload[type] = content;\n\n        var http = factory.CreateClient(\"whatsapp\");\n        using var res = await http.PostAsJsonAsync(_url, payload, ct);\n        var body = await res.Content.ReadAsStringAsync(ct);\n        if (!res.IsSuccessStatusCode)\n        {\n            log.LogError(\"API {Status}: {Body}\", (int)res.StatusCode, body);\n            res.EnsureSuccessStatusCode();\n        }\n        return body;\n    }\n\n    public Task&lt;string&gt; SendTextAsync(IDictionary&lt;string, string&gt; dest, string text, CancellationToken ct = default) =&gt;\n        SendAsync(dest, \"text\", new { body = text }, ct);\n\n    public Task&lt;string&gt; SendTemplateAsync(string to, string name, string lang, string[] values,\n                                          CancellationToken ct = default) =&gt;\n        SendAsync(new Dictionary&lt;string, string&gt; { [\"to\"] = to }, \"template\", new\n        {\n            name,\n            language = new { code = lang },\n            components = new[]\n            {\n                new { type = \"body\", parameters = values.Select(v =&gt; new { type = \"text\", text = v }).ToArray() }\n            }\n        }, ct);\n\n    public Task&lt;string&gt; SendButtonsAsync(IDictionary&lt;string, string&gt; dest, string text,\n                                         (string Id, string Title)[] buttons, CancellationToken ct = default) =&gt;\n        SendAsync(dest, \"interactive\", new\n        {\n            type = \"button\",\n            body = new { text },\n            action = new\n            {\n                buttons = buttons.Select(b =&gt; new { type = \"reply\", reply = new { id = b.Id, title = b.Title } })\n            }\n        }, ct);\n}<\/code><\/pre>\n\n\n\n<p>Notes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Anonymous types become Meta&#8217;s exact JSON.<\/strong> <code>PostAsJsonAsync<\/code> uses <code>System.Text.Json<\/code> with the Web defaults, which camelCase property names and leave dictionary keys untouched. Since the fields are already lowercase in the code and <code>messaging_product<\/code> is a dictionary key, the payload comes out in the expected format with no extra configuration.<\/li>\n\n\n<li><strong>The error body goes to the log.<\/strong> Meta returns an <code>error<\/code> object with <code>code<\/code> and <code>error_data.details<\/code>. That text is what solves most problems; the table of <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-error-codes\/\">WhatsApp API error codes<\/a> helps you interpret it.<\/li>\n\n\n<li><strong>Template messages require the exact number of parameters.<\/strong> If <code>values<\/code> has one item more or less than the approved template, the response is error 132000, explained in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-error-132000-template-parameters\/\">errors 132000 and 132012<\/a>.<\/li>\n\n\n<li><strong><code>dest<\/code> is a dictionary<\/strong> because the recipient can be <code>to<\/code> (phone number) or <code>recipient<\/code> (BSUID), when the customer uses a username. See <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-usernames-bsuid\/\">WhatsApp usernames and BSUID<\/a>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. WebhookModels.cs: the typed payload<\/h2>\n\n\n\n<p>Records with only the fields the bot uses:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-csharp\">using System.Text.Json.Serialization;\n\npublic record WebhookPayload(List&lt;Entry&gt;? Entry);\npublic record Entry(List&lt;Change&gt;? Changes);\npublic record Change(string? Field, ChangeValue? Value);\npublic record ChangeValue(List&lt;Message&gt;? Messages);\npublic record Message(\n    string? From,\n    [property: JsonPropertyName(\"from_user_id\")] string? FromUserId,\n    string Id,\n    string Type,\n    TextBody? Text,\n    Interactive? Interactive);\npublic record TextBody(string Body);\npublic record Interactive(string Type, [property: JsonPropertyName(\"button_reply\")] Reply? ButtonReply);\npublic record Reply(string Id, string Title);<\/code><\/pre>\n\n\n\n<p>Deserialization uses <code>JsonSerializerDefaults.Web<\/code>, which matches names case-insensitively. So <code>from<\/code> maps to <code>From<\/code> and <code>changes<\/code> to <code>Changes<\/code>. Fields with underscores need <code>JsonPropertyName<\/code>. Unknown fields are ignored by default.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. WebhookWorker.cs: the queue consumer<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-csharp\">using System.Text.Json;\nusing System.Threading.Channels;\n\npublic class WebhookWorker(Channel&lt;byte[]&gt; queue, WhatsAppClient wa, ILogger&lt;WebhookWorker&gt; log)\n    : BackgroundService\n{\n    private static readonly JsonSerializerOptions Json = new(JsonSerializerDefaults.Web);\n    private readonly HashSet&lt;string&gt; _processed = []; \/\/ in production: Redis or a database, with expiration\n\n    private static readonly Dictionary&lt;string, string&gt; Answers = new()\n    {\n        [\"horario\"] = \"We're open Monday to Friday, 9 a.m. to 6 p.m.\",\n        [\"precos\"] = \"See the full price list at https:\/\/example.com\/precos\",\n        [\"humano\"] = \"Sure! An agent will continue the conversation here.\",\n    };\n\n    protected override async Task ExecuteAsync(CancellationToken stop)\n    {\n        await foreach (var body in queue.Reader.ReadAllAsync(stop))\n        {\n            try\n            {\n                var payload = JsonSerializer.Deserialize&lt;WebhookPayload&gt;(body, Json);\n                var messages = (payload?.Entry ?? [])\n                    .SelectMany(e =&gt; e.Changes ?? [])\n                    .SelectMany(c =&gt; c.Value?.Messages ?? []);\n                foreach (var msg in messages)\n                {\n                    if (!_processed.Add(msg.Id)) continue; \/\/ Meta may resend\n                    await HandleAsync(msg, stop);\n                }\n            }\n            catch (Exception e) when (e is not OperationCanceledException)\n            {\n                log.LogError(e, \"failed to process event\");\n            }\n        }\n    }\n\n    private async Task HandleAsync(Message msg, CancellationToken ct)\n    {\n        IDictionary&lt;string, string&gt; dest = msg.From is not null\n            ? new Dictionary&lt;string, string&gt; { [\"to\"] = msg.From }\n            : new Dictionary&lt;string, string&gt; { [\"recipient\"] = msg.FromUserId! };\n\n        switch (msg.Type)\n        {\n            case \"text\":\n                var text = msg.Text!.Body.Trim().ToLowerInvariant();\n                if (text is \"hi\" or \"hello\" or \"menu\")\n                    await wa.SendButtonsAsync(dest, \"Hi! How can I help?\",\n                        [(\"horario\", \"Business hours\"), (\"precos\", \"Pricing\"), (\"humano\", \"Talk to an agent\")], ct);\n                else\n                    await wa.SendTextAsync(dest, \"Sorry, I didn't get that. Type *menu* to see the options.\", ct);\n                break;\n\n            case \"interactive\" when msg.Interactive?.Type == \"button_reply\":\n                var choice = msg.Interactive!.ButtonReply!.Id;\n                await wa.SendTextAsync(dest, Answers.GetValueOrDefault(choice, \"Invalid option.\"), ct);\n                break;\n\n            default:\n                await wa.SendTextAsync(dest, \"For now I only understand text and buttons.\", ct);\n                break;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>The parentheses in <code>(payload?.Entry ?? [])<\/code> make <code>SelectMany<\/code> run over the <code>entry<\/code> list or, if it isn&#8217;t in the payload, over an empty list.<\/p>\n\n\n\n<p>About the worker:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>A single reader.<\/strong> The <code>Channel<\/code> was created with <code>SingleReader = true<\/code>, and <code>HashSet<\/code> isn&#8217;t thread-safe; with only one consumer, the two fit together. If you need parallelism, switch to <code>ConcurrentDictionary<\/code> and run multiple readers.<\/li>\n\n\n<li><strong>Delivery statuses<\/strong> (<code>sent<\/code>, <code>delivered<\/code>, <code>read<\/code>, <code>failed<\/code>) arrive on the same webhook, under <code>value.statuses<\/code>, and are ignored here. To handle them, see <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-message-status-webhook\/\">message status via webhook<\/a>.<\/li>\n\n\n<li><strong>Button limits:<\/strong> up to 3 per message, <code>title<\/code> up to 20 characters, <code>id<\/code> up to 256.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. Run and test<\/h2>\n\n\n\n<p>ASP.NET Core reads environment variables into configuration by default, so <code>cfg[\"VERIFY_TOKEN\"]<\/code> finds the exported variable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">export VERIFY_TOKEN=\"any-text-you-like\"\nexport ACCESS_TOKEN=\"EAAG...\"\nexport APP_SECRET=\"your-app-secret\"\nexport PHONE_NUMBER_ID=\"123456789012345\"\ndotnet run --urls http:\/\/localhost:5000<\/code><\/pre>\n\n\n\n<p>Test the verification and a signed event:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">curl \"http:\/\/localhost:5000\/webhook?hub.mode=subscribe&amp;hub.verify_token=any-text-you-like&amp;hub.challenge=42\"\n\nBODY='{\"entry\":[{\"changes\":[{\"value\":{\"messages\":[{\"from\":\"5511999999999\",\"id\":\"wamid.teste1\",\"type\":\"text\",\"text\":{\"body\":\"menu\"}}]}}]}]}'\nSIG=$(printf '%s' \"$BODY\" | openssl dgst -sha256 -hmac \"$APP_SECRET\" | awk '{print $NF}')\ncurl -i -X POST http:\/\/localhost:5000\/webhook \\\n  -H \"Content-Type: application\/json\" \\\n  -H \"X-Hub-Signature-256: sha256=$SIG\" \\\n  --data-binary \"$BODY\"<\/code><\/pre>\n\n\n\n<p>The first command returns <code>42<\/code>. The second returns <code>200<\/code>, and the worker sends the menu to the number in the <code>from<\/code> field (use your own test number). A <code>401<\/code> means the signature is wrong.<\/p>\n\n\n\n<p>For real events, Meta requires a public URL with a valid TLS certificate; self-signed certificates are not accepted. During development, use a tunnel, as shown in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/test-whatsapp-webhook-locally\/\">testing the webhook locally with ngrok<\/a>. Then, in App Dashboard &gt; WhatsApp &gt; Configuration, enter the callback URL and the verify token and subscribe to the <code>messages<\/code> field.<\/p>\n\n\n\n<p>To deploy, the .NET SDK builds a container image without a <code>Dockerfile<\/code>, using <code>dotnet publish -t:PublishContainer<\/code>. Put a reverse proxy with HTTPS in front of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Production checklist<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Durable queue.<\/strong> The <code>Channel<\/code> lives in memory: if the process goes down, queued events are lost, and Meta does not resend anything that already got a <code>200<\/code>. For high volume or slow processing, write the event to an external queue (Azure Service Bus, RabbitMQ, SQS) before responding. To run the webhook on functions, see <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-aws-lambda-serverless\/\">serverless webhook<\/a>.<\/li>\n\n\n<li><strong>Shared deduplication.<\/strong> With more than one instance, each instance&#8217;s <code>HashSet<\/code> can&#8217;t see the others. Use Redis or a table with a unique key.<\/li>\n\n\n<li><strong>Send throughput.<\/strong> The Cloud API has a messages-per-second limit per number; see <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-rate-limit-throughput\/\">throughput and rate limits<\/a>.<\/li>\n\n\n<li><strong>Secrets.<\/strong> In production, use a vault (Azure Key Vault, AWS Secrets Manager) or orchestrator variables, never a version-controlled <code>appsettings.json<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to do it with Vectalk<\/h2>\n\n\n\n<p>Vectalk is a proxy for the official WhatsApp Cloud API: payloads and webhook events are the same as Meta&#8217;s, so the project works with no change in logic. Three adjustments:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>URL and token.<\/strong> Set <code>API_URL=https:\/\/apis.vectalk.com.br\/api\/messages<\/code> and use a Vectalk instance token in <code>ACCESS_TOKEN<\/code>. With it, the <code>phone_number_id<\/code> is resolved automatically.<\/li>\n\n\n<li><strong>Webhook registered via API.<\/strong> Register the URL with <code>POST https:\/\/apis.vectalk.com.br\/api\/webhooks<\/code>, passing <code>instance_id<\/code>, <code>url<\/code> and <code>name<\/code>. Each instance accepts multiple URLs.<\/li>\n\n\n<li><strong>Endpoint protection.<\/strong> The <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk webhooks documentation<\/a> does not describe a signature header. Leave <code>APP_SECRET<\/code> empty, set <code>WEBHOOK_KEY<\/code> to a long random value and register the URL with <code>?key=YOUR_VALUE<\/code>.<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">curl -X POST https:\/\/apis.vectalk.com.br\/api\/webhooks \\\n  -H \"Authorization: Bearer YOUR_VECTALK_TOKEN\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\"instance_id\": \"YOUR_INSTANCE\", \"url\": \"https:\/\/bot.yourcompany.com\/webhook?key=YOUR_VALUE\", \"name\": \"Bot .NET\"}'<\/code><\/pre>\n\n\n\n<p>Vectalk expects a <code>200<\/code> within 20 seconds and resends if it doesn&#8217;t get one; deduplication already covers that case. Create your account at <a href=\"https:\/\/apps.vectalk.com.br\/register\">apps.vectalk.com.br\/register<\/a> and check the <a href=\"https:\/\/docs.vectalk.com.br\">documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Is there an official Meta SDK for C#?<\/h3>\n\n\n\n<p>You don&#8217;t need one. The Cloud API is HTTP with JSON, and <code>HttpClient<\/code> with <code>System.Text.Json<\/code> covers both sending and receiving. Calling the API directly lets you use new features as soon as Meta documents them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does it work with controllers instead of a minimal API?<\/h3>\n\n\n\n<p>Yes. The point to watch is the same: in the <code>POST<\/code>, read <code>Request.Body<\/code> as bytes to validate the signature before deserializing. If the controller takes a typed <code>[FromBody]<\/code> parameter, the original body has already been consumed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I process events directly in the endpoint, without a queue?<\/h3>\n\n\n\n<p>For testing, yes. In production, any slow call (database, AI, another API) delays the <code>200<\/code>, and Meta resends the event. The queue separates the two with very little code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can the bot start the conversation?<\/h3>\n\n\n\n<p>Free-form messages and buttons only work inside the 24-hour window opened by the customer&#8217;s last message. To start or resume a conversation after that, use <code>SendTemplateAsync<\/code> with an approved template message.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Official sources consulted on October 29, 2026:<\/strong> <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Create a webhook endpoint (Meta)<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/overview\" target=\"_blank\" rel=\"noreferrer noopener\">Webhooks overview (Meta)<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/messages\/interactive-reply-buttons-messages\" target=\"_blank\" rel=\"noreferrer noopener\">Interactive reply buttons (Meta)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/fundamentals\/minimal-apis\" target=\"_blank\" rel=\"noreferrer noopener\">Minimal APIs (Microsoft)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/fundamentals\/http-requests\" target=\"_blank\" rel=\"noreferrer noopener\">IHttpClientFactory (Microsoft)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/dotnet\/core\/extensions\/channels\" target=\"_blank\" rel=\"noreferrer noopener\">System.Threading.Channels (Microsoft)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/aspnet\/core\/fundamentals\/host\/hosted-services\" target=\"_blank\" rel=\"noreferrer noopener\">Background tasks with hosted services (Microsoft)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/dotnet\/api\/system.security.cryptography.cryptographicoperations.fixedtimeequals\" target=\"_blank\" rel=\"noreferrer noopener\">CryptographicOperations.FixedTimeEquals (Microsoft)<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk: webhooks<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/authentication\">Vectalk: authentication<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WhatsApp API tutorial with C<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-814","post","type-post","status-publish","format-standard","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WhatsApp API in C<\/title>\n<meta name=\"description\" content=\"WhatsApp API C\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WhatsApp API in C\" \/>\n<meta property=\"og:description\" content=\"WhatsApp API C\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Vectalk\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-29T13:33:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-29T13:33:16+00:00\" \/>\n<meta name=\"author\" content=\"wanderleyfcunha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"wanderleyfcunha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/\"},\"author\":{\"name\":\"wanderleyfcunha\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"headline\":\"WhatsApp Cloud API with C\",\"datePublished\":\"2026-10-29T13:33:13+00:00\",\"dateModified\":\"2026-10-29T13:33:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/\"},\"wordCount\":1388,\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/\",\"name\":\"WhatsApp API in C\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\"},\"datePublished\":\"2026-10-29T13:33:13+00:00\",\"dateModified\":\"2026-10-29T13:33:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"description\":\"WhatsApp API C\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-cloud-api-csharp-dotnet\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WhatsApp Cloud API with C\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\",\"name\":\"Blog Vectalk\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\",\"name\":\"wanderleyfcunha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"caption\":\"wanderleyfcunha\"},\"sameAs\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WhatsApp API in C","description":"WhatsApp API C","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/","og_locale":"en_US","og_type":"article","og_title":"WhatsApp API in C","og_description":"WhatsApp API C","og_url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/","og_site_name":"Blog Vectalk","article_published_time":"2026-10-29T13:33:13+00:00","article_modified_time":"2026-10-29T13:33:16+00:00","author":"wanderleyfcunha","twitter_card":"summary_large_image","twitter_misc":{"Written by":"wanderleyfcunha","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/#article","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/"},"author":{"name":"wanderleyfcunha","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"headline":"WhatsApp Cloud API with C","datePublished":"2026-10-29T13:33:13+00:00","dateModified":"2026-10-29T13:33:16+00:00","mainEntityOfPage":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/"},"wordCount":1388,"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/","url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/","name":"WhatsApp API in C","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/#website"},"datePublished":"2026-10-29T13:33:13+00:00","dateModified":"2026-10-29T13:33:16+00:00","author":{"@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"description":"WhatsApp API C","breadcrumb":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-cloud-api-csharp-dotnet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vectalk.com.br\/blog\/"},{"@type":"ListItem","position":2,"name":"WhatsApp Cloud API with C"}]},{"@type":"WebSite","@id":"https:\/\/vectalk.com.br\/blog\/#website","url":"https:\/\/vectalk.com.br\/blog\/","name":"Blog Vectalk","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vectalk.com.br\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b","name":"wanderleyfcunha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","caption":"wanderleyfcunha"},"sameAs":["https:\/\/vectalk.com.br\/blog"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/comments?post=814"}],"version-history":[{"count":1,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":817,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions\/817"}],"wp:attachment":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/media?parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/categories?post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/tags?post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}