Skip to content

HuangLiPang/serverless-line-bot-echo-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Responsive LineBot builds on Heroku

npmjs

A serverless responsive line-bot builds on Heroku

Requirements

  • Node.js 4 or higher

Documents

Getting Start

Install

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

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!

View logs

heroku logs

Demo locally with ngrok

  1. Simply run echo.js
node echo.js
  • Open another terminal and run ngrok
./ngrok http 3000
  1. 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}

Releases

No releases published

Packages

No packages published