How to use the bottender.LineHandler function in bottender

To help you get started, we’ve selected a few bottender 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 Yoctol / bottender / examples / line-builder / index.js View on Github external
const { LineBot, LineHandler } = require('bottender');
const { createServer } = require('bottender/express');

const bot = new LineBot({
  channelSecret: '__FILL_YOUR_SECRET_HERE__',
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
});

const handler = new LineHandler()
  .onText(/yo/i, async context => {
    await context.sendText('Hi there!');
  })
  .onEvent(async context => {
    await context.sendText("I don't know what you say.");
  })
  .onError(async context => {
    await context.sendText('Something wrong happened.');
  });

bot.onEvent(handler);

const server = createServer(bot);
server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github zaoldyeck / cross-platform-chatbot / src / handler.js View on Github external
const welcomeMessage = 'Hi~ 本 Bot 是用 https://goo.gl/YWhP2L 開源程式碼打造\n\n' +
    '您可以問我\n' +
    '天氣:「台北天氣如何」\n' +
    '百科:「川普是誰」\n' +
    '新聞:「今日新聞」\n' +
    '音樂:「播放告白氣球」;「播放自傳專輯的歌」;「播放動漫歌曲類型的歌」\n' +
    '日曆:「現在時間」\n' +
    '詩詞:「我想聽水調歌頭這首詩」\n' +
    '笑話:「講個笑話」\n' +
    '故事:「說個故事」\n' +
    '股票:「台積電的股價」\n' +
    '食譜:「蛋炒飯怎麼做」\n' +
    '聊天:「你好嗎」'

exports.lineHandler = new LineHandler()
    .onFollow(async context => {
        await context.replyText(welcomeMessage)
    })
    .onText('\/help', async context => {
        await context.replyText(welcomeMessage)
    })
    .onText(async context => {
            const text = context.event.text
            const userId = context._session.user.id
            const reply = await olami.nli(text, userId)
            await context.reply([reply.toLineMessage()])
        }
    )
    .onError(async (context, err) => {
        await context.replyText('對不起唷~ 我需要多一點時間來處理 Q_Q')
    })