DotNetLineBotSDK 8.0.0

dotnet add package DotNetLineBotSDK --version 8.0.0                
NuGet\Install-Package DotNetLineBotSDK -Version 8.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="DotNetLineBotSDK" Version="8.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetLineBotSDK --version 8.0.0                
#r "nuget: DotNetLineBotSDK, 8.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 DotNetLineBotSDK as a Cake Addin
#addin nuget:?package=DotNetLineBotSDK&version=8.0.0

// Install DotNetLineBotSDK as a Cake Tool
#tool nuget:?package=DotNetLineBotSDK&version=8.0.0                

取得User Message

var req = this.HttpContext.Request;
using (var bodyReader = new StreamReader(stream: req.Body,
    encoding: Encoding.UTF8,
    detectEncodingFromByteOrderMarks: false,
    bufferSize: 1024, leaveOpen: true))

{
    var body = await bodyReader.ReadToEndAsync();
    var lineReceMsg = ReceivedMessageConvert.ReceivedMessage(body);
    if (lineReceMsg != null && lineReceMsg.Events[0].Type == WebhookEventType.message.ToString())
    {
        if (lineReceMsg.Events[0].Message.Type == MessageType.text.ToString())
        {
            // user message text
            lineReceMsg.Events[0].Message.Text;
        }
    }
}

回應文字訊息

var replyEvent = new ReplyEvent(channel_Access_Token);
var txtMessage1 = new TextMessage("reply message");
await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
                           new List<IMessage>() {
                                txtMessage1
                           });

回應文字+表情訊息

var replyEvent = new ReplyEvent(channel_Access_Token);
var txtMessage1 = new TextMessage("$ LINE emoji $")
{
    Emojis = new List<TextMessageEmoji>()
    {
        new TextMessageEmoji(){Index=0,ProductId="5ac1bfd5040ab15980c9b435",EmojiId="002"},
        new TextMessageEmoji(){Index=13,ProductId="5ac1bfd5040ab15980c9b435",EmojiId="008"}
    }
};
var txtMessage2 = new TextMessage("\U0001F449 Unicode emoji \U0001F617");               
await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
                           new List<IMessage>() {
                                txtMessage1, txtMessage2
                           });

回應圖片訊息

var replyEvent = new ReplyEvent(channel_Access_Token);
var imgMessage = new ImageMessage("{Image URL}"
, "{Preview image URL}");

await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
                            new List<IMessage>() {
                                imgMessage
                            });

回應表情訊息

var replyEvent = new ReplyEvent(channel_Access_Token);
var stickerMessage1 = new StickerMessage(6325, 10979907);
var stickerMessage2 = new StickerMessage(1070, 17843);

await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
                            new List<IMessage>() {
                                stickerMessage1,stickerMessage2
                            });

回應地點訊息

var locMessage = new LocationMessage("title", "address", 22.63434293546932m, 120.3024596345037m);

await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
        locMessage
    });

回應影片訊息

var videoMessage = new VideoMessage("{mp4 video URL}", "{Preview image URL}");
await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
        videoMessage
    });

回應音訊訊息

var audioMessage = new AudioMessage("{m4a audio URL}", "{ Length of audio file (milliseconds) }");
await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
        audioMessage
    });

  

回應Buttons Template訊息

var tempObj = new ButtonsTemplate("線上線下混合教學,隨選自由上,老師互動零距離,直播上課零時差,補課超便利,事後回放不限次數");
tempObj.Title = "巨匠電腦";
tempObj.thumbnailImageUrl = "https://{image url}";

tempObj.DefaultAction = new PostbackAction("課程諮詢", "q=coursehelp");
tempObj.Actions = new List<IAction>()
{
    new PostbackAction("課程諮詢", "q=coursehelp"),
    new PostbackAction("排課需求", "q=courseschedule"),
    new PostbackAction("真人回電", "q=servicecall"),
    new UriAction("巨匠官網", "https://www.pcschool.com.tw/")
};

var tmpMessage = new TemplateMessage("Button Template Message", tempObj);


await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
            tmpMessage
    });
var colums = new List<CarouselColumn>();

var c1 = new CarouselColumn("Python高手養成─網路爬蟲開發密技",
    "網路爬蟲,Python 提供多個套件工具,可以有效率地自動完成許多網路資訊擷取的工作",
    new List<IAction>() { new PostbackAction("登記課程", "action=buy&code=py101"),
                            new UriAction("課程詳情", "https://www.worker360.com.tw/live/TP0008") }
    );
c1.thumbnailImageUrl = "https://{image url}";

var c2 = new CarouselColumn("Excel VBA 第一關:一學就會資料整理術",
    "在9小時課程中,老師將一步步引導您快速學會如何錄製巨集,5分鐘馬上完成資料整理!結合工具鈕1秒完封資料格式!",
    new List<IAction>() { new PostbackAction("登記課程", "action=buy&code=vba102"),
                            new UriAction("課程詳情", "https://www.worker360.com.tw/live/TF0009") }
    );
c2.thumbnailImageUrl = "https://{image url}";

var c3 = new CarouselColumn("網頁前端排版基礎心法篇",
    "做中學習,實際上手設計出兩個完整網站,觀念、方法、實例活用,你也能做網頁",
    new List<IAction>() { new PostbackAction("登記課程", "action=buy&code=ht101"),
                            new UriAction("課程詳情", "https://www.worker360.com.tw/video/DiT000376") }
    );
c3.thumbnailImageUrl = "https://{image url}";

colums.Add(c1);
colums.Add(c2);
colums.Add(c3);

var tempObj = new CarouselTemplate(colums);

var tmpMessage = new TemplateMessage("Confirm Template Message", tempObj);

var json = JsonConvert.SerializeObject(tmpMessage);


await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
            tmpMessage
    });
var colums = new List<ImageCarouselColumn>();

var c1 = new ImageCarouselColumn("https://linebotstorage1129.blob.core.windows.net/img/c1.jpg",
    new UriAction("課程詳情", "https://www.worker360.com.tw/live/TP0008")
    );

var c2 = new ImageCarouselColumn("https://linebotstorage1129.blob.core.windows.net/img/c3.jpg",
    new UriAction("課程詳情", "https://www.worker360.com.tw/live/TF0009"));

var c3 = new ImageCarouselColumn("https://linebotstorage1129.blob.core.windows.net/img/c4.jpg",
    new UriAction("課程詳情", "https://www.worker360.com.tw/video/DiT000376"));

colums.Add(c1);
colums.Add(c2);
colums.Add(c3);

var tempObj = new ImageCarouselTemplate(colums);

var tmpMessage = new TemplateMessage("Image Template Message", tempObj);

await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
            tmpMessage
    });

QuickReplies 訊息

var qrAction1 = new QuickReplyActionBase(new MessageAction("藍色", "藍色"));
qrAction1.ImageUrl = "https://linebotstorage1129.blob.core.windows.net/img/blue.png";

var qrAction2 = new QuickReplyActionBase(new MessageAction("紅色", "紅色"));
qrAction2.ImageUrl = "https://linebotstorage1129.blob.core.windows.net/img/red.png";

var qrAction3 = new QuickReplyActionBase(new UriAction("work360","https://www.worker360.com.tw/"));

var quickReply = new QuickReplyBase();
quickReply.Items.Add(qrAction1);
quickReply.Items.Add(qrAction2);
quickReply.Items.Add(qrAction3);

var txtMessage = new TextMessage("選擇你喜愛顏色或是至網站查詢");
txtMessage.QuickReply = quickReply;


await replyEvent.ReplyAsync(lineReceMsg.Events[0].ReplyToken,
    new List<IMessage>() {
            txtMessage
    });

發送等待回應的Typing效果

var chatId = lineReceMsg.Events[0].Source.UserId;
var botHelper = new BotHelper("bot channelAccessToken");
await botHelper.SendLoadingAsync(chatId, 5); //等待5秒  
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. 
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
8.0.0 93 11/25/2024
1.0.0 228 7/18/2023
0.0.5-alpha 192 1/28/2023
0.0.4-alpha 176 12/25/2022
0.0.3-alpha 179 11/30/2022
0.0.2-alpha 185 11/29/2022
0.0.1-alpha 173 11/22/2022