How to Send Text, Image, Video, and Location Messages with LINEJS
Use client.base.talk.sendMessage() with the appropriate contentType parameter—set to ContentType.IMAGE, VIDEO, or LOCATION—and provide the corresponding payload via text, chunks, or location properties.
The LINEJS library (evex-dev/linejs) provides a TypeScript-native abstraction over LINE's Messaging API, enabling developers to send different message types through a unified sendMessage interface. Whether you're transmitting plain text, binary image chunks, or geographic coordinates, the library handles Thrift request construction, content encoding, and automatic E2EE encryption fallback.
Understanding the LINEJS Message Architecture
LINEJS organizes message sending capabilities into service classes that manage the underlying Thrift protocol communication. When you invoke sending methods, the library constructs specific request structs and manages the binary payload transmission.
Service Layer Implementation
The core sending logic resides in two primary service modules:
- TalkService (
packages/linejs/base/service/talk/mod.ts, lines 80-89): Handles one-to-one and group chat messages - SquareService (
packages/linejs/base/service/square/mod.ts, lines 47-56): Manages LINE Square (community) chat messages
Both services utilize LINEStruct helpers from packages/linejs/base/thrift/readwrite/struct.ts to build Thrift request structs like sendMessage_args. The library then dispatches these through the BaseClient.request layer, which manages HTTP/2 transport, retries, and timeout handling.
Content Type Enumeration
Message types are defined in the ContentType enum located at packages/types/line_types.ts (lines 3693-3702). Key values include:
NONE(0): Default text messagesIMAGE(1): Image attachmentsVIDEO(2): Video filesLOCATION(3): Geographic coordinatesAUDIO(4): Audio files
Sending Text Messages with LINEJS
Text messages use the default contentType of NONE and require only the to and text parameters.
await client.base.talk.sendMessage({
to: "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // recipient user MID
text: "Hello from LINEJS!",
});
The method returns a Promise<Message> containing the server's response metadata. For group chats, substitute the user MID with a group MID (format: Cxxxxxxxx...).
Sending Image and Video Messages
Binary content requires the chunks parameter—an array of Buffer or Uint8Array objects—and explicit contentType specification.
Image Messages
Set contentType to ContentType.IMAGE (numeric value 1) and provide the binary data:
import { ContentType } from "@evex/linejs-types";
const imageBytes = await Deno.readFile("./photo.jpg"); // or Buffer in Node.js
await client.base.talk.sendMessage({
to: "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
contentType: ContentType.IMAGE,
chunks: [imageBytes],
contentMetadata: {
"ATTACHMENT_TYPE": "image",
"FILE_NAME": "photo.jpg"
},
});
Video Messages
Video transmission follows the identical pattern, changing only the content type identifier:
import { ContentType } from "@evex/linejs-types";
const videoBuffer = await Deno.readFile("./clip.mp4");
await client.base.talk.sendMessage({
to: "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
contentType: ContentType.VIDEO, // 2
chunks: [videoBuffer],
contentMetadata: {
"ATTACHMENT_TYPE": "video",
"FILE_NAME": "clip.mp4"
},
});
The chunks array supports multiple buffers for large files; LINEJS streams these as a single logical message without additional slicing logic.
Sending Location Messages
Location messages transmit geographic coordinates through a structured object rather than binary chunks. Import the Location type and set contentType to LOCATION.
import type { Location } from "@evex/linejs-types";
const locationData: Location = {
title: "Tokyo Station",
address: "1 Chome Marunouchi, Chiyoda City, Tokyo",
latitude: 35.6812,
longitude: 139.7671,
};
await client.base.talk.sendMessage({
to: "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
contentType: ContentType.LOCATION, // or string "LOCATION"
location: locationData,
});
Working with Square Chats
To send different message types to LINE Square communities, use client.base.square.sendMessage() with squareChatMid instead of to:
await client.base.square.sendMessage({
squareChatMid: "SCxxxxxxxxxxxx",
text: "Hello Square members!",
contentType: ContentType.IMAGE,
chunks: [imageBytes],
});
The Square service implementation (packages/linejs/base/service/square/mod.ts) handles the specific SquareService_sendMessage_args struct construction while maintaining the same public interface as the Talk service.
E2EE Encryption and Error Handling
LINEJS implements automatic end-to-end encryption fallback when the server requires E2EE for specific conversations. According to the source code in packages/linejs/base/service/talk/mod.ts (lines 61-68), if the initial request returns an E2EE error and the e2ee option was not explicitly set to true, the service automatically:
- Encrypts the payload using
client.e2ee.encryptE2EEMessage() - Reconstructs the Thrift request with encrypted content
- Retries the transmission
You can force E2EE encryption preemptively by setting e2ee: true in the options object:
await client.base.talk.sendMessage({
to: "Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
text: "Secret message",
e2ee: true,
});
Summary
- Unified interface: Use
client.base.talk.sendMessage()orclient.base.square.sendMessage()for all message types - Content identification: Specify
contentTypeusing theContentTypeenum (IMAGE,VIDEO,LOCATION) from@evex/linejs-types - Binary payloads: Provide images and videos as
BufferorUint8Arrayarrays via thechunksparameter - Location data: Pass structured
Locationobjects containing latitude, longitude, title, and address - Automatic security: The library handles E2EE encryption fallback automatically when required by the server
Frequently Asked Questions
What ContentType values does LINEJS support for sending messages?
LINEJS supports the full ContentType enumeration defined in packages/types/line_types.ts, including NONE (text), IMAGE (1), VIDEO (2), LOCATION (3), AUDIO (4), and FILE (14). Each numeric constant maps to the underlying Thrift protocol's integer representation used in sendMessage_args structs.
How does LINEJS handle large image or video files?
The library accepts binary data as an array of chunks (chunks: string[] | Buffer[]), allowing you to split large files into multiple buffers. LINEJS encodes each chunk into the Thrift binary fields without performing additional slicing, streaming the complete payload through the BaseClient.request layer to LINE's servers.
Does LINEJS automatically encrypt messages?
Yes. According to the implementation in packages/linejs/base/service/talk/mod.ts (lines 61-68), if the server responds with an E2EE error to an unencrypted message, the service automatically encrypts the payload using the E2EE module (packages/linejs/base/e2ee/mod.ts) and retries the request. You can also force encryption by setting e2ee: true in the message options.
Can I send messages to LINE Square chats using the same methods?
Yes. While one-to-one chats use client.base.talk.sendMessage() with a to parameter, LINE Square chats use client.base.square.sendMessage() with squareChatMid. Both methods support identical contentType, chunks, text, and location parameters, as implemented in packages/linejs/base/service/square/mod.ts (lines 47-56).
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →