Skip to content

Tatsuyato/lineclientbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

lineclientbot

LINE client library for Node.js.

Install

npm install lineclientbot

Quick Start

import { LineClient } from "lineclientbot";

// Login with auth token
const line = new LineClient();
await line.login({ authToken: "YOUR_AUTH_TOKEN" });

// Send a message
await line.sendMessage("u1234567890abcdef1234567890abcdef", "Hello!");

// Listen for messages
line.on("message", async (msg) => {
    console.log(`${msg.from}: ${msg.text}`);
    await msg.reply(`Echo: ${msg.text}`);
});

line.listen();

If you want the library to remember the login automatically, pass rememberMe: true or rememberMe: "./my-token.txt".

The client also exposes a categorized facade for the most common flows:

const line = new LineClient();
await line.api.auth.login({ authToken: "YOUR_AUTH_TOKEN" });
await line.api.messages.sendText("u1234567890abcdef1234567890abcdef", "Hello!");
const profile = await line.api.profile.get();

The original top-level methods still work for compatibility, but the grouped API keeps related actions together.

API

Constructor

new LineClient(options?)
Option Type Default Description
authToken string - Auth token for direct login
mail string - Email for login
pass string - Password for login
device Device "DESKTOPWIN" Device type to emulate
version string auto LINE app version
endpoint string "legy.line-apps.com" API endpoint
storage string | false false File path for persistence, or false for memory only
rememberMe boolean | string false Remember auth token in a plain text file

Login

// With auth token
const line = new LineClient();
await line.login({ authToken: "xxx" });

// With email/password
const line2 = new LineClient();
await line2.login({ mail: "email@example.com", pass: "password" });

// QR Login with event callbacks
const qrClient = await LineClient.loginWithQR({
    rememberMe: true,
    onQR: (url) => console.log("Scan:", url),
    onPin: (pin) => console.log("PIN:", pin),
});

// QR Login from an instance
const client = new LineClient();
await client.login({ rememberMe: true });

QR login is the easiest way to get a fresh authToken. When rememberMe is enabled, the library stores the token in a text file and reuses it on later runs.

Profile

const profile = await line.getMyProfile();
await line.updateMyProfile({ displayName: "New Name" });

Messages

// Send text
await line.sendMessage(chatId, "Hello!");

// Other message types (require full integration)
await line.sendImage(chatId, imageBuffer);
await line.sendVideo(chatId, videoBuffer);
await line.sendAudio(chatId, audioBuffer);
await line.sendFile(chatId, fileBuffer, "file.txt");
await line.sendSticker(chatId, "stickerId");
await line.sendFlex(chatId, "Alt text", flexJson);
await line.sendLocation(chatId, {
    title: "Location",
    address: "123 Street",
    latitude: 13.7563,
    longitude: 100.5018,
});

Chat Management

const chats = await line.getChats();
const chat = await line.getChat(chatMid);
const newChat = await line.createChat({ name: "My Group", memberMids: ["mid1", "mid2"] });
await line.inviteToChat(chatMid, ["mid1"]);
await line.leaveChat(chatMid);

Friends

const contacts = await line.getContacts();
const user = await line.getContact(userMid);
await line.blockContact(userMid);
await line.unblockContact(userMid);

OpenChat (Square)

const squares = await line.getSquares();
await line.joinSquare(invitationUrl);
await line.leaveSquare(squareMid);

Events

line.on("message", async (msg) => {
    console.log(msg.text);
    await msg.reply("Got it!");
    await msg.react("๐Ÿ‘");
    await msg.read();
});

line.on("event", (event) => {
    console.log("Event:", event.type);
});

line.listen();

Storage

import { LineClient, FileStorage, MemoryStorage } from "lineclientbot";

// File-based storage (persists across restarts)
const lineWithFileStorage = new LineClient({
    authToken: "xxx",
    storage: "./line-data.json",
});

// Memory storage (default, no persistence)
const lineInMemory = new LineClient({
    authToken: "xxx",
    storage: false,
});

Device Types

Device Description
"DESKTOPWIN" Windows desktop (default)
"DESKTOPMAC" Mac desktop
"ANDROID" Android phone
"ANDROIDSECONDARY" Android secondary device
"IOS" iPhone
"IOSIPAD" iPad
"WATCHOS" Apple Watch
"WEAROS" Wear OS

Events

Event Callback Description
message (msg: MessageEvent) => void New message received
event (event: any) => void Any LINE event
square:message (msg: MessageEvent) => void OpenChat message
square:event (event: any) => void OpenChat event
log (data: {type, data}) => void Debug logs

License

MIT

About

LINE client library for Node.js

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages