Skip to main content
Version: Next

Migrating from LINE SDK for Node.js

Bottender aims to help LINE developers focus on project-specific business logic. We carefully craft Bottender to save developers' time based on real project experience.

To feel the magic of Bottender, you can check the section of comparison, Creating a Bot Project by LINE SDK vs Bottender. If you are keen on migrating your existing project to Bottender, you can jump to the section, Migrate Your LINE SDK Bot Project to Bottender.

Create a Bot Project by LINE SDK vs Bottender

In the following comparison, you can see a significant difference between creating an echo bot project by LINE SDK or Bottender. Comparing with the code lines of the LINE SDK project, you only need 5% code lines by Bottender.

Create a Bot Project by LINE SDK

The sample code below is from LINE. It represents a basic bot that echoes the user's input.

const express = require('express');
const line = require('@line/bot-sdk');

const config = {
channelAccessToken: 'YOUR_CHANNEL_ACCESS_TOKEN',
channelSecret: 'YOUR_CHANNEL_SECRET',
};

const app = express();
app.post('/webhooks/line', line.middleware(config), (req, res) => {
Promise.all(req.body.events.map(handleEvent)).then((result) =>
res.json(result)
);
});

const client = new line.Client(config);
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
return Promise.resolve(null);
}

return client.replyMessage(event.replyToken, {
type: 'text',
text: event.message.text,
});
}

app.listen(3000);

If you have experienced in bot projects, you can figure out that 80% of the above code is duplicated from project to project. That's why we need an excellent bot framework, i.e., Bottender, to save your development time from redundant works.

Create a Bot Project by Bottender

By Bottender, you can make a simple echo bot in 3 steps:

First, create a LINE bot project by the following one-line command:

npx create-bottender-app my-app

Finish the LINE project environment setup. Please refer to LINE environment setup guide, if you are not familiar with it.

Finally, add bot echo feature by editing the src/index.js file and add one line of code.

module.exports = function App(context) {
await context.sendText(context.event.text);
};

Migrate Your LINE SDK Bot Project to Bottender

In the case that you have an existing bot project, you can follow the below steps to migrate your bot from LINE SDK to Bottender.

To begin with, install Bottender and uninstall LINE Bot SDK:

// Using npm
npm install bottender@next
npm uninstall @line/bot-sdk

// Using yarn
yarn add bottender@next
yarn remove @line/bot-sdk

Then, create your Bottender config file.

Edit your bottender.config.js file as follows:

module.exports = {
enabled: true,
path: '/webhooks/line',
accessToken: process.env.LINE_ACCESS_TOKEN,
channelSecret: process.env.LINE_CHANNEL_SECRET,
};

Create the main logic of your bot project by editing your bot logic in the index.js file:

module.exports = function App(context) {
await context.sendText(context.event.text);
};

Create an environment file .env, and fill in access token and channel secret:

LINE_ACCESS_TOKEN=
LINE_CHANNEL_SECRET=

Finally, run your bot by the following command:

npx bottender start