NetCoreLineBotSDK 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NetCoreLineBotSDK --version 1.0.0
NuGet\Install-Package NetCoreLineBotSDK -Version 1.0.0
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="NetCoreLineBotSDK" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetCoreLineBotSDK --version 1.0.0
#r "nuget: NetCoreLineBotSDK, 1.0.0"
#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.
// Install NetCoreLineBotSDK as a Cake Addin
#addin nuget:?package=NetCoreLineBotSDK&version=1.0.0

// Install NetCoreLineBotSDK as a Cake Tool
#tool nuget:?package=NetCoreLineBotSDK&version=1.0.0

描述

Line Message Api .NET 5 SDK

如何安裝

Nuget
Install-Package NetCoreLineBotSDK -Version 0.2.0
dotnet cli
dotnet add package NetCoreLineBotSDK --version 0.2.0

快速開始

於Line Develop Console 取得 Channel Secret 及 Access Token

https://developers.line.biz/zh-hant/

  • 申請一個Provider
  • 申請一個Channel (一個Provider可以有多個Channel)
  • 於Channel取得 Channel Secret 及 Access Token
  • Use webhook 啟用
  • Auto-reply messages 關閉
  • 設定 Webhook URL (需為https)

Startup.cs 新增 AddLineBotSDK

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddLineBotSDK(Configuration);
}

新增一個 Web Api Controller

[Route("api/[controller]")]
[ApiController]
public class LineController : ControllerBase
{
    private readonly ILineMessageUtility lineMessageUtility;
    public LineController(ILineMessageUtility _lineMessageUtility)
    {
        lineMessageUtility = _lineMessageUtility;
    }

    [HttpPost]
    [LineVerifySignature]
    public async Task<IActionResult> Post(WebhookEvent request)
    {
        var app = new LineBotSampleApp(lineMessageUtility);
        await app.RunAsync(request.events);
        return Ok();
    }
}

繼承 LineBotApp,可針對不同事件 override 處理

public class LineBotSampleApp : LineBotApp
{
    private readonly ILineMessageUtility lineMessageUtility;
    public LineBotSampleApp(ILineMessageUtility _lineMessageUtility) : base(_lineMessageUtility)
    {
        lineMessageUtility = _lineMessageUtility;
    }

    protected override async Task OnMessageAsync(LineEvent ev)
    {
        await lineMessageUtility.ReplyMessageAsync(ev.replyToken, $"You Said:{ev.message.Text}");
    }
}

完成第一個 Echo Bot

Echo Bot)

appsettings.json 增加token

"LineSetting": {
    "ChannelSecret": "<Your Line Channel Secret>",
    "ChannelAccessToken": "<Your Line Channel Access Token>"
}

Line message Api 官方文件

https://developers.line.biz/en/services/messaging-api/

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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. 
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
1.3.0 4,029 7/9/2021
1.2.0 330 7/6/2021
1.1.0 344 7/5/2021
1.0.1 324 6/24/2021
1.0.0 324 6/22/2021
0.2.0 797 12/19/2020
0.1.3 386 10/9/2020
0.1.2 411 10/9/2020
0.1.0 420 10/9/2020