Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// create LINE SDK client
const client = new line.Client(config);
// create Express app
// about Express itself: https://expressjs.com/
const app = express();
// serve static and downloaded files
app.use('/static', express.static('static'));
app.use('/downloaded', express.static('downloaded'));
app.get('/callback', (req, res) => res.end(`I'm listening. Please access with POST.`));
// webhook callback
app.post('/callback', line.middleware(config), (req, res) => {
if (req.body.destination) {
console.log("Destination User ID: " + req.body.destination);
}
// req.body.events should be an array of events
if (!Array.isArray(req.body.events)) {
return res.status(500).end();
}
// handle events separately
Promise.all(req.body.events.map(handleEvent))
.then(() => res.end())
.catch((err) => {
console.error(err);
res.status(500).end();
});
// create LINE SDK config from env variables
const config = {
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.CHANNEL_SECRET,
};
// create LINE SDK client
const client = new line.Client(config);
// create Express app
// about Express itself: https://expressjs.com/
const app = express();
// register a webhook handler with middleware
// about the middleware, please refer to doc
app.post('/', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result));
});
// event handler
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
// ignore non-text-message event
return Promise.resolve(null);
}
var options1 = {
method: 'GET',
url: 'http://api.susi.ai/susi/chat.json',
qs: {
// create LINE SDK config from env variables
const config = {
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.CHANNEL_SECRET,
};
// create LINE SDK client
const client = new line.Client(config);
// create Express app
// about Express itself: https://expressjs.com/
const app = express();
// register a webhook handler with middleware
// about the middleware, please refer to doc
app.post('/callback', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result));
});
// event handler
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
// ignore non-text-message event
return Promise.resolve(null);
}
// create a echoing text message
const echo = { type: 'text', text: event.message.text };
// use reply API
app.post('/webhook', (req, res, next) => {
const lineConfig = getLineConfig(req)
middleware(lineConfig)(req, res, async err => {
if (err) return next(err)
endpoint(async (context, req, services) => {
const client = services.line
const data = await handleWebhook(context, req.body.events, client)
console.log('Response:', data)
return data
})(req, res, next)
})
})
require('dotenv').config();
const express = require('express');
const line = require('@line/bot-sdk');
const webhookHandler = require('./handler/webhook');
const healthyCheckHandler = require('./handler/healthy-check');
const config = require('./config.js');
const app = express();
app.get('/', healthyCheckHandler);
app.post('/webhook', line.middleware(config), webhookHandler);
app.listen(process.env.PORT || 3000);