An open API service indexing awesome lists of open source software.

https://github.com/soenneker/soenneker.blazor.chatwoot

A Blazor interop library for Chatwoot, the open-source customer engagement suite.
https://github.com/soenneker/soenneker.blazor.chatwoot

blazor blazorlibrary chat chatwoot chatwootinterop csharp customer dotnet engagement interop live

Last synced: about 1 month ago
JSON representation

A Blazor interop library for Chatwoot, the open-source customer engagement suite.

Awesome Lists containing this project

README

        

๏ปฟ[![](https://img.shields.io/nuget/v/soenneker.blazor.chatwoot.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.chatwoot/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.blazor.chatwoot/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.blazor.chatwoot/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.blazor.chatwoot.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.chatwoot/)

# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Blazor.Chatwoot

### A Blazor interop library for [Chatwoot](https://www.chatwoot.com/), the open-source customer engagement suite.

---

## โœจ Features

- ๐Ÿ“ฆ Lightweight Blazor component wrapper for the Chatwoot JS SDK
- ๐Ÿ”„ Full .NET interop with JavaScript events
- ๐Ÿ“ก Supports event callbacks like `OnOpen`, `OnMessage`, and `OnError`
- โš™๏ธ Clean integration using dependency injection
- ๐Ÿงช Supports unit testing with `IChatwoot` abstraction

---

## ๐Ÿ“ฆ Installation

```bash
dotnet add package Soenneker.Blazor.Chatwoot
```

Register the interop in DI:

```csharp
public static async Task Main(string[] args)
{
builder.Services.AddChatwootInteropAsScoped();
}
```

---

## ๐Ÿš€ Usage

### ๐Ÿงฉ Add to a Razor component

```razor

```

### ๐Ÿง  Component code-behind

```csharp
@code {
private readonly ChatwootConfiguration _config = new()
{
WebsiteToken = "replace-with-your-token",
BaseUrl = "https://app.chatwoot.com"
};

private Task HandleReady() => ConsoleLog("Chatwoot is ready!");
private Task HandleOpen() => ConsoleLog("Chat opened");
private Task HandleClose() => ConsoleLog("Chat closed");

private Task HandleMessage(ChatwootMessage message)
{
Console.WriteLine($"Message from Chatwoot: {message.Content}");
return Task.CompletedTask;
}

private Task HandleError(JsonElement error)
{
Console.WriteLine($"Chatwoot error: {error}");
return Task.CompletedTask;
}

private Task ConsoleLog(string msg)
{
Console.WriteLine(msg);
return Task.CompletedTask;
}
}
```

---

## โš™๏ธ Configuration

You must supply a `ChatwootConfiguration` object to the component:

```csharp
var config = new ChatwootConfiguration
{
WebsiteToken = "your-token", // Required
BaseUrl = "https://app.chatwoot.com", // Optional, defaults to this
Locale = "en", // Optional, default is "en"
HideMessageBubble = false,
ShowUnreadMessagesDialog = false,
Position = "right", // "left" or "right"
UseBrowserLanguage = false,
Type = "standard", // or "expanded_bubble"
DarkMode = "auto", // "light" or "auto"
BaseDomain = null // Optional, for cross-subdomain tracking
};
```

## ๐Ÿ“š API

This library provides a full interface via `IChatwoot`, including:

- `SetUser(...)`
- `SetLabel(...)`
- `Shutdown()`
- `Toggle()`
- `SetLocale(...)`
- `SetCustomAttributes(...)`
- ... and more!

---

## ๐Ÿ’ฌ Chatwoot Events

The following Chatwoot events are exposed as Blazor `EventCallback`s:

| Chatwoot Event | .NET Callback |
|----------------------|--------------------------|
| `chatwoot:ready` | `OnReady` |
| `chatwoot:open` | `OnOpen` |
| `chatwoot:close` | `OnClose` |
| `chatwoot:on-message`| `OnMessage(ChatwootMessage)` |
| `chatwoot:error` | `OnError(JsonElement)` |