Waha-net/waha-net: .NET C# Client Library for WhatsApp HTTP API (WAHA)

Waha-net/waha-net: .NET C# Client Library for WhatsApp HTTP API (WAHA)

Summary

Waha-net/waha-net is a .NET C# client library designed to simplify interaction with the WAHA (WhatsApp HTTP API). It enables developers to easily integrate WhatsApp services into their .NET applications, providing a streamlined way to manage chats and sessions.

Repository Info

Updated on October 12, 2025
View on GitHub

Tags

Click on any tag to explore related repositories

Introduction

Waha-net/waha-net is a .NET C# client library designed to simplify interaction with the WAHA (WhatsApp HTTP API). This library enables .NET developers to easily integrate WhatsApp services into their applications, providing an efficient way to manage chats and sessions. With Waha-net, you can build robust applications that communicate with WhatsApp through an HTTP API.

Installation

To start using the Waha-net library in your .NET project, you can install it via NuGet.

Run the following command in your .NET project:

dotnet add package Waha

Alternatively, you can use the NuGet Package Manager in Visual Studio to add the reference to the Waha package.

Examples

This section demonstrates how to integrate Waha-net into your .NET projects. Before using the library, it's essential to have an instance of WAHA (WhatsApp HTTP API) running.

Setting up WAHA Docker Container

First, ensure you have WAHA (WhatsApp HTTP API) running. Follow these steps to set it up as a Docker container:

Prerequisite: Ensure Docker is installed on your system.

docker pull devlikeapro/waha

Run the container:

docker run -it --rm -p 3000:3000/tcp --name waha devlikeapro/waha

After starting, WAHA will be accessible at http://localhost:3000/, where you can find the API documentation (Swagger).

ASP.NET Core Integration

Here's a sample code snippet for an ASP.NET Core application that lists WhatsApp chats from the logged-in user:

using Waha;
using Microsoft.AspNetCore.Mvc; // Added for [FromHeader]

var builder = WebApplication.CreateBuilder(args);

// This method will look for "Waha" settings configuration section or connectionstring in your appsettings.json
// It also will use Waha default endpoint value ("localhost:3000") if can´t find a valid configuration
builder.AddWahaApiClient("Waha");

var app = builder.Build();
app.MapDefaultEndpoints();

app.MapGet("/chats", async (
  IWahaApiClient wahaApiClient, CancellationToken cancellationToken,
  [FromHeader] int limit = 5, [FromHeader] int offset = 0, [FromHeader] string sortBy = "", [FromHeader] string sortOrder = "") =>
{
  var sessions = await wahaApiClient.GetSessionsAsync(true, cancellationToken);
  var session = sessions.FirstOrDefault();
  if (session == null)
  {
      return Results.Json(new { Message = "No active session found." }, statusCode: StatusCodes.Status412PreconditionFailed);
  }
  var chats = await wahaApiClient.GetChatsAsync(session.Name, limit, offset, sortBy, sortOrder, cancellationToken);
  return Results.Ok(chats);
}).WithName("GetChats");

app.Run(); // Added app.Run() to make it a runnable example

For Other .NET Applications

For .NET applications that are not ASP.NET Core, you can initialize the client as follows:

using Waha;
using System.Net.Http; // Added for HttpClient
using System.Threading; // Added for CancellationToken
using System.Linq; // Added for FirstOrDefault

var wahaApiClient = new WahaApiClient(new HttpClient() { BaseAddress = WahaSettings.Default.Endpoint });
var sessions = await wahaApiClient.GetSessionsAsync(true, CancellationToken.None); // Use CancellationToken.None for simplicity
var session = sessions.FirstOrDefault();
if (session != null)
{
    var chats = await wahaApiClient.GetChatsAsync(session.Name, 10, 0, "", "", CancellationToken.None); // Use CancellationToken.None
    // Process the chats as needed...
}

Why Use Waha-net?

Waha-net significantly simplifies integration with the WhatsApp HTTP API (WAHA) in your .NET projects. By abstracting the complexities of API calls, it allows developers to focus on their application's business logic. The library is written in C#, leveraging the robust .NET ecosystem, and is open-source, encouraging community contributions and feedback. It's a powerful solution for any application needing to interact with WhatsApp programmatically.

Links