Skip to content

Latest commit

 

History

History
513 lines (506 loc) · 17.9 KB

MESSAGE_kor.md

File metadata and controls

513 lines (506 loc) · 17.9 KB

메시지 발송

LineMessaging API.Net을 통해 여러가지 유형의 메시지 생성 방법 및 발송 방법에 대해 아래와 같이 정리하였으니 참고하시기 바랍니다.

메시지 타입과 quick reply

LINE Developers에서 제공되는 모든 유형의 메시지를 만들 수 있습니다. 위키 내용을 우선 참고해주세요.

참고 코드

메시지 발송 sample

  • SendBroadcastMessageAsync method를 통해 X-Line-Retry-Key와 함께 단순 text메시지 발송 예시)
    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);
            }
        }
    }
  • SendBroadcastMessageAsync method를 통한 다중 유형 메시지 발송 예시)
    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

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);

메시지 유형 및 생성 방법

quick reply buttons는 아래 모든 메시지에 포함 될 수 있습니다.

image

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

image

PackageId / StickerId는 List of available stickers를 참조하세요

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
        },
    },
};