Skip to content

Latest commit

 

History

History
516 lines (507 loc) · 18 KB

File metadata and controls

516 lines (507 loc) · 18 KB

how to create / send a message

message types & quick reply

LINE message API has been offered variant message types and you can develop it through LineDevelopers.NET.
please refer to my wiki.

test codes

send message sample

  • example to send a simple text message with a 'X-Line-Retry-Key' header via SendBroadcastMessageAsync method
    using Line;
    using Line.Message;
    
    using (var client = new LineMessagingClient("your access token"))
    {
        try
        {
            await client.Message.SendBroadcastMessageAsync(new TextMessage("hello world"), xLineRetryKey: Guid.NewGuid().ToString());
        }
        catch (LineException ex)
        {
            Console.WriteLine(ex.Message);
    
            foreach (var detail in ex.Details ?? Enumerable.Empty<Detail>())
            {
                Console.WriteLine(detail.Message);
                Console.WriteLine(detail.Property);
            }
        }
    }
  • send multiple message types all at once via SendBroadcastMessageAsync
    var messages = new List<IMessage>()
    {
        new TextMessage()
        {
            Text = "hello world!"
        },
        new StickerMessage()
        {
            PackageId = "6632",
            StickerId = "11825375"
        },
        new LocationMessage()
        {
            Title = "location title",
            Address = "location address",
            Longitude = 127.0374m,
            Latitude = 37.5444m
        },
        new TemplateMessage()
        {
            AltText = "alt text",
            Template = new ButtonTemplate()
            {
                Title = "button template title",
                Text = "button template text",
                Actions = new List<IAction>()
                {
                    new PostBackAction()
                    {
                        Label = "pb action label",
                        Text = "pb text",
                        Data = "pb data"
                    }
                }
            }
        },
        new TextMessage()
        {
            Text = "text with quick",
            QuickReply = new QuickReply()
            {
                Items = new List<QuickReplyButtonObject>()
                {
                    new QuickReplyButtonObject()
                    {
                        Action = new UriAction()
                        {
                            Uri = "https://developers.line.biz/",
                            Label = "uri label"
                        }
                    }
                }
            }
        }
    };
    
    await client.Message.SendBroadcastMessageAsync(messages);

methods for send message

Task SendReplyMessageAsync(string replyToken, IMessage message, bool? notificationDisabled = null);
Task SendReplyMessageAsync(string replyToken, IList<IMessage> messages, bool? notificationDisabled = null);
Task SendPushMessageAsync(string to, IList<IMessage> messages, bool? notificationDisabled = null, string? xLineRetryKey = null);
Task SendPushMessageAsync(string to, IMessage message, bool? notificationDisabled = null, string? xLineRetryKey = null);
Task SendMulticastMessageAsync(IList<string> to, IList<IMessage> messages, bool? notificationDisabled = null, IList<string>? customAggregationUnits = null, string? xLineRetryKey = null);
Task SendMulticastMessageAsync(IList<string> to, IMessage message, bool? notificationDisabled = null, IList<string>? customAggregationUnits = null, string? xLineRetryKey = null);
Task SendNarrowcastMessageAsync(IList<IMessage> messages, IRecipientObject? recipient = null, NarrowcastMessageFilter? filter = null, NarrowcastLimit? limit = null, bool? notificationDisabled = null, string? xLineRetryKey = null);
Task SendNarrowcastMessageAsync(IMessage message, IRecipientObject? recipient = null, NarrowcastMessageFilter? filter = null, NarrowcastLimit? limit = null, bool? notificationDisabled = null, string? xLineRetryKey = null);
Task SendBroadcastMessageAsync(IList<IMessage> messages, bool? notificationDisabled = null, string? xLineRetryKey = null);
Task SendBroadcastMessageAsync(IMessage message, bool? notificationDisabled = null, string? xLineRetryKey = null);

how to make a message via each type

LINE has varient messge types so, you can refer to the below sample cases. all the message types can include quick reply buttons and it's an optional.

image

var message = new TextMessage()
{
    Text = "hello world"
};

image

var message = new StickerMessage()
{ 
    PackageId = "6632",
    StickerId = "11825375"
};

image

var message = new ImageMessage()
{
    OriginalContentUrl = "your image url",
    PreviewImageUrl = "preview image url"
};
var message = new VideoMessage()
{
    OriginalContentUrl = "your mp4 video url",
    PreviewImageUrl = "your preview url",
    TrackingId = "trackingid"
};
var message = new AudioMessage()
{
    OriginalContentUrl = "your m4a audio url",
    Duration = 100
};

image

var message = new LocationMessage()
{        
    Title = "location title",
    Address = "location address",
    Longitude = 127.0374m,
    Latitude = 37.5444m
};
var message = new ImageMapMessage()
{
    BaseUrl = "https://example.com/bot/images/rm001",
    AltText = "This is an imagemap",
    BaseSize = new ImageMapBaseSize()
    { 
        Width = 1040,
        Height = 1040
    },
    Video = new ImageMapVideo()
    { 
        OriginalContentUrl = "https://example.com/video.mp4",
        PreviewImageUrl = "https://example.com/video_preview.jpg",
        Area = new ImageMapArea()
        {
            X = 0,
            Y = 0,
            Width = 1040,
            Height = 585
        },
        ExternalLink = new ImageMapExternalLink()
        { 
            LinkUri = "https://example.com/see_more.html",
            Label = "See More"
        }
    },
    Actions = new List<IImageMapAction>()
    { 
        new ImageMapUriAction()
        {
            LinkUri =  "https://example.com/",
            Area = new ImageMapArea()
            { 
                X = 0,
                Y = 586,
                Width = 520,
                Height = 454
            }
        },
        new ImageMapMessageAction()
        { 
            Text = "Hello",
            Area = new ImageMapArea()
            { 
                X = 520,
                Y = 586,
                Width = 520,
                Height = 454
            }
        }
    }
};

image

var message = new TemplateMessage()
{
    AltText = "alt text",
    Template = new ButtonTemplate()
    {
        Title = "button template title",
        Text = "button template text",
        Actions = new List<IAction>()
        {
            new PostBackAction()
            {
                Label = "pb action",
                Text = "pb text",
                Data = "pb data"
             }
        }
    }
};

image

var message = new TemplateMessage()
{
    AltText = "this is a confirm template",
    Template = new ConfirmTemplate()
    {
        Text = "Are you sure?",
        Actions = new List<IAction>()
        {
            new MessageAction()
            {
                Label = "Yes",
                Text = "yes"
            },
            new MessageAction()
            {
                Label = "No",
                Text = "no"
            }
        }
    }
};

image

var message = new TemplateMessage()
{
    AltText = "alt text",
    Template = new CarouselTemplate()
    {
        Columns = new List<CarouselColumnObject>()
        {
            new CarouselColumnObject()
            {
                ThumbnailImageUrl = "https://upload.wikimedia.org/wikipedia/commons/4/47/VU-Banana-1000x1000.png",
                ImageBackgroundColor = "#FFFFFF",
                Title = "carousel title 1",
                Text = "carousel text 1",
                Actions = new List<IAction>()
                {
                    new PostBackAction()
                    {
                        Label = "pb action",
                        Text = "pb text",
                        Data = "pb data"
                    }
                }
            },
            new CarouselColumnObject()
            {
                ThumbnailImageUrl = "https://upload.wikimedia.org/wikipedia/commons/4/47/VU-Banana-1000x1000.png",
                Title = "carousel title 2",
                Text = "carousel text 2",
                Actions = new List<IAction>()
                {
                    new PostBackAction()
                    {
                        Label = "pb action",
                        Text = "pb text",
                        Data = "pb data"
                    }
                }
            }
        }
    }
};

image

var message = new TemplateMessage()
{
    AltText = "alt text",
    Template = new ImageCarouselTemplate()
    {
        Columns = new List<ImageCarouselColumnObject>()
        {
            new ImageCarouselColumnObject()
            {
                ImageUrl = "https://imageurl",
                Action = new PostBackAction()
                {
                    Label = "pb action 1",
                    Text = "pb text 1",
                    Data = "pb data 1"
                }
            },
            new ImageCarouselColumnObject()
            {
                ImageUrl = "https://imageurl",
                Action = new PostBackAction()
                {
                    Label = "pb action 2",
                    Text = "pb text 2",
                    Data = "pb data 2"
                }
            }
        }
    }
};

image

var message = new FlexMessage()
{
    AltText = "flex message test",
    Contents = new Bubble()
    {
        Hero = new ImageComponent()
        {
            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png",
            Size = SizeType.Full,
            AspectRatio = "20:13",
            AspectMode = AspectModeType.Cover,
            Action = new UriAction()
            {
                Uri = "http://linecorp.com/"
            }
        },
        Body = new BoxComponent()
        {
            Layout = BoxLayoutType.Vertical,
            Contents =
            {
                new TextComponent()
                {
                    Text = "Brown Cafe",
                    Weight = WeightType.Bold,
                    Size = SizeType.Xl
                },
                new BoxComponent()
                {
                    Layout = BoxLayoutType.Baseline,
                    Margin = MarginType.Md,
                    Contents =
                    {
                        new IconComponent()
                        {
                            Size = SizeType.Sm,
                            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
                        },
                        new IconComponent()
                        {
                            Size = SizeType.Sm,
                            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
                        },
                        new IconComponent()
                        {
                            Size = SizeType.Sm,
                            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
                        },
                        new IconComponent()
                        {
                            Size = SizeType.Sm,
                            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png"
                        },
                        new IconComponent()
                        {
                            Size = SizeType.Sm,
                            Url = "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png"
                        },
                        new TextComponent()
                        {
                            Text = "4.0",
                            Size = SizeType.Sm,
                            Color = "#999999",
                            Margin = MarginType.Md,
                            Flex = 0
                        }
                    }
                },
                new BoxComponent()
                {
                    Layout = BoxLayoutType.Vertical,
                    Margin = MarginType.Lg,
                    Spacing = SpacingType.Sm,
                    Contents =
                    {
                        new BoxComponent()
                        {
                            Layout = BoxLayoutType.Baseline,
                            Spacing = SpacingType.Sm,
                            Contents =
                            {
                                new TextComponent()
                                {
                                    Text = "Place",
                                    Color = "#aaaaaa",
                                    Size = SizeType.Sm,
                                    Flex = 1
                                },
                                new TextComponent()
                                {
                                    Text = "Miraina Tower, 4-1-6 Shinjuku, Tokyo",
                                    Wrap = true,
                                    Color = "#666666",
                                    Size = SizeType.Sm,
                                    Flex = 5
                                }
                            }
                        }
                    }
                },
                new BoxComponent()
                {
                    Layout = BoxLayoutType.Baseline,
                    Spacing = SpacingType.Sm,
                    Contents =
                    {
                        new TextComponent()
                        {
                            Text = "Time",
                            Color = "#aaaaaa",
                            Size = SizeType.Sm,
                            Flex= 1
                        },
                        new TextComponent()
                        {
                            Text =  "10:00 - 23:00",
                            Wrap = true,
                            Color = "#666666",
                            Size = SizeType.Sm,
                            Flex = 5
                        }
                    }
                }
            }
        },
        Footer = new BoxComponent()
        {
            Layout = BoxLayoutType.Vertical,
            Spacing = SpacingType.Sm,
            Contents =
            {
                new ButtonComponent()
                {
                    Style = ButtonStyleType.Link,
                    Height = "sm",
                    Action = new UriAction()
                    {
                        Label = "CALL",
                        Uri = "https://linecorp.com"
                    }
                },
                new ButtonComponent()
                {
                    Style = ButtonStyleType.Link,
                    Height = "sm",
                    Action = new UriAction()
                    {
                        Label = "WEBSITE",
                        Uri = "https://linecorp.com"
                    }
                },
                new BoxComponent()
                {
                    Layout = BoxLayoutType.Vertical,
                    Margin = MarginType.Sm
                }
            },
            Flex = 0
        },
    },
};