ExLine.Message (ExLine v0.1.0)

Copy Markdown View Source

Builders for LINE message objects.

Functions return plain maps conforming to the LINE Messaging API message object spec, ready to pass to ExLine.Api.Messaging.reply/4 / push/4. Template, action, flex and imagemap sub-objects live in ExLine.Message.Template, ExLine.Message.Action, ExLine.Message.Flex and ExLine.Message.Imagemap.

Ref: https://developers.line.biz/en/reference/messaging-api/#message-objects

Summary

Functions

Audio message. duration is in milliseconds.

Coupon message. Option :delivery_tag (route tag for LINE OA Manager analysis).

Imagemap message — a tappable image divided into action areas.

Text message.

Text message v2 — supports mentions/emoji via {placeholder} substitutions.

Video message. Option :tracking_id correlates with the video viewing complete event.

Attaches quick reply actions to a message object.

Overrides the display name and icon of a single message (the "sender" / icon switch).

Functions

audio(original_content_url, duration)

@spec audio(String.t(), integer()) :: map()

Audio message. duration is in milliseconds.

Ref: https://developers.line.biz/en/reference/messaging-api/#audio-message

iex> ExLine.Message.audio("https://x/a.m4a", 60000)
%{type: "audio", originalContentUrl: "https://x/a.m4a", duration: 60000}

coupon(coupon_id, opts \\ [])

@spec coupon(
  String.t(),
  keyword()
) :: map()

Coupon message. Option :delivery_tag (route tag for LINE OA Manager analysis).

Ref: https://developers.line.biz/en/reference/messaging-api/#coupon-message

iex> ExLine.Message.coupon("cpn-1")
%{type: "coupon", couponId: "cpn-1"}

image(original_content_url, preview_image_url)

@spec image(String.t(), String.t()) :: map()

Image message.

Ref: https://developers.line.biz/en/reference/messaging-api/#image-message

iex> ExLine.Message.image("https://x/o.jpg", "https://x/p.jpg")
%{type: "image", originalContentUrl: "https://x/o.jpg", previewImageUrl: "https://x/p.jpg"}

imagemap(base_url, alt_text, base_size, actions, opts \\ [])

@spec imagemap(String.t(), String.t(), map(), [map()], keyword()) :: map()

Imagemap message — a tappable image divided into action areas.

base_size is %{width: w, height: h}; actions are built with ExLine.Message.Imagemap. Option :video.

Ref: https://developers.line.biz/en/reference/messaging-api/#imagemap-message

location(title, address, latitude, longitude)

@spec location(String.t(), String.t(), number(), number()) :: map()

Location message.

Ref: https://developers.line.biz/en/reference/messaging-api/#location-message

iex> ExLine.Message.location("Office", "Taipei", 25.0, 121.5)
%{type: "location", title: "Office", address: "Taipei", latitude: 25.0, longitude: 121.5}

sticker(package_id, sticker_id)

@spec sticker(String.t(), String.t()) :: map()

Sticker message.

Ref: https://developers.line.biz/en/reference/messaging-api/#sticker-message

iex> ExLine.Message.sticker("446", "1988")
%{type: "sticker", packageId: "446", stickerId: "1988"}

text(text, opts \\ [])

@spec text(
  String.t(),
  keyword()
) :: map()

Text message.

Options: :emojis (list of LINE emoji objects), :quote_token (quote a message).

Ref: https://developers.line.biz/en/reference/messaging-api/#text-message

iex> ExLine.Message.text("hello")
%{type: "text", text: "hello"}

iex> ExLine.Message.text("hi", quote_token: "qt")
%{type: "text", text: "hi", quoteToken: "qt"}

text_v2(text, opts \\ [])

@spec text_v2(
  String.t(),
  keyword()
) :: map()

Text message v2 — supports mentions/emoji via {placeholder} substitutions.

Options: :substitution (map of placeholder => substitution object), :quote_token.

Ref: https://developers.line.biz/en/reference/messaging-api/#text-message-v2

iex> ExLine.Message.text_v2("hello {user}")
%{type: "textV2", text: "hello {user}"}

video(original_content_url, preview_image_url, opts \\ [])

@spec video(String.t(), String.t(), keyword()) :: map()

Video message. Option :tracking_id correlates with the video viewing complete event.

Ref: https://developers.line.biz/en/reference/messaging-api/#video-message

iex> ExLine.Message.video("https://x/o.mp4", "https://x/p.jpg")
%{type: "video", originalContentUrl: "https://x/o.mp4", previewImageUrl: "https://x/p.jpg"}

with_quick_reply(message, actions \\ [])

@spec with_quick_reply(map(), [map()]) :: map()

Attaches quick reply actions to a message object.

Ref: https://developers.line.biz/en/docs/messaging-api/using-quick-reply/

iex> "hi" |> ExLine.Message.text() |> ExLine.Message.with_quick_reply([ExLine.Message.Action.message("Yes", "yes")])
%{
  type: "text",
  text: "hi",
  quickReply: %{items: [%{type: "action", action: %{type: "message", label: "Yes", text: "yes"}}]}
}

with_sender(message, name, icon_url)

@spec with_sender(map(), String.t(), String.t()) :: map()

Overrides the display name and icon of a single message (the "sender" / icon switch).

Ref: https://developers.line.biz/en/reference/messaging-api/#icon-nickname-switch

iex> "hi" |> ExLine.Message.text() |> ExLine.Message.with_sender("Bot", "https://example.com/i.png")
%{type: "text", text: "hi", sender: %{name: "Bot", iconUrl: "https://example.com/i.png"}}