建立 .net core console專案 在命令列模式建立資料夾,接著透過 dotnet new 指令建立專案
PS D:\> md linetest
PS D:\> cd linetest
PS D:\linetest> dotnet new console
系統會出現類似底下畫面...
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on D:\linetest\linetest.csproj...
正在判斷要還原的專案...
已還原 D:\linetest\linetest.csproj (251 ms 內)。
Restore succeeded.
2.接著執行底下指令, 安裝 LineBotSDK 套件...
PS D:\linetest> dotnet add package linebotsdk
系統會出現類似底下畫面...
PS D:\linetest> dotnet add package linebotsdk
正在判斷要還原的專案...
Writing C:\Users\...\AppData\Local\Temp\tmpC537.tmp
info : 正在將套件 'linebotsdk' 的 PackageReference 新增至專案 'D:\linetest\linetest.csproj'。
info : 正在還原 D:\linetest\linetest.csproj 的封裝...
info : GET https://api.nuget.org/v3-flatcontainer/linebotsdk/index.json
info : OK https://api.nuget.org/v3-flatcontainer/linebotsdk/index.json 1088 毫秒
info : 套件 'linebotsdk' 與專案 'D:\linetest\linetest.csproj' 中的所有架構相容。
info : 已將套件 'linebotsdk' 版本 '2.2.23' 的 PackageReference 新增至檔案 'D:\linetest\linetest.csproj'。
info : 正在認可還原...
info : 正在將資產檔案寫入磁碟。路徑: D:\linetest\obj\project.assets.json
log : 已還原 D:\linetest\linetest.csproj (3.16 sec 內)。
安裝完成後我們順便建置(Build)一下,看結果如何:
PS D:\linetest> dotnet build
Microsoft (R) Build Engine for .NET Core 16.6.0+5ff7b0c9e 版
Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。
正在判斷要還原的專案...
已還原 D:\linetest\linetest.csproj (712 ms 內)。
linetest -> D:\linetest\bin\Debug\netcoreapp3.1\linetest.dll
建置成功。
0 個警告
0 個錯誤
經過時間 00:00:05.39
//Console.WriteLine("Hello World!");
var ChannelAccessToken = "_____replace_with_your_channel_access_token_____";
var UserId = "_____replace_with_your_userId_____";
var bot = new isRock.LineBot.Bot(ChannelAccessToken);
//push text
bot.PushMessage(UserId, "Hello World");
//push sticker
bot.PushMessage(UserId, 1, 3);
//push image
bot.PushMessage(UserId, new Uri("https://i.imgur.com/OQx8aid.png"));
//push Audio
var AudioMsg = new isRock.LineBot.AudioMessage(
new Uri("https://arock.blob.core.windows.net/blogdata202008/test.mp3"), 6000);
bot.PushMessage(UserId, AudioMsg);
//push Video
var VideoMsg = new isRock.LineBot.VideoMessage(
new Uri("https://arock.blob.core.windows.net/blogdata202008/POC.mp4"),
new Uri("https://imgur.com/LPQhfXR.png")
);
bot.PushMessage(UserId, VideoMsg);
//push location
var LocationMsg = new isRock.LineBot.LocationMessage(
"大安森林公園", "台北市大安區新生南路二段1號", 25.030000, 121.535833);
bot.PushMessage(UserId, LocationMsg);