Skip to content

Latest commit

 

History

History
118 lines (108 loc) · 5.69 KB

WEBHOOK_eng.md

File metadata and controls

118 lines (108 loc) · 5.69 KB

webhook api quick start

This is a simple test through WebHook. if you'd like to webhook test quickly using LINE Developers.NET, please following below description step by step.

quick start

  • Messaging API → issue and copy to Channel access token (long-lived)

2. open webhook api sample project

  1. download line webhook sample project
  2. Visual Studio → open line webhook sample project
  3. modify to your Channel access token in LineController constructor
  • LineController.cs
public LineController()
{
    _client = new LineMessagingClient("your channel access token"); //here
}
  1. Visual Studio → F5
  2. take a note or remember of your localhost address and callback url.

3. install ngrok & setting

need to follow the below process for LINE Messenger Serever call directly your local webhook address.

3-1. Download the ngrok what your proper PC environment

3-2. ngrok

  1. run ngrok with your local host in console
    ngrok http https://localhost:7250/
  2. copy created host via ngrok image

4. register Webhook url in LINE Developers

image

  1. LINE Developers Console → Messaging API → Webhook settings
  2. Use webhhook ✔
  3. Webhook URL → Edit → ngrok host + callback url → Update → Verifiy → Success

5. LINE Messanger

If you type some text on your channel, you'll get the message from LINE messenger which is set the webhook.

sample source

LINE Developers Methods
Message event OnMessageEventAsync
Unsend event OnUnSendEventAsync
Follow event OnFollowEventAsync
Unfollow event OnUnFollowEventAsync
Join event OnJoinEventAsync
Leave event OnLeaveEventAsync
Member join event OnMemberJoinEventAsync
Member leave event OnMemberLeaveEventAsync
Postback event OnPostBackEventAsync
Video viewing complete event OnVideoViewingCompleteEventAsync
Beacon event OnBeaconEventAsync
Account link event OnAccountLinkEventAsync
Device link event OnThingsEventAsync
Device unlink event OnThingsEventAsync
LINE Things scenario execution event OnThingsEventAsync

example

ping pong message

This is a sample of message property handling of Message event, it will response as a user input a text or sticker.

protected override async Task OnMessageEventAsync(MessageEventObject messageEventObject)
{
    IMessage message;

    switch (messageEventObject.Message)
    {
        case TextObject:
            var text = (TextObject)messageEventObject.Message;
            message = new TextMessage(text.Text);
            break;
        case StickerObject:
            var sticker = (StickerObject)messageEventObject.Message;
            message = new StickerMessage(sticker.PackageId, sticker.StickerId);
            break;
        default:
            message = new TextMessage("unknown message");
            break;
    }

    await _lineMessagingClient.Message.SendReplyMessageAsync(messageEventObject.ReplyToken, message);
}

a sample of source property handling

protected override async Task OnMessageEventAsync(MessageEventObject messageEventObject)
{
    switch (messageEventObject.Source)
    {
        case UserSource:
            var user = (UserSource)messageEventObject.Source;
            var userId = user.UserId;
            break;
        case GroupChatSource:
            var group = (GroupChatSource)messageEventObject.Source;
            var groupID = group.GroupId;
            var groupUserID = group.UserId;
            break;
        case MultiPersonChatSource:
            var multi = (MultiPersonChatSource)messageEventObject.Source;
            var multiRoomId = multi.RoomId;
            var multiUserId = multi.UserId;
            break;
    }
}