Sagara.Core.Google 7.0.0-preview.1

This is a prerelease version of Sagara.Core.Google.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Sagara.Core.Google --version 7.0.0-preview.1
                    
NuGet\Install-Package Sagara.Core.Google -Version 7.0.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sagara.Core.Google" Version="7.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sagara.Core.Google" Version="7.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Sagara.Core.Google" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sagara.Core.Google --version 7.0.0-preview.1
                    
#r "nuget: Sagara.Core.Google, 7.0.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sagara.Core.Google@7.0.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sagara.Core.Google&version=7.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Sagara.Core.Google&version=7.0.0-preview.1&prerelease
                    
Install as a Cake Tool

Sagara.Core.Google

Common Google API integration code that I use across many projects.

Google Chat

Breaking changes in 7.0

  • GoogleChatService's constructor now takes IOptions<GoogleChatServiceOptions> instead of GoogleChatServiceOptions.
  • GoogleChatServiceOptions is no longer registered in DI as a plain singleton. Resolve IOptions<GoogleChatServiceOptions> instead.
  • Options are now validated when first resolved, and at host startup via ValidateOnStart. Invalid options throw OptionsValidationException.

Registration and configuration

Register the service in code, from a configuration section, or from a configuration path. In every case, the optional callback runs after binding, so values set in code override bound values.

// In code
services.AddGoogleChatService(o => o.MentionStyle = GoogleChatMentionStyle.Email);

// From a configuration section
services.AddGoogleChatService(builder.Configuration.GetSection("GoogleChat"));

// From a path in the app's registered IConfiguration
services.AddGoogleChatService("GoogleChat");
"GoogleChat": {
  "MentionStyle": "Id",
  "ConvertBodyToClassicMarkup": true,
  "Relay": {
    "BaseAddress": "https://chatrelay.example.com"
  }
}

Keep the relay's API token out of appsettings.json. Put it in user-secrets locally (dotnet user-secrets set "GoogleChat:Relay:ApiToken" "...") and in the GoogleChat__Relay__ApiToken environment variable or a secret store in production. Both are merged into the same configuration section automatically.

Options are validated when they're first resolved. In hosted apps (ASP.NET Core, Generic Host) that happens at startup via ValidateOnStart. In console apps without a host, the OptionsValidationException is thrown the first time GoogleChatService is resolved.

Configuration binding uses reflection. Apps that publish trimmed or Native AOT can turn on the configuration binder source generator with <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>.

Sending directly vs. enqueueing through the throttling relay

Google Workspace allows one message per second per Chat space. A burst of messages sent straight to a webhook gets 429 responses.

  • SendMessageAsync(webhookUrl, ...) posts directly to a Google Chat incoming webhook. Failures are logged and swallowed.
  • EnqueueMessageAsync(spaceName, ...) posts to the Google Chat throttling relay. The relay queues messages per space and forwards them to Google in order, no faster than the limit allows. It requires GoogleChatServiceOptions.Relay; without it, EnqueueMessageAsync throws InvalidOperationException.

Each EnqueueMessageAsync overload matches a SendMessageAsync overload (body, @all mention, user mentions, cards), with two differences:

  • It takes the relay's space name (a key in the relay's webhook map, such as "alerts") instead of a webhook URL. Webhook URLs stay inside the relay.

  • It accepts an optional GoogleChatEnqueueOptions:

    • ThreadKey replies in that thread, or starts it.
    • IdempotencyKey stops repeats within 24 hours from being sent again, so retries are safe.

    Each key must be non-blank and at most 200 characters.

var result = await googleChatService.EnqueueMessageAsync(
    "alerts",
    "Disk is **95%** full",
    new GoogleChatEnqueueOptions { ThreadKey = "disk-alerts", IdempotencyKey = $"disk-{alertId}" },
    cancellationToken);

if (!result.Succeeded)
{
    // result.StatusCode is null when no response came back (network error or timeout).
    logger.LogWarning("Relay rejected message: {Status} {Error}", result.StatusCode, result.Error);
}

GoogleChatEnqueueResult reports:

Property Meaning
Succeeded The relay accepted the message into its queue.
StatusCode The relay's HTTP status, or null if no response was received.
Error The relay's error message (for example, Unknown space "alerts") or the exception message.
Id The relay's per-space sequence number for the message.
QueuePosition The message's place in the queue: 1 is next, and 0 means a duplicate that was already sent.
Duplicate IdempotencyKey matched a message from the last 24 hours, so this one wasn't queued again.

Succeeded means the relay accepted the message, not that Google delivered it. The relay delivers at least once (a message can rarely arrive twice) and moves messages that Google permanently rejects to its dead letters. Argument and configuration errors throw. Canceling the caller's CancellationToken throws OperationCanceledException. Every other failure is logged and returned as Succeeded = false.

Markdown Formatting

Callers always pass the message body and any card Text Paragraph widgets as Markdown.

For the official documentation of what's supported, see Format messages.

Message body: Markdown is converted to classic markup

Incoming webhooks do not render Markdown in the top-level message body, so by default the library converts the Markdown body to Google Chat "classic" markup before sending (GoogleChatServiceOptions.ConvertBodyToClassicMarkup, default true). Set it to false to send the body bytes exactly as supplied. This conversion never touches Markdown in card Text Paragraph widgets — those are always sent with MARKDOWN text syntax and rendered by Google.

Markdown you write Sent as classic markup
[Sagara.org](https://www.sagara.org) <https://www.sagara.org\|Sagara.org>
**Bold** / __Bold__ *Bold*
*Italic* / _Italic_ _Italic_
~~Strikethrough~~ ~Strikethrough~
`single line code` `single line code` (unchanged)
```csharp … ``` ``` … ``` (language info string dropped)
- Simple / 1. Numbered lists unchanged (nested indentation preserved)
# Heading *Heading* (bold line — classic markup has no headings)
> Blockquote > Blockquote (literal > prefix — classic markup has no blockquote)
![alt](url) image <url\|alt> (link form — classic markup has no images)
Raw HTML, e.g. a <chat-user …> mention chip passed through untouched

When ConvertBodyToClassicMarkup is enabled, user mentions are also emitted in classic form (<users/all>, <users/USER_ID>). Google Chat classic markup has no email-mention form, so users are always mentioned by ID while this option is enabled, even when GoogleChatMentionStyle.Email is configured.

Supported in Text Paragraph in cards

Blockquotes and user mentions are not supported in card Text Paragraph widgets.

Feature Markdown
Link [Sagara.org](https://www.sagara.org)
Bold **Bold**
Italic *Italic*
Strikethrough ~~Strikethrough~~
Inline code `single line code`
Code block ```csharp <br> var jon = "sagara"; <br> var name = jon.ToUpperInvariant(); <br> ```
Simple list - Simple <br> - List
Nested list - Nested <br>    - List <br>     - Third item
Numbered list 1. Numbered <br> 1. List
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.0-preview.2 49 11/24/2026
7.0.0-preview.1 56 11/23/2026
6.0.1 119 11/12/2026
6.0.0 99 11/10/2026
6.0.0-preview.28 61 11/5/2026
6.0.0-preview.27 71 11/3/2026
6.0.0-preview.26 61 10/30/2026
6.0.0-preview.25 69 10/28/2026
6.0.0-preview.24 64 10/26/2026
6.0.0-preview.23 68 10/24/2026
6.0.0-preview.22 75 10/23/2026
6.0.0-preview.21 87 10/19/2026
5.10.12 87 11/10/2026
5.10.11 102 11/5/2026
5.10.10 95 11/3/2026
5.10.9 102 10/30/2026
5.10.8 101 10/28/2026
5.10.7 105 10/26/2026
5.10.6 110 10/24/2026
5.10.5 115 10/23/2026
Loading failed