How to use the @line/bot-sdk.Client function in @line/bot-sdk

To help you get started, we’ve selected a few @line/bot-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DT42 / BerryNet / line.js View on Github external
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.`)
github line / line-bot-sdk-nodejs / examples / kitchensink / index.js View on Github external
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);
  }
github fossasia / susi_linebot / index.js View on Github external
'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') {
github serverless / examples / azure-node-line-bot / handler.js View on Github external
'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
github nkjm / bot-express / module / messenger / line.js View on Github external
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
        })
    }
github chaintng / panda-crypto-bot / upload-rich-menu.js View on Github external
#!/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: {
github line / line-bot-sdk-nodejs / examples / echo-bot / index.js View on Github external
'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') {
github dtinth / automatron / src / bot.ts View on Github external
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)

@line/bot-sdk

Node.js SDK for LINE Messaging API

Apache-2.0
Latest version published 2 days ago

Package Health Score

90 / 100
Full package analysis