Line.OpenApi.Bot 0.1.0-preview

This is a prerelease version of Line.OpenApi.Bot.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Line.OpenApi.Bot --version 0.1.0-preview
                    
NuGet\Install-Package Line.OpenApi.Bot -Version 0.1.0-preview
                    
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="Line.OpenApi.Bot" Version="0.1.0-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Line.OpenApi.Bot" Version="0.1.0-preview" />
                    
Directory.Packages.props
<PackageReference Include="Line.OpenApi.Bot" />
                    
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 Line.OpenApi.Bot --version 0.1.0-preview
                    
#r "nuget: Line.OpenApi.Bot, 0.1.0-preview"
                    
#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 Line.OpenApi.Bot@0.1.0-preview
                    
#: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=Line.OpenApi.Bot&version=0.1.0-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Line.OpenApi.Bot&version=0.1.0-preview&prerelease
                    
Install as a Cake Tool

English | 日本語

LINE .NET client (Line.OpenApi.*)

CI Docs License: MIT

A set of .NET/C# client libraries generated from the official LINE OpenAPI specifications with Kiota, layered with hand-written facades / DI / receive glue organized by usage scenario.

  • Supports messaging (Bot) and LIFF app management as the primary use cases
  • Automatically routes the two hosts — control plane (api.line.me) and data plane (api-data.line.me) — through the MessagingClient facade
  • Consolidates webhook receiving (signature verification + deserialization) in WebhookRequestParser
  • DI integration based on IHttpClientFactory

The target framework is net10.0 only (netstandard2.0 / .NET Framework are out of scope).

Packages

Package Role
Line.OpenApi.Core Common foundation (authentication providers, webhook signature verification, allowed hosts)
Line.OpenApi.ChannelAccessToken Channel access token issuance (v2.1 JWT / v3 stateless, refreshing provider)
Line.OpenApi.Messaging Messaging (MessagingClient facade = control-plane + data-plane clients unified)
Line.OpenApi.Messaging.Webhook Webhook models + receive glue (WebhookRequestParser = signature verification + deserialization)
Line.OpenApi.Liff LIFF app management (LiffClient facade)
Line.OpenApi.Bot Convenience meta-package (optional) = the full Bot set in a single reference (bundles Messaging + Messaging.Webhook + ChannelAccessToken; no code, dependencies only)

Installation

Publishing to NuGet.org is in preparation (currently 0.1.0-preview). Once published:

# Install the full Bot set (send + receive + token issuance) at once
dotnet add package Line.OpenApi.Bot

# Or install per usage scenario
dotnet add package Line.OpenApi.Messaging
dotnet add package Line.OpenApi.Liff

Requirements

  • .NET SDK 10 or later (check with dotnet --version)

Usage

Sending messages (Line.OpenApi.Messaging)

using Line.OpenApi.Messaging;
using Line.OpenApi.Messaging.Generated.Api.Models;

// Quick construction (long-lived channel access token)
var client = MessagingClient.CreateWithStaticToken("CHANNEL_ACCESS_TOKEN");

await client.Api.V2.Bot.Message.Push.PostAsync(new PushMessageRequest
{
    To = "U0123456789abcdef...",
    Messages = new()
    {
        new TextMessage { Text = "Hello, world" },
    },
});

// Content retrieval is automatically routed to the data plane (api-data.line.me)
var stream = await client.Blob.V2.Bot.Message["<messageId>"].Content.GetAsync();

DI (recommended: handler sharing via IHttpClientFactory, CVE-fixed middleware applied):

using Line.OpenApi.Messaging.DependencyInjection;

services.AddLineMessaging(o => o.ChannelAccessToken = "CHANNEL_ACCESS_TOKEN");
// Resolve: sp.GetRequiredService<MessagingClient>()

To use short-lived tokens (e.g. v2.1 JWT assertion), pass a refreshing provider through the authentication-provider injection path:

services.AddLineMessaging(sp => /* return an IAuthenticationProvider (e.g. the refreshing provider from Line.OpenApi.ChannelAccessToken) */);

LIFF app management (Line.OpenApi.Liff)

using Line.OpenApi.Liff;
using Line.OpenApi.Liff.Generated.Models;

var liff = LiffClient.CreateWithStaticToken("CHANNEL_ACCESS_TOKEN");

var apps  = await liff.GetAppsAsync();
var added = await liff.AddAppAsync(new AddLiffAppRequest
{
    View = new LiffView { Type = LiffView_type.Full, Url = "https://example.com" },
});
await liff.UpdateAppAsync(added!.LiffId!, new UpdateLiffAppRequest { Description = "updated" });
await liff.DeleteAppAsync(added.LiffId!);

DI: services.AddLineLiff(o => o.ChannelAccessToken = "…");

Receiving webhooks (Line.OpenApi.Messaging.Webhook)

WebhookRequestParser bundles signature verification (x-line-signature) + body deserialization into a single call. It throws WebhookSignatureException on a bad signature and WebhookPayloadException on a malformed body (both derive from WebhookException).

using Line.OpenApi.Messaging.Webhook.DependencyInjection;

services.AddLineWebhook(o => o.ChannelSecret = "CHANNEL_SECRET");
// Resolve: sp.GetRequiredService<WebhookRequestParser>()

Receiving example in ASP.NET Core (reading the raw body and extracting the signature header is the caller's responsibility; the signature is verified against the raw bytes, so read the raw body before model binding):

using Line.OpenApi.Messaging.Webhook;
using Line.OpenApi.Messaging.Webhook.Generated.Models;

app.MapPost("/webhook", async (HttpRequest request, WebhookRequestParser parser) =>
{
    using var ms = new MemoryStream();
    await request.Body.CopyToAsync(ms);
    var body = ms.ToArray();                                  // raw bytes to verify against
    var signature = request.Headers["x-line-signature"];

    CallbackRequest callback;
    try
    {
        callback = await parser.ParseAsync(body, signature);
    }
    catch (WebhookSignatureException) { return Results.Unauthorized(); }  // bad signature
    catch (WebhookPayloadException)   { return Results.BadRequest(); }    // bad body

    // Events are restored to concrete types by the type discriminator (unknown types stay as the base Event).
    // Branching from here is up to the caller:
    foreach (var ev in callback.Events!)
    {
        switch (ev)
        {
            case MessageEvent m when m.Message is TextMessageContent t:
                Console.WriteLine($"text: {t.Text}");
                break;
            case FollowEvent:                 /* friend added */        break;
            case PostbackEvent p:             /* p.Postback!.Data */    break;
            // Unknown events arrive as the base Event type (may be ignored)
        }
    }
    return Results.Ok();
});

For multi-tenant scenarios (a different secret per channel), use the static overload WebhookRequestParser.ParseAsync(channelSecret, body, signature).

A maximum body size (DoS protection) is out of scope for this helper. Enforce a raw-body size limit upstream, e.g. ASP.NET Core's MaxRequestBodySize.

CLI / MCP tool (line)

A CLI / MCP tool line (Line.OpenApi.Tools) for operating LINE from your local machine is included under tools/. It provides token issuance, message send, webhook development helpers, and LIFF management both as CLI subcommands and as MCP server tools (usable from Claude Desktop / Claude Code).

dotnet tool install -g Line.OpenApi.Tools   # after publishing
line message push --to <id> --text "Hello"
line mcp                                   # start as an MCP server

See tools/README.md (日本語) for details.

Samples

Runnable demo apps are included under samples/ (not part of the NuGet packages). They are offline by default and connect to the real API when environment variables are set.

  • Line.OpenApi.Samples.Console — send / LIFF management / token issuance / webhook parsing (dotnet run -- webhook works without credentials)
  • Line.OpenApi.Samples.Webhook — minimal API webhook receiver + echo reply (live demo via a dev tunnel)

See samples/README.md for run steps, environment variables, and dev tunnel setup.

Build from source

At the repository root:

dotnet build            # net10.0 only
dotnet test             # runs everything by default, including webhook polymorphism (no opt-in flag)

Regenerating from the spec (optional)

The Kiota CLI is only needed if you regenerate the clients from the OpenAPI specs (bundled under openapi/):

dotnet tool install --global Microsoft.OpenApi.Kiota

./scripts/generate.ps1        # Windows / PowerShell
bash scripts/generate.sh      # macOS / Linux

Generated code lives under src/**/Generated/ (kiota-lock.json is committed). The Microsoft.Kiota.Bundle version is managed centrally via KiotaBundleVersion in Directory.Build.props (currently 2.0.0).

Documentation

dotnet tool restore                              # first time only (restores DocFX)
dotnet docfx docs/manual/docfx.json              # metadata extraction + site build → docs/manual/_site/
dotnet docfx docs/manual/docfx.json --serve      # local preview (http://localhost:8080)

The API reference is auto-generated in English from the XML doc comments on the hand-written public surface (generated Line.*.Generated is excluded via filterConfig.yml). Generated artifacts (docs/manual/api/, docs/manual/_site/) are not tracked by Git. See design §13 for details.

Project layout

(repository root)
├── LineOpenApi.slnx             # solution
├── Directory.Build.props        # shared TFM (net10.0) / nullable / Kiota version
├── openapi/                     # spec snapshots
├── scripts/                     # Kiota generation & package verification scripts
├── src/
│   ├── Line.OpenApi.Core/               # auth providers, signature verification, allowed hosts (hand-written)
│   ├── Line.OpenApi.ChannelAccessToken/ # token issuance (form-urlencoded generation + hand-written helpers)
│   ├── Line.OpenApi.Messaging/          # control-plane + data-plane clients + MessagingClient facade
│   ├── Line.OpenApi.Messaging.Webhook/  # webhook models + WebhookRequestParser (receive glue)
│   ├── Line.OpenApi.Liff/               # LIFF + LiffClient facade
│   └── Line.OpenApi.Bot/                # convenience meta-package (dependencies only, no code)
├── tools/                       # CLI / MCP tool (Line.OpenApi.Tools, command name `line`)
├── samples/                     # bundled demo apps (console / webhook Web API)
├── tests/                       # tests for the hand-written surface (signature/receive/routing/DI/snapshot, etc.)
└── docs/                        # design, review records, user manual (manual/)

License

MIT © pierre3

There are no supported framework assets in this 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
0.2.0-preview 54 7/16/2026
0.1.0-preview 54 7/14/2026