Add in-app support to a .NET app

Give your Windows .NET app (WinForms, WPF) a "Get help" button that shares your app's window with your support team, with consent, in your own name, colour and logo.

Embed
Preview of the card
<a href="https://gaiadesk.net/docs/dotnet-in-app-support"><img src="https://gaiadesk.net/docs/_api/public/orgs/89a5df38-be2c-4963-8823-21d4bd40a2ab/spaces/57b99ea0-d45a-4986-8aa6-6b0683c9fe1d/pages/44c851ce-f86d-4677-acf2-deee7fdb23a2/social-card.svg?v=3e7ae33eec8b" alt="Add in-app support to a .NET app" width="600" height="315"></a>

Give your Windows desktop app a "Get help" button: your customer clicks it and agrees, and your support team sees your app's window in the GaiaDesk console — and, if you allow it, guides it — without the customer installing anything.

GaiaDesk's .NET SDK, GaiaDesk.Embed 0.4.0, works with .NET 8 apps on Windows x64: WinForms, WPF, or anything else with a window handle. Its source is open (MIT), at github.com/Gaia-Desk/gaiadesk-embed-dotnet. It wraps the same signed native library, libgaiadesk_embed, as GaiaDesk's other embed SDKs; the library is a prebuilt binary that ships, unmodified, beside your app. For how the SDKs fit together, see in-app support.

What your customer sees

  • One button. Your app shows "Get help" wherever you put it.

  • A consent dialog in your colours. It names your company, says what will be shared (this app's window, or the screen if you chose it) and whether your team will be able to guide it. Nothing is shared until the customer agrees. It is owned by the window that asked, so it never opens behind it. For a live preview, choices, who is waiting and a stored receipt, use the consent step.

  • An indicator for as long as anything is shared. "Sharing with Acme · Stop sharing", drawn by the library on top of your app. Your app cannot hide it. In a guided session it also has Pause control. While the customer waits for an agent it offers Cancel instead, and your customer can drag it anywhere (see The indicator).

  • A support code. Nine digits your customer can read to an agent over the phone.

When the session ends — the customer presses Stop sharing, your app stops it, the session expires, or the app quits — sharing stops at once and nothing is left behind: the library installs nothing, runs no service and writes nothing to disk.

What your support team sees

Agents open Support in the GaiaDesk console, see the waiting customer (with the details your backend passed) and join, or type the support code. Only your own account and team can join, and only team members with a support seat.

1. Install the package

GaiaDesk.Embed is not on nuget.org yet. It ships as a .nupkg on the v0.4.0 GitHub release (GaiaDesk.Embed.0.4.0.nupkg, with its .sha256). Download it into a folder and install it from there:

mkdir packages
curl -L -o packages/GaiaDesk.Embed.0.4.0.nupkg https://github.com/Gaia-Desk/gaiadesk-embed-dotnet/releases/download/v0.4.0/GaiaDesk.Embed.0.4.0.nupkg
dotnet add package GaiaDesk.Embed --version 0.4.0 --source ./packages

To keep the folder as a package source for restores (and for your build server), add it once:

dotnet nuget add source ./packages -n gaiadesk-local

2. The native library

The package carries the library for Windows x64 at runtimes/win-x64/native/gaiadesk_embed.dll. When you build, .NET copies it beside your app; ship it with your app as it is, together with the package's LICENSE-BINARY. There is nothing else to fetch or install.

To load the DLL from somewhere else, set GAIADESK_EMBED_LIB_DIR to the folder that holds it. GaiaDeskEmbed.IsNativeLibraryAvailable tells you whether it can be loaded, and GaiaDeskEmbed.Version which version was.

3. Create sessions from your backend

The .NET SDK starts a session from an embed token, which your backend gets from GaiaDesk. That way your server decides who may get help, and the customer details it passes show as verified in the console.

Create the session with a secret API key (scope support):

curl -s -X POST https://api.gaiadesk.net/v1/support/sessions \
  -H "Authorization: Bearer $GAIADESK_API_KEY" -H "Content-Type: application/json" \
  -d '{"mode": "cobrowse", "customer": {"name": "Ada", "plan": "pro"}}'

The response carries embed_token (gdemb_…). Hand only that to your app. Never ship the secret key in your app: the embed token is all it needs. The full request is in the support API reference.

4. Add the button

A WinForms form with a getHelp button, a statusLabel and a cardPanel to keep private. GetEmbedTokenAsync stands for your own call to your backend.

using GaiaDesk.Embed;

public partial class MainForm : Form
{
    GaiaDeskEmbed? help;

    async void GetHelp_Click(object? sender, EventArgs e)
    {
        if (help is not null) { help.Stop(); return; }   // the button is "Stop sharing" while a session runs

        // The library's own dialog; null means there is none here: ask with yours.
        var agreed = GaiaDeskEmbed.RequestConsent("Acme")
            ?? MessageBox.Show(this, "Share this window with Acme support?", "Acme",
                   MessageBoxButtons.YesNo) == DialogResult.Yes;
        if (!agreed) return;

        string embedToken = await GetEmbedTokenAsync();

        // Painted out from the very first frame.
        var s = cardPanel.RectangleToScreen(cardPanel.ClientRectangle);
        var card = EmbedRect.FromScreenRect(Handle, (s.X, s.Y, s.Width, s.Height));

        try
        {
            help = GaiaDeskEmbed.Start(
                new EmbedOptions { EmbedToken = embedToken, Company = "Acme", WindowId = Handle, Masks = new[] { card } },
                consentGranted: true,
                OnHelpEvent,
                SynchronizationContext.Current);   // events arrive on the UI thread
            getHelp.Text = "Stop sharing";
        }
        catch (GaiaDeskEmbedException ex)
        {
            statusLabel.Text = $"Could not start: {ex.Message} ({ex.Code})";
        }
    }

    void OnHelpEvent(EmbedEvent e)
    {
        switch (e)
        {
            case CodeEvent c: statusLabel.Text = $"Your support code is {c.Code}"; break;
            case JoinedEvent j: statusLabel.Text = $"{j.Agent ?? "An agent"} is viewing this window"; break;
            case EndedEvent: help?.Dispose(); help = null; getHelp.Text = "Get help"; break;
        }
    }
}

That is the whole integration. Start refuses without consent (GaiaDeskEmbedException with Code == "consent_required"), so never pass consentGranted: true without asking. Other refusals have stable codes too: bad_token, bad_config, bad_server, and so on.

EndedEvent is always the last event, exactly once. Its Reason is stopped, app_stopped, customer_cancelled (Cancel, or Stop(), before an agent was admitted), customer_declined / consent_timeout (the consent step said no or timed out), disconnected, expired or error. Stop() (or Dispose()) is safe to call more than once and from an event handler. On waiting, StateEvent.Choices is what the consent step let the session do.

In WPF, the window handle is new WindowInteropHelper(this).Handle, and you pass SynchronizationContext.Current from the UI thread the same way.

Use the library's consent step, GaiaDeskEmbed.Consent(ConsentStepOptions) (package and libgaiadesk_embed 0.4.0), rather than consentGranted: true after a dialog of your own. It gives you, with no UI to build:

  • a live preview of exactly what support will see, masked fields already black;

  • per-session choices for the customer: allow click-and-type or keep it view-only, share app logs, one window or the whole screen (each only when you offer it);

  • who is waiting and for how long, links to your privacy policy and terms, and an optional auto-decline timeout;

  • a consent receipt (who agreed to what, when, to which wording, hashed), stored on the session and shown in the console (see Proof of consent);

  • wording localized into 14 languages (or your own), and an accessible dialog: keyboard only, Enter accepts, Esc declines, screen reader (UI Automation) names, reduced motion.

var consent = GaiaDeskEmbed.Consent(new ConsentStepOptions
{
    Company = "Acme", Guided = true, Masked = true, ParentWindow = Handle, WindowId = Handle, Masks = masks,
    Theme = new ConsentTheme { Accent = "#0f766e", Radius = 12 },
    Choices = new ConsentOffers { OfferGuided = true, OfferLogs = true },
    PrivacyUrl = "https://acme.example/privacy",
    Server = "https://gaiadesk.net", EmbedToken = embedToken, SessionId = sessionId, // the library posts the receipt, shows who is waiting
}, e => Debug.WriteLine(e));                      // ConsentShownEvent, ConsentAcceptedEvent / ConsentDeclinedEvent

switch (consent.Decision)
{
    case ConsentOutcome.Accepted:
        help = GaiaDeskEmbed.Start(options, consent, OnHelpEvent, SynchronizationContext.Current);
        break;
    case ConsentOutcome.Unavailable: // no native dialog here: ask with your own, then RecordConsent
        break;
    default: // Declined, Timeout: the receipt says so; the session leaves the queue
        break;
}

Start(options, consent, …) sends the decision's ConsentToken and ConsentReceipt with the join (also settable as EmbedOptions.ConsentToken / ConsentReceipt) and starts with what the customer chose (their capture; Guided only if they allowed it). Call Consent on your UI thread; refused options throw bad_config and show no dialog, never a decline. A session that ends because of the consent step ends with customer_declined or consent_timeout.

Consent(ConsentStepOptions, onEvent)

the dialog → a ConsentDecision (Accepted, Declined, Timeout, Unavailable; ConsentChoices, ConsentToken, ConsentReceipt). Choices are offered with ConsentOffers, the look with ConsentTheme

Preview(ConsentStepOptions)

the same picture (ConsentPreview: PNG bytes, size, masked count) for a UI of your own

RecordConsent(ConsentAnswer)

your own UI's answer (decision, choices, the strings you showed) → the same ConsentDecision and receipt

Start(EmbedOptions, ConsentDecision, …)

start with the decision

Events to Consent's handler: ConsentShownEvent (Locale, WordingVersion), ConsentAcceptedEvent (Choices), ConsentDeclinedEvent (Reason: declined or timeout). RequestConsent is unchanged.

Your customer sees your brand, not ours. Company names you on the consent dialog and the indicator. Your colour and logo go on both, so pass them to each:

var logo = File.ReadAllBytes("logo.png");   // a PNG, at most 256 KiB

var agreed = GaiaDeskEmbed.RequestConsent(new ConsentOptions
{
    Company = "Acme", Capture = CaptureMode.Window, BrandColor = "#0f766e", LogoPng = logo,
});
if (agreed != true) return;   // null: no native dialog here, ask with your own

help = GaiaDeskEmbed.Start(
    new EmbedOptions { EmbedToken = embedToken, Company = "Acme", BrandColor = "#0f766e", LogoPng = logo },
    consentGranted: true, OnHelpEvent, SynchronizationContext.Current);

Option (on ConsentOptions and EmbedOptions)

Company

Your name: "Sharing with Acme".

BrandColor

Accent colour, #RRGGBB.

LogoPng

Your logo as PNG bytes, at most 256 KiB.

LogoPngBase64

The same logo already base64-encoded. Set this or LogoPng, not both.

A colour that is not #RRGGBB, or a logo the library refuses (not a PNG, over 256 KiB), throws GaiaDeskEmbedException with Code == "bad_config". It is never read as the customer declining.

ConsentOptions also takes Masked = true, so the dialog says private fields stay hidden (pass the masks too), and ParentWindow (an HWND), which owns the dialog so it never opens behind your window.

The indicator

The indicator starts top right, clear of the window that asked (EmbedOptions.ParentWindow, an HWND; default the focused window), or in the corner IndicatorPosition names (TopLeft, TopRight, BottomLeft, BottomRight). Your customer can drag it; each drag sends an IndicatorMovedEvent with X and Y. The library writes nothing to disk, so keep the place yourself and pass it back as IndicatorOrigin next time (restored while it fits on a screen):

case IndicatorMovedEvent m: Settings.Default.HelpIndicator = $"{m.X},{m.Y}"; break;
// next start:
new EmbedOptions { EmbedToken = embedToken, Company = "Acme", ParentWindow = Handle,
                   IndicatorOrigin = saved is { } p ? new IndicatorPoint(p.X, p.Y) : null }

Until an agent is admitted the indicator offers Cancel: the request leaves your support team's queue at once and the session ends with customer_cancelled (as does Stop() before an agent was admitted). That is also the session's end_reason in the API and in webhooks.

Guided sessions

By default your team can only look. To let them click and type, create the session as cobrowse ("mode": "cobrowse") and set Guided = true — both ends must want it. Pass the same guided to RequestConsent so the dialog says so. Their input is delivered inside your app's own process, only to your app's windows, only while your app is in front, never under a mask, and at most 20 actions a second. Anything refused arrives as an ActionEvent with Applied == false and a Reason (not_focused, outside_app, masked, …).

Your customer can pause it at any time from the indicator; your app can too (SetPaused(true), and SetPaused(false) to resume). A ControlEvent says whether input is allowed right now.

Keeping things private

  • Your app's window only. Capture is CaptureMode.Window by default: one window of your app (WindowId, or the app's frontmost). CaptureMode.App shares all of its windows. Other apps, notifications and the desktop are never captured, unless you choose CaptureMode.Screen. Another app's window is refused.

  • Masks. Pass rectangles over anything sensitive — card numbers, balances, passwords. They are painted black before a frame is encoded. Masks passed in EmbedOptions.Masks cover the very first frame; SetMaskedRects replaces them later (an empty list clears them), so call it again after your layout changes. If masks are set and the window cannot be located, the whole picture is blacked out.

  • Mask coordinates. Rectangles are relative to the top-left of the shared window as GetWindowRect reports it (title bar and borders included), in physical pixels. EmbedRect.FromScreenRect(windowHandle, screenRect) converts a screen rectangle for you. Make your app per-monitor DPI aware so coordinates are physical pixels: in WinForms, <ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode> in the project file; in WPF, per-monitor awareness in app.manifest.

  • Consent every time. The library refuses to start without it; there is no setting that skips the dialog or hides the indicator.

What each platform supports

Capture

Guided input

Consent dialog

Windows 10 and 11 (x64)

window, app, screen

yes

native, branded

  • Windows: nothing to install; the library needs the Visual C++ runtime most apps already ship.

  • Other platforms: the package carries only the Windows x64 library. For a cross-platform desktop app, see the Tauri guide, or the other SDKs listed under in-app support.

What is and is not permitted

You may: ship the prebuilt library unmodified inside your app, with its licence in your app's notices; offer support sessions to your own customers; brand the dialog and indicator with your name, colour and logo.

You may not: modify, decompile or re-sign the library separately from your app; hide or imitate the indicator; start a session without your customer's agreement.

See the SDK's README for every option, event and error code.

Updated