Modern LINE bot framework for Node.js with clean API and working E2EE support
β οΈ Beta Version: This framework is in active development. It includes comprehensive Thrift protocol implementations for TalkService and other LINE services. While functional, please test thoroughly and report any issues.
git clone https://github.com/CyberTKR/line-nodejs.git
cd line-nodejs
npm install
npm startimport { Bot } from './src/core/Bot.js';
const bot = new Bot({
device: "DESKTOPWIN",
enableE2EE: true,
logLevel: 'INFO'
});
// Handle text messages
bot.onText(async (message) => {
const { text, to } = message;
if (text === 'hi') {
await bot.send(to, 'Hello! π');
} else if (text === 'ping') {
await bot.send(to, 'Pong! π');
}
});
// Handle group invitations
bot.onInvite(async (invite) => {
await bot.acceptInvitation(invite.groupId);
await bot.send(invite.groupId, 'π Hello everyone!');
});
// Start the bot
await bot.start();import { Bot } from './src/core/Bot.js';
const bot = new Bot({
token: 'your-auth-token-here',
device: "DESKTOPWIN",
enableE2EE: true
});
await bot.start();const bot = new Bot({
token: 'string', // Optional: LINE auth token for direct login
device: 'string', // Device type (see supported devices below)
enableE2EE: true, // Enable E2EE message decryption
language: 'en_EN', // Language setting
storage: './data', // Storage directory path
logLevel: 'INFO' // Logging level (DEBUG, INFO, WARN, ERROR)
});// Authentication & Control
await bot.start() // Start bot (shows QR if no token)
await bot.stop() // Stop bot gracefully
await bot.getProfile() // Get bot profile
// Messaging
await bot.send(to, message) // Send text message to user or group
// Group Management
await bot.acceptInvitation(groupId) // Accept group invitation
await bot.deleteSelfFromChat(chatId) // Leave group/chat
await bot.getChats(chatIds) // Get chat information
await bot.getAllChatMids() // Get all chat IDs// Message Events
bot.onText(handler) // Handle text messages
bot.onMessage(handler) // Handle all message types
bot.onRead(handler) // Handle message read events
// System Events
bot.onReady(handler) // Bot ready (after successful login)
bot.onInvite(handler) // Group invitations
bot.onJoin(handler) // User joined group
bot.onLeave(handler) // User left group
bot.onError(handler) // Error handling{
type: 'receive', // 'send' or 'receive'
from: 'u1234...', // Sender ID
to: 'u5678...', // Recipient ID (user or group)
id: '_...', // Unique message ID
text: 'Hello', // Message text content
contentType: 0, // Content type (0=text, 1=image, etc.)
createdTime: 1234567890, // Unix timestamp
encrypted: false, // Whether message was E2EE encrypted
raw: {...} // Raw operation data from LINE
}- Core Bot System - Main Bot class with clean API
- Thrift Services - Complete TalkService and protocol implementations
- E2EE Handler - End-to-end encryption support
- Command System - Built-in commands and extensible architecture
- Storage Manager - Automatic data persistence
line-nodejs includes full E2EE support with automatic message decryption:
bot.onText(async (message) => {
// E2EE messages are automatically decrypted
if (message.encrypted) {
console.log('π This was an encrypted message!');
}
// message.text contains the decrypted content
console.log('Message:', message.text);
});- β Automatic Decryption - Encrypted messages are transparently decrypted
- β V1 & V2 Support - Supports both E2EE protocol versions
- β Key Management - Automatic key generation, storage and retrieval
- β Error Recovery - Graceful fallback for decryption failures
- β Performance Optimized - Efficient encryption/decryption processing
line-nodejs supports multiple LINE client types:
- DESKTOPWIN - Windows desktop client (recommended)
- IOS - iOS mobile client
- IOSIPAD - iPad client
- CHROMEOS - Chrome OS client
const bot = new Bot({
device: "DESKTOPWIN" // Most stable option
});The framework includes a comprehensive command system:
| Command | Description | Usage |
|---|---|---|
hi |
Greet the bot | Send "hi" |
time |
Show current time | Send "time" |
gr |
Show chat information | Send "gr" |
tagall |
Tag all group members | Send "tagall" |
stats |
Show bot statistics | Send "stats" |
help |
Show available commands | Send "help" |
chats |
List all chat IDs | Send "chats" |
bye |
Leave current group | Send "bye" |
ping |
Ping/pong test | Send "ping" |
version |
Show bot version | Send "version" |
joke |
Tell a random joke | Send "joke" |
Automatic data persistence with simple API:
// Data is automatically saved to ./data/ directory
// Storage is handled per-bot instance
// Bot data is automatically managed
// No manual storage configuration neededbot.onError((error) => {
console.error('Bot error:', error.message);
});const bot = new Bot({ device: "DESKTOPWIN", enableE2EE: true });
bot.onReady((profile) => {
console.log(`β
Logged in as: ${profile.displayName}`);
});
await bot.start(); // Shows QR codeThis framework is in beta stage and may have undiscovered issues. Please:
- Test thoroughly before using in production
- Report bugs and issues on GitHub
- Keep backups of your data
- Use at your own risk
QR Code not appearing
- Make sure you don't have a token set
- Check that your terminal supports image display
- Try running with
logLevel: 'DEBUG'
Messages not being received
- Verify bot is properly started with
bot.onReady() - Check if E2EE is enabled for encrypted chats
- Ensure proper event handlers are registered
E2EE decryption failing
- Some bot accounts don't support E2EE
- This is normal behavior - bot will handle regular messages
- Enable debug logging to see encryption status
Connection issues
- Check your internet connection
- Verify LINE servers are accessible
- Try different device types if issues persist
Enable detailed logging for troubleshooting:
const bot = new Bot({
logLevel: 'DEBUG' // Show all debug information
});- Memory efficient - Optimized for long-running bots
- Fast startup - Quick initialization and connection
- Reliable polling - Robust message polling with auto-recovery
- Low latency - Fast message processing and response times
line-nodejs provides a simpler, more intuitive API while maintaining full functionality:
// Traditional LINE implementation
// Complex Thrift setup, manual E2EE handling, raw protocol management
// line-nodejs style
const bot = new Bot({ token: '...' });
// Clean API with automatic E2EE, built-in commands, and modern async/awaitEasy migration with familiar event-driven architecture and clean async/await syntax.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
This project was inspired by and references the following excellent LINE bot frameworks:
Special thanks to the developers of these projects for their pioneering work in LINE bot development!
If you encounter any issues or have questions:
- Check the troubleshooting section
- Enable debug mode for detailed logs
- Open an issue on GitHub with error details
- π± Contact via LINE:
Add me on LINE
line-nodejs - Modern LINE bot framework with clean API and working E2EE support π