Skip to content

Instantly share code, notes, and snippets.

@doniwirawan
Created May 12, 2022 07:01
Show Gist options
  • Save doniwirawan/c023461fb4aeb9de79e2e77600cac668 to your computer and use it in GitHub Desktop.
Save doniwirawan/c023461fb4aeb9de79e2e77600cac668 to your computer and use it in GitHub Desktop.
Line bot server
require('dotenv').config()
const configuration = {
channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.LINE_CHANNEL_SECRET
}
const express = require('express')
const app = express()
const line = require('@line/bot-sdk')
const client = new line.Client(configuration)
app.get('/', (req, res) => {
res.status(200).send('Line Chatbot Running')
})
app.post('/event', line.middleware(configuration),(req,res) => {
req.body.events.map(event => {
// command list
client.replyMessage(event.replyToken, { type: 'text', text: 'Your command list: /command, /second, /creator' }, false)
// assign your command and text response here
if(event.message.text.toLowerCase().includes('/command')){
client.replyMessage(event.replyToken, { type: 'text', text: 'Your command get trigger here' }, false)
}
// second command
if (event.message.text.toLowerCase().includes('/second')){
client.replyMessage(event.replyToken, { type: 'text', text: 'Your second command trigger here' }, false)
}
// third command
if (event.message.text.toLowerCase().includes('/creator')) {
client.replyMessage(event.replyToken, { type: 'text', text: 'Doni wirawan who makes this repo' }, false)
}
})
res.status(200).send('Line Chatbot Running')
})
app.listen(process.env.PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment