Rolespace.Sdk
0.2.6
dotnet add package Rolespace.Sdk --version 0.2.6
NuGet\Install-Package Rolespace.Sdk -Version 0.2.6
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="Rolespace.Sdk" Version="0.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rolespace.Sdk" Version="0.2.6" />
<PackageReference Include="Rolespace.Sdk" />
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 Rolespace.Sdk --version 0.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Rolespace.Sdk, 0.2.6"
#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 Rolespace.Sdk@0.2.6
#: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=Rolespace.Sdk&version=0.2.6
#tool nuget:?package=Rolespace.Sdk&version=0.2.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Rolespace .NET SDK
Minimal client for the Rolespace bot API. Targets .NET 6+.
Install
dotnet add package Rolespace.Sdk
Or drop Rolespace.cs into your project.
Quick start
using Rolespace.Sdk;
// Reads ROLESPACE_BOT_TOKEN from your environment.
using var rs = RolespaceClient.FromEnv();
var me = await rs.MeAsync();
Console.WriteLine($"Logged in as {me.GetProperty("bot").GetProperty("username").GetString()}");
// Send a message:
await rs.SendMessageAsync(serverId, channelId, "Hello from my bot!");
// Listen for interactions:
await foreach (var ix in rs.InteractionsAsync())
{
if (ix.GetProperty("customId").GetString() == "book")
{
var id = ix.GetProperty("id").GetInt64();
await rs.RespondAsync(id, new { type = "message", content = "Booked!", ephemeral = true });
}
}
Webhook signature verification (ASP.NET Core)
using Rolespace.Sdk;
app.MapPost("/webhook", async (HttpContext ctx) =>
{
// Read the RAW body — NOT through a model binder.
using var ms = new MemoryStream();
await ctx.Request.Body.CopyToAsync(ms);
var raw = ms.ToArray();
var sig = ctx.Request.Headers["X-Rolespace-Signature"].ToString();
var secret = Environment.GetEnvironmentVariable("WEBHOOK_SECRET")!;
if (!RolespaceClient.VerifyWebhook(raw, sig, secret))
return Results.Unauthorized();
using var doc = JsonDocument.Parse(raw);
// ...handle doc.RootElement...
return Results.NoContent();
});
Important: model binders eagerly parse JSON; reading from ctx.Request.Body
yourself is the only way to keep the original bytes for HMAC verification.
What this SDK does for you
- Loads the token from
ROLESPACE_BOT_TOKENso you don't hardcode it - Retries 429s with exponential backoff (honors
Retry-After) - Hides the bot token from
ToString() - Verifies webhook signatures with
CryptographicOperations.FixedTimeEquals(constant-time) IAsyncEnumerable<JsonElement>over/interactions— no manual polling loop
API
| Method | What it does |
|---|---|
rs.MeAsync() |
Bot account + owner + scopes |
rs.ServersAsync() |
All servers the bot is in |
rs.ServerAsync(id) |
One server with its channels |
rs.ServerChannelsAsync(id) / ServerMembersAsync(id) |
Lists |
rs.SendMessageAsync(serverId, channelId, "text" or anonymous payload) |
Post a message |
rs.SendDmAsync(recipientId, "text") |
Send a DM |
await foreach (var ix in rs.InteractionsAsync()) |
Stream of interactions |
rs.RespondAsync(id, reply) |
Reply to an interaction |
rs.GetAsync/PostAsync/PatchAsync/PutAsync/DeleteAsync(path, body?) |
Raw HTTP for endpoints not covered above |
RolespaceClient.VerifyWebhook(rawBody, sigHeader, secret) |
Static; constant-time check |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.