Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bottender-compose

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bottender-compose

An utility library for bottender and higher-order handlers

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30
increased by66.67%
Maintainers
3
Weekly downloads
 
Created
Source

bottender-compose

npm License: MIT

An utility library for Bottender and higher-order handlers

Installation

npm install bottender-compose

API Reference

series

Create a function that executes methods in series.

const { series, sendText } = require('bottender-compose');

bot.onEvent(series([
  sendText('1. First Item'),
  sendText('2. Second Item'),
  sendText('3. Third Item'),
]));

parallel

Create a function that executes methods in parallel.

const { parallel, sendText } = require('bottender-compose');

bot.onEvent(parallel([
  sendText('- You got one of Items'),
  sendText('- You got one of Items'),
  sendText('- You got one of Items'),
]));

random

Create a function that executes one of method randomly.

const { random, sendText } = require('bottender-compose');

bot.onEvent(random([
  sendText('You got a random item: A'),
  sendText('You got a random item: B'),
  sendText('You got a random item: C'),
]));

branch

Create a function that will process either the onTrue or the onFalse function depending upon the result of the condition predicate.

const { branch, sendText } = require('bottender-compose');

bot.onEvent(branch(
  context => true,
  sendText('You are the lucky one.'),
  sendText('Too bad.')
));

Or you can executes function on true and do nothing when received false.

branch(context => true, sendText('You are the lucky one.'));

condition

Create a function that encapsulates if/else, if/else, ... logic.

const { condition, sendText } = require('bottender-compose');

bot.onEvent(
  condition([
    [context => false, sendText('a')],
    [context => false, sendText('b')],
    [context => true, sendText('c')],
  ])
);

platform

Create a function that will process function depending upon the platform context.

const {
  platform,
  sendGenericTemplate,
  sendImagemap,
} = require('bottender-compose');

bot.onEvent(platform({
  messenger: sendGenericTemplate(...),
  line: sendImagemap(...),
}));

Or you can use others key to match other platforms:

platform({
  messenger: sendGenericTemplate(...),
  line: sendImagemap(...),
  others: sendText('Unsupported.'),
});

tryCatch

Create a function that calls error handler on error.

const { tryCatch, sendText } = require('bottender-compose');

bot.onEvent(tryCatch(
  doSomethingMayFail(),
  sendText('Error Happened~~~~~~~~~~~!')
));

weight

Create a function that randomly executes one of method by its weight.

const { weight, sendText } = require('bottender-compose');

bot.onEvent(
  weight([
    [0.2, sendText('20%')],
    [0.4, sendText('40%')],
    [0.4, sendText('40%')],
  ])
);

doNothing

Create a no-op function.

const { branch, sendText, doNothing } = require('bottender-compose');

bot.onEvent(
  branch(
    context => false,
    sendText('You are the lucky one.'),
    doNothing() // do exactly nothing...
  )
);

Other Methods

Common
  • setState
  • resetState
  • typing
Messenger
  • sendMessage
  • sendText
  • sendAttachment
  • sendAudio
  • sendImage
  • sendVideo
  • sendFile
  • sendTemplate
  • sendButtonTemplate
  • sendGenericTemplate
  • sendListTemplate
  • sendOpenGraphTemplate
  • sendMediaTemplate
  • sendReceiptTemplate
  • sendAirlineBoardingPassTemplate
  • sendAirlineCheckinTemplate
  • sendAirlineItineraryTemplate
  • sendAirlineFlightUpdateTemplate
  • sendSenderAction
  • markSeen
  • typingOn
  • typingOff
  • associateLabel
  • dissociateLabel
  • getAssociatedLabels
LINE
  • sendText
  • sendImage
  • sendVideo
  • sendAudio
  • sendLocation
  • sendSticker
  • sendImagemap
  • sendButtonTemplate
  • sendConfirmTemplate
  • sendCarouselTemplate
  • sendImageCarouselTemplate
  • reply
  • replyText
  • replyImage
  • replyVideo
  • replyAudio
  • replyLocation
  • replySticker
  • replyImagemap
  • replyButtonTemplate
  • replyConfirmTemplate
  • replyCarouselTemplate
  • replyImageCarouselTemplate
  • sendImageCarouselTemplate
  • push
  • pushText
  • pushImage
  • pushVideo
  • pushAudio
  • pushLocation
  • pushSticker
  • pushImagemap
  • pushButtonTemplate
  • pushConfirmTemplate
  • pushCarouselTemplate
  • pushImageCarouselTemplate
  • getLinkedRichMenu
  • linkRichMenu
  • unlinkRichMenu
Slack
  • sendText
  • postMessage
Telegram
  • sendText
  • sendMessage
  • sendPhoto
  • sendAudio
  • sendDocument
  • sendSticker
  • sendVideo
  • sendVoice
  • sendVideoNote
  • sendLocation
  • sendVenue
  • sendContact
  • sendChatAction
Viber
  • sendMessage
  • sendText
  • sendPicture
  • sendVideo
  • sendFile
  • sendContact
  • sendLocation
  • sendURL
  • sendSticker
  • sendCarouselContent
FB
  • sendComment
  • sendPrivateReply

License

MIT © Yoctol

Keywords

FAQs

Package last updated on 14 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc