Echo messages from LINE chat to Slack
In our case, we have a Line group and a Slack channel. Both of them are discussing similar things but with different people. In order to reduce efforts on sending the same messages on both sides, we plan to utilize LINE’s messaging API, connecting it with Slack’s incoming webhook.

The overall process can be broken down to the following steps:
- Create an Incoming Webhook on Slack
- Create a LINE echo bot
- Pass messages to Slack channel whenever the bot receives a message
Create an Incoming Webhook on Slack
There are many nice tutorials on Youtube guiding us on setting up incoming webhooks. The main goal here is to derive a Webhook Url.
We can later open the terminal and use curl to see whether the url works:
$ curl -X POST -H 'Content-type: application/json' --data '{"text":"It is rainy today"}' https://hooks.slack.com/your-webhook-url

Create a LINE echo bot
In order to use LINE’s messaging API, it is required to register ourselves as LINE developers and create a provider. Here is the step by step instructions. In the end, we can add the bot by QR code:

After having a bot, please edit the settings and invite the bot to the chatroom where we want it to ❌ spy ✅ forward messages.

Pass messages to Slack channel whenever the bot receives a message
Now, we will use Node.js to write the message passing part. Create a new folder and download index.js, package-lock.json, and package.json from the following github link:
To setup the configuration easily, we will create a file named .env
in the same folder. We then declare our channel_secret, channel_access_token, and intended port.

We also need to install the some packages. We can type the following commands in terminal:
npm install # download line-sdk listed in package.json
npm install dotenv # for enabling the file .env
npm install node-fetch # for posting api
Great 👊 Let’s rewrite codes in index.js
for posting messages to slack whenever the LINE bot receives a message:
Last step is to run this Node.js server in a place where we can get a public url (It must use https. LINE’s webhook does not accept http 😧) You choose between:
- export your localhost ip using ngrok.
- use firebase function, which is highly recommended since it is easy and fast to setup for production.
In my case, I run it on Google Cloud Platform, where I already setup an apache server to host another website. (Yes, running node.js server and apache server on the same machine was such an arduous work 🙀 I’ve shared my experience in this post 👉 Run Node.js application on Apache server)
In either method, you may start your node.js server by typing this command in the terminal:
node .
Then verify your webhook in LINE’s developer console with your public url (Mine is the GCP machine):

TADA! That’s all 🎊🎊🎊 Now all the messages received by your LINE bot, either texts you directly send to it or those it eavesdrops in the group’s chatroom, will be sent to our slack channel 🙌
