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);
}
'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') {
return async (req, res, next) => {
const context = req.webtaskContext
const lineConfig = getLineConfig(req)
const client = new Client(lineConfig)
try {
const result = await f(context, req, { line: client })
res.json({ ok: true, result })
} catch (e) {
console.error('An error has been caught in the endpoint...')
logError(e)
try {
await client.pushMessage(
context.secrets.LINE_USER_ID,
createErrorMessage(e)
)
} catch (ee) {
console.error('Cannot send error message to LINE!')
logError(ee)
}
return next(e)