Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const broker = config.brokerHost;
const client = mqtt.connect(broker);
const topicActionLog = config.topicActionLog;
const topicNotifyLINE = config.topicNotifyLINE;
const topicDashboardInferenceResult = config.topicDashboardInferenceResult;
const targetUserID = config.LINETargetUserID;
// create LINE SDK config
const LINEConfig = {
channelAccessToken: config.LINEChannelAccessToken,
channelSecret: config.LINEChannelSecret,
};
// create LINE SDK client
const LINEClient = new line.Client(LINEConfig);
function log(m) {
client.publish(topicActionLog, m);
console.log(m);
}
client.on('connect', () => {
client.subscribe(topicNotifyLINE);
client.subscribe(topicDashboardInferenceResult);
log(`client connected to ${broker} successfully.`);
});
client.on('message', (t, m) => {
const size = m.length;
log(`client on topic ${t}, received ${size} bytes.`)
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const ngrok = require('ngrok');
// create LINE SDK config from env variables
const config = {
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN,
channelSecret: process.env.CHANNEL_SECRET,
};
// base URL for webhook server
let baseURL = process.env.BASE_URL;
// 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);
}
// 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();
});
'use strict';
const line = require('@line/bot-sdk');
const express = require('express');
var request = require('request');
var http = require('http');
// 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') {
'use strict';
/* eslint-disable no-param-reassign */
const line = require('@line/bot-sdk');
// create LINE SDK config from env variables
const config = {
channelAccessToken: 'CHANNEL_ACCESS_TOKEN',
channelSecret: 'CHANNEL_SECRET',
};
const client = new line.Client(config);
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
return client.replyMessage(event.replyToken, echo);
}
module.exports.hello = (context, req) => {
Promise
access_token = response.access_token;
// We save access token in cache for 24 hours by default.
const token_retention = this._token_retention || 86400
debug(`Saving access token. Retention is ${String(token_retention)} seconds. Store is ${this.token_store}.`)
if (this.token_store === "redis"){
await this.redis_client.set(key, access_token, "EX", token_retention, "NX")
} else {
cache.put(key, access_token, token_retention * 1000)
}
debug(`Saved access token.`)
}
this._access_token = access_token;
this.sdk = new bot_sdk.Client({
channelAccessToken: this._access_token,
channelSecret: this._channel_secret
})
}
#!/usr/bin/env node
require('dotenv').config();
const config = require('./config.js');
const program = require('commander');
const line = require('@line/bot-sdk');
const fs = require('fs');
const client = new line.Client(config);
program
.version('0.1.0')
.option('-d, --delete-all', 'Delete all existed rich menu')
.parse(process.argv);
let housekeeping = Promise.resolve();
if (program.deleteAll) {
housekeeping = client.getRichMenuList()
// eslint-disable-next-line max-len
.then(output => Promise.all(output.map(richMenuItem => client.deleteRichMenu(richMenuItem.richMenuId))));
}
housekeeping.then(() => client.createRichMenu({
size: {
'use strict';
const line = require('@line/bot-sdk');
const express = require('express');
// 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') {
// 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