LibroLineMessageSDK 2.1.4

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package LibroLineMessageSDK --version 2.1.4
                    
NuGet\Install-Package LibroLineMessageSDK -Version 2.1.4
                    
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="LibroLineMessageSDK" Version="2.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LibroLineMessageSDK" Version="2.1.4" />
                    
Directory.Packages.props
<PackageReference Include="LibroLineMessageSDK" />
                    
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 LibroLineMessageSDK --version 2.1.4
                    
#r "nuget: LibroLineMessageSDK, 2.1.4"
                    
#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 LibroLineMessageSDK@2.1.4
                    
#: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=LibroLineMessageSDK&version=2.1.4
                    
Install as a Cake Addin
#tool nuget:?package=LibroLineMessageSDK&version=2.1.4
                    
Install as a Cake Tool

LineMessageApiSDK

GitHub release CI CodeQL NuGet NuGet downloads License Issues PRs .NET

此專案為 LINE Messaging API 的 C# SDK,並以開源專案結構進行整理,方便維護與擴充。

NuGet

dotnet add package LibroLineMessageSDK

若要使用 DI/Options 方便註冊,請加裝擴充套件:

dotnet add package LibroLineMessageSDK.Extensions

快速使用範例

1) 直接建立實例

using LineMessageApiSDK;

var channelAccessToken = Environment.GetEnvironmentVariable("LINE_CHANNEL_ACCESS_TOKEN");
if (string.IsNullOrWhiteSpace(channelAccessToken))
{
    throw new InvalidOperationException("缺少 LINE_CHANNEL_ACCESS_TOKEN");
}

var sdk = new LineSdkBuilder(channelAccessToken)
    .UseBot()
    .UseMessages()
    .Build();

2) 透過 DI 注入

using LineMessageApiSDK;
using LineMessageApiSDK.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
var configuration = new ConfigurationBuilder()
    .AddEnvironmentVariables()
    .Build();

services.AddLineSdk(
    configuration,
    sdkBuilder => sdkBuilder
        .UseBot()
        .UseMessages());

var serviceProvider = services.BuildServiceProvider();
var sdk = serviceProvider.GetRequiredService<LineSdk>();

3) Webhook 驗證與回覆訊息(最短流程)

using LineMessageApiSDK;
using LineMessageApiSDK.LineMessageObject;
using LineMessageApiSDK.LineReceivedObject;
using System.Text.Json;

public async Task<IActionResult> Webhook(HttpRequestMessage request, string channelSecret, string channelAccessToken)
{
    if (!LineChannel.VaridateSignature(request, channelSecret))
    {
        return new UnauthorizedResult();
    }

    var body = await request.Content.ReadAsStringAsync();
    var payload = JsonSerializer.Deserialize<LineReceivedMsg>(body);
    var replyToken = payload?.events?[0]?.replyToken;

    if (!string.IsNullOrWhiteSpace(replyToken))
    {
        var sdk = new LineSdkBuilder(channelAccessToken)
            .UseMessages()
            .Build();

        await sdk.Messages!.SendReplyMessageAsync(replyToken, new TextMessage("收到!"));
    }

    return new OkResult();
}

LINE Messaging API 2.0 快速使用

請先閱讀「LINE Messaging API 2.0 規格速覽與快速上手」,內含支援端點與最短上手流程。
docs/line-message-api-2.0.md

Wiki 同步

本 repo 以 docs/wiki/ 作為文件來源,可用腳本同步到 GitHub Wiki repo:

pwsh scripts/sync-wiki.ps1
pwsh scripts/sync-wiki.ps1 -Commit
pwsh scripts/sync-wiki.ps1 -Commit -Push

授權

本專案採用 MIT License,詳見 LICENSE

範例:API 與 Dashboard 兩種流程

此範例提供兩條路徑:

  1. API 範例:透過設定或環境變數注入 Channel Access Token / Secret
  2. Dashboard 範例:由頁面輸入並存於記憶體,提供快速驗證與即時事件流

API 範例(注入或環境變數)

設定 LineChannel

{
  "LineChannel": {
    "ChannelAccessToken": "YOUR_CHANNEL_ACCESS_TOKEN",
    "ChannelSecret": "YOUR_CHANNEL_SECRET"
  }
}

或使用環境變數:

  • LineChannel__ChannelAccessToken
  • LineChannel__ChannelSecret

Webhook 入口:

  • POST /line/hook

Dashboard 範例(頁面設定)

新增 Bootstrap 5 + Vue 的 Web UI 範例,支援輸入 Token/Secret、設定 Webhook Endpoint,並即時顯示 webhook 事件。

詳細說明請見: docs/example-line-webhook-dashboard.md

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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.

Version Downloads Last Updated