Line.Messaging.NETCore
1.1.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Line.Messaging.NETCore --version 1.1.0
NuGet\Install-Package Line.Messaging.NETCore -Version 1.1.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="Line.Messaging.NETCore" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Line.Messaging.NETCore" Version="1.1.0" />
<PackageReference Include="Line.Messaging.NETCore" />
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 Line.Messaging.NETCore --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Line.Messaging.NETCore, 1.1.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 Line.Messaging.NETCore@1.1.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=Line.Messaging.NETCore&version=1.1.0
#tool nuget:?package=Line.Messaging.NETCore&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Perform issue fixes and version upgrade for Line.Messaging
- Upgraded the framework from .NET Framework 4.6 to .NET Core 6 and addressed compatibility issues.
- Updated URLs for image, audio, and video messages to use a different domain name.
- Created message types for image, audio, and video.
The original project URL
Modified content references to the data source at
Development environment
- Visual Stdio 2022
TargetFramework
- .net 6
Sample Code
using Line.Messaging.Webhooks;
using Line.Messaging;
using Microsoft.AspNetCore.Mvc;
using Imgur.API.Authentication;
using Imgur.API.Endpoints;
namespace LineBot.Controllers
{
[Route("[controller]")]
[ApiController]
public class LineBotController : ControllerBase
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly HttpContext _httpContext;
private readonly string channelSecret = "{Your channelSecret}";
private readonly string accessToken = "{Your accessToken}";
public LineBotController(IServiceProvider serviceProvider)
{
_httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
_httpContext = _httpContextAccessor.HttpContext;
}
//full URL https://xxx/linebot/run
[HttpPost("run")]
public async Task<IActionResult> Post()
{
var events = await _httpContext.Request.GetWebhookEventsAsync(channelSecret);
var lineMessagingClient = new LineMessagingClient(accessToken);
var lineBotApp = new LineBotApp(lineMessagingClient);
await lineBotApp.RunAsync(events);
return Ok();
}
public class LineBotApp : WebhookApplication
{
private LineMessagingClient _messagingClient;
public LineBotApp(LineMessagingClient lineMessagingClient)
{
_messagingClient = lineMessagingClient;
}
protected override async Task OnMessageAsync(MessageEvent ev)
{
List<ISendMessage> result = new List<ISendMessage>();
string userId = ev.Source.UserId;
string channelId = ev.Source.Id;
switch (ev.Message)
{
case TextEventMessage textMessage:
{
string text = textMessage.Text;
switch (text)
{
case "Image_A":
break;
case "Image_B":
break;
default:
break;
}
result.Add(new TextMessage($"You say:{text}"));
}
break;
case ImageEventMessage imageMessage:
{
if (imageMessage.ContentProvider.Type != ContentProviderType.Line)
break;
using (var stream = await _messagingClient.GetContentStreamAsync(imageMessage.Id))
{
string ext = stream.ContentHeaders.ContentType.MediaType.ToString().Split('/')[1];
string fileName = $"{imageMessage.Id}.{ext}";
string imageUrl = await UploadToImgurAsync(stream);
var message = new ImageMessage(imageUrl, imageUrl);
message.QuickReply = new QuickReply
{
Items = new List<QuickReplyButtonObject>
{
new QuickReplyButtonObject(
new MessageTemplateAction("This is Image_A!", "Image_A")),
new QuickReplyButtonObject(
new MessageTemplateAction("This is Image_B!", "Image_B"))
}
};
result.Add(message);
}
}
break;
}
if (result.Count != 0)
await _messagingClient.ReplyMessageAsync(ev.ReplyToken, result);
}
public async Task<string> UploadToImgurAsync(Stream stream)
{
var apiClient = new ApiClient("{Your Imgur clientId}");
var httpClient = new HttpClient();
var imageEndpoint = new ImageEndpoint(apiClient, httpClient);
var imageUpload = await imageEndpoint.UploadImageAsync(stream);
return imageUpload.Link;
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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.
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.The original project URL is https://github.com/pierre3/LineMessagingApi/.
2.Upgraded the framework from .NET Framework 4.6 to .NET Core 6 and addressed compatibility issues.
3.Updated URLs for image, audio, and video messages to use a different domain name.
4.Created message types for image, audio, and video.
5.Modified content references to the data source at https://ithelp.ithome.com.tw/users/20106865/ironman/2732.