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-echoBuild dependencies Using npm:
npm initInstall dependencies
npm install @line/bot-sdk --save
npm install express --save
npm install request --save
npm install request-promise --saveInput 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 >> ProcfileDeploy 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 masterSet env
heroku config:set CHANNEL_ACCESS_TOKEN=your_channel_access_token
heroku config:set CHANNEL_SECRET=your_channel_secretStart your application
heroku ps:scale web=1Copy heroku app url to line-bot webhook
https://line-bot-echo-demo.herokuapp.com/webhookDone!
heroku logsDemo 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}