Line.Messaging
0.5.0-alpha
This is a prerelease version of Line.Messaging.
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 --version 0.5.0-alpha
NuGet\Install-Package Line.Messaging -Version 0.5.0-alpha
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" Version="0.5.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Line.Messaging --version 0.5.0-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Line.Messaging, 0.5.0-alpha"
#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 Line.Messaging as a Cake Addin #addin nuget:?package=Line.Messaging&version=0.5.0-alpha&prerelease // Install Line.Messaging as a Cake Tool #tool nuget:?package=Line.Messaging&version=0.5.0-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LINE Messaging API
This is a C# implementation of the LINE Messaging API.
Getting Started
- .Net Standard Class Library
NuGet Gallery | Line.Messaging - Azure Function Project Template for Visual Studio 2017
Line Bot Function - Visual Studio Marketplace
LineMessagingApiClient Class
HttpClient-based asynchronous methods.
Task ReplyMessageAsync(string replyToken, IList<ISendMessage> messages)
Task ReplyMessageAsync(string replyToken, params string[] messages)
Task PushMessageAsync(string to, IList<ISendMessage> messages)
Task PushMessageAsync(string to, params string[] messages)
Task MultiCastMessageAsync(IList<string> to, IList<ISendMessage> messages)
Task MultiCastMessageAsync(IList<string> to, params string[] messages)
Task<ContentStream> GetContentStreamAsync(string messageId)
Task<UserProfile> GetUserProfileAsync(string userId)
Task<byte[]> GetContentBytesAsync(string messageId)
Task<UserProfile> GetGroupMemberProfileAsync(string groupId, string userId)
Task<UserProfile> GetRoomMemberProfileAsync(string roomId, string userId)
Task<IList<UserProfile>> GetGroupMemberProfilesAsync(string groupId)
Task<IList<UserProfile>> GetRoomMemberProfilesAsync(string roomId)
Task<GroupMemberIds> GetGroupMemberIdsAsync(string groupId, string continuationToken)
Task<GroupMemberIds> GetRoomMemberIdsAsync(string roomId, string continuationToken = null)
Task LeaveFromGroupAsync(string groupId)
Task LeaveFromRoomAsync(string roomId)
Examples
Examples of use in Azure functions.
Parse and process Webhook-Events
see FunctionAppSample/HttpTriggerFunction.sc
using Line.Messaging;
using Line.Messaging.Webhooks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace FunctionAppSample
{
public static class HttpTriggerFunction
{
static LineMessagingClient lineMessagingClient;
static HttpTriggerFunction()
{
lineMessagingClient = new LineMessagingClient(System.Configuration.ConfigurationManager.AppSettings["ChannelAccessToken"]);
var sp = ServicePointManager.FindServicePoint(new Uri("https://api.line.me"));
sp.ConnectionLeaseTimeout = 60 * 1000;
}
[FunctionName("LineMessagingApiSample")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
IEnumerable<WebhookEvent> events;
try
{
//Parse Webhook-Events
var channelSecret = System.Configuration.ConfigurationManager.AppSettings["ChannelSecret"];
events = await req.GetWebhookEventsAsync(channelSecret);
}
catch (InvalidSignatureException e)
{
//Signature validation failed
return req.CreateResponse(HttpStatusCode.Forbidden, new { Message = e.Message });
}
try
{
var connectionString = System.Configuration.ConfigurationManager.AppSettings["AzureWebJobsStorage"];
var tableStorage = await LineBotTableStorage.CreateAsync(connectionString);
var blobStorage = await BlobStorage.CreateAsync(connectionString, "linebotcontainer");
//Process the webhook-events
var app = new LineBotApp(lineMessagingClient, tableStorage, blobStorage, log);
await app.RunAsync(events);
}
catch (Exception e)
{
log.Error(e.ToString());
}
return req.CreateResponse(HttpStatusCode.OK);
}
}
}
Process Webhook-events using the class that inherited the WebhookApplication class
Line.Messaging/Webhooks/WebhookApplication.cs
public abstract class WebhookApplication
{
protected virtual Task OnMessageAsync(MessageEvent ev);
protected virtual Task OnJoinAsync(JoinEvent ev);
protected virtual Task OnLeaveAsync(LeaveEvent ev);
protected virtual Task OnFollowAsync(FollowEvent ev);
protected virtual Task OnUnfollowAsync(UnfollowEvent ev);
protected virtual Task OnBeaconAsync(BeaconEvent ev);
protected virtual Task OnPostbackAsync(PostbackEvent ev);
}
class LineBotApp : WebhookApplication
{
private LineMessagingClient MessagingClient { get; }
private TraceWriter Log { get; }
public WebhookApplication(LineMessagingClient lineMessagingClient,TraceWriter log)
{
MessagingClient = lineMessagingClient;
Log = log;
}
protected override async Task OnMessageAsync(MessageEvent ev)
{
Log.Info($"SourceType:{ev.Source.Type},SourceId:{ev.Source.Id}");
switch (ev.Message.Type)
{
case EventMessageType.Text:
await MessagingClient.ReplyMessageAsync(ev.ReplyToken, ((TextEventMessage)ev.Message).Text);
break;
case EventMessageType.Image:
case EventMessageType.Audio:
case EventMessageType.Video:
case EventMessageType.File:
case EventMessageType.Location:
case EventMessageType.Sticker:
break;
}
}
protected override async Task OnFollowAsync(FollowEvent ev)
{
throw new NotImplementedException();
}
protected override async Task OnUnfollowAsync(UnfollowEvent ev)
{
throw new NotImplementedException();
}
protected override async Task OnJoinAsync(JoinEvent ev)
{
throw new NotImplementedException();
}
protected override async Task OnLeaveAsync(LeaveEvent ev)
{
throw new NotImplementedException();
}
protected override Task OnBeaconAsync(BeaconEvent ev)
{
throw new NotImplementedException();
}
protected override async Task OnPostbackAsync(PostbackEvent ev)
{
throw new NotImplementedException();
}
}
see also FunctionAppSample/LineBotApp.cs
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Line.Messaging:
Repository | Stars |
---|---|
pierre3/LineMessagingApi
LINE Messaging API for .Net
|
|
microsoft/Dynamics365-Apps-Samples
Sample code for Dynamics 365 apps
|
Version | Downloads | Last updated |
---|---|---|
1.4.5 | 51,301 | 1/20/2019 |
1.4.4 | 1,370 | 12/27/2018 |
1.4.3 | 1,412 | 11/23/2018 |
1.4.2 | 1,238 | 11/13/2018 |
1.4.1 | 2,086 | 9/21/2018 |
1.3.1 | 1,844 | 6/20/2018 |
1.2.6 | 1,740 | 5/2/2018 |
1.2.5 | 1,473 | 4/15/2018 |
1.2.4 | 4,963 | 3/4/2018 |
1.2.2 | 1,564 | 2/7/2018 |
1.2.1 | 2,150 | 12/14/2017 |
1.1.0 | 1,810 | 12/1/2017 |
1.0.1 | 1,676 | 11/9/2017 |
0.7.0-beta | 1,242 | 11/4/2017 |
0.6.0-beta | 1,279 | 10/7/2017 |
0.5.0-alpha | 1,360 | 10/4/2017 |
0.4.0-alpha | 1,273 | 9/18/2017 |
0.3.1-alpha | 1,260 | 9/10/2017 |
0.2.0-alpha | 1,266 | 8/27/2017 |
0.1.0-alpha | 1,257 | 8/22/2017 |
- Supports the datetime picker template action.
- Improved the error handling.