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.
<PackageVersion Include="NetCoreLineBotSDK" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NetCoreLineBotSDK" />
                    
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 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.
#:package NetCoreLineBotSDK@1.0.0
                    
#: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=NetCoreLineBotSDK&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NetCoreLineBotSDK&version=1.0.0
                    
Install as a Cake Tool

描述

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.  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.

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,244 7/9/2021
1.2.0 495 7/6/2021
1.1.0 534 7/5/2021
1.0.1 493 6/24/2021
1.0.0 489 6/22/2021
0.2.0 984 12/19/2020
0.1.3 575 10/9/2020
0.1.2 627 10/9/2020
0.1.0 604 10/9/2020