An example LINE bot to echo message with TypeScript. The bot is coded according to TypeScript's best practices.
- Git
- Node.js version 10 and up
- Heroku CLI (optional)
- LINE Developers Account for the bot
- Clone the repository.
git clone https://github.com/line/line-bot-sdk-nodejs.git
- Change directory to the example.
cd line-bot-sdk-nodejs/examples/echo-bot-ts
- Install all dependencies.
npm install
- Configure all of the environment variables.
export CHANNEL_ACCESS_TOKEN=<YOUR_CHANNEL_ACCESS_TOKEN>
export CHANNEL_SECRET=<YOUR_CHANNEL_SECRET>
export PORT=<YOUR_PORT>
- Setup your webhook URL in your LINE Official Account to be in the following format. Don't forget to disable the greeting messages and auto-response messages for convenience.
https://example-url.com/webhook
- Compile the TypeScript files.
npm run build
- Run the application.
npm start
If you want to deploy it via Heroku, it is also possible and is even easier for testing purposes.
- Clone the repository.
git clone https://github.com/line/line-bot-sdk-nodejs.git
- Change directory to the example.
cd line-bot-sdk-nodejs/examples/echo-bot-ts
- Create a Heroku application.
git init
heroku create <YOUR_APP_NAME> # Do not specify for a random name
- Setup the environment variables, and don't forget to setup your webhook URL (from the Heroku application that you have just created) in your LINE Offical Account. The webhook URL will still accept the following format:
https://example-url.com.herokuapp.com/webhook
.
heroku config:set CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
heroku config:set CHANNEL_SECRET=YOUR_CHANNEL_SECRET
- Push the application to the server.
git add .
git commit -m "Initial commit for Heroku testing"
git push heroku master
- Open your application.
heroku open
- Done!