A serverless responsive line-bot builds on Heroku
- Node.js 4 or higher
Make a directory of linebot
mkdir line-bot-echo
cd line-bot-echo
Build dependencies Using npm:
npm init
Install dependencies
npm install @line/bot-sdk --save
npm install express --save
npm install request --save
npm install request-promise --save
Input CHANNELACCESSTOKEN and CHANNELSECRET in echo.js Or you can set in heroku env
const defaultAccessToken = 'CHANNEL_ACCESS_TOKEN';
const defaultSecret = 'CHANNEL_SECRET';
Create a Procfile
echo web: node echo.js >> Procfile
Deploy to heroku using git
git init
git add .
git commit -m "First echo."
Create heroku app and deploy
heroku create line-bot-echo-demo
git push heroku master
Set env
heroku config:set CHANNEL_ACCESS_TOKEN=your_channel_access_token
heroku config:set CHANNEL_SECRET=your_channel_secret
Start your application
heroku ps:scale web=1
Copy heroku app url to line-bot webhook
https://line-bot-echo-demo.herokuapp.com/webhook
Done!
heroku logs
Demo locally with ngrok
- Simply run echo.js
node echo.js
- Open another terminal and run ngrok
./ngrok http 3000
- Using
heroku local
. You need to configure CHANNELACCESSTOKEN and CHANNELSECRET in .env
- Copy Heroku config vars to your local .env file
heroku config:get CHANNEL_ACCESS_TOKEN CHANNEL_SECRET -s >> .env
- Locally start heroku app
heroku local
- Open another terminal and start ngrok with the port heroku local open
./ngrok http ${port}