bottender-compose
An utility library for Bottender and higher-order handlers
Installation
npm install bottender-compose
API Reference
TOC
Actions
series()
Creates a function that executes methods in series.
const series sendText = ; module { return ;};
parallel()
Creates a function that executes methods in parallel.
const parallel sendText = ; module { return ;};
random()
Creates a function that executes one of method randomly.
const random sendText = ; module { return ;};
branch()
Creates a function that will process either the onTrue
or the onFalse
function depending upon the result of the condition predicate.
Furthermore, branch
can be sued as curry function.
const branch sendText = ; module { return ;}; // curry functionconst trueConditionBranch = ; module { return ;};
Or you can executes function on true
and do nothing when received false
.
;
branch
works well with predicates.
condition()
Creates a function that encapsulates if/else
, if/else
, ... logic.
const condition sendText = ; module { return ;};
condition
works well with predicates.
match()
Creates a function that encapsulates value matching logic.
const match sendText = ; module { return ;};
It accepts function with context
argument:
module { return ;}; // curry functionconst matchAnswer = ; module { return ;};
To assign default action, use _
as pattern:
const _ match sendText = ; module { return };
platform()
Creates a function that will process function depending upon the platform context.
const platform sendGenericTemplate sendImagemap = ; module { return ;};
Or you can use others
key to match other platforms:
;
weight()
Creates a function that randomly executes one of method by its weight.
const weight sendText = ; module { return ;};
noop()
Creates a no-op function.
const branch sendText noop = ; module { return ;};
repeat()
Creates a function that executes the method repeatedly.
Furthermore, repeat
can be sued as curry function.
const repeat sendText = ; module { return ;}; // curry functionconst repeatFiveTimes = ; module { return };
delay()
Creates a function that executes methods after a number of milliseconds.
const series delay sendText = ; module { return ;};
setDisplayName()
Assigns to the displayName
property on the action.
const setDisplayName sendText = ; ; // curry function;
attachOptions()
Attaches additional options to the action.
const attachOptions sendText = ; module { return ;}; // curry functionconst attachIssueResolutionTag = ; module { reutnr ;};
Logger Methods
B;
It supports template too.
B;
You can use your owner adapter for the logger:
const log info warn error = B; B;
Context Methods
Common
setState()
resetState()
typing()
Messenger
sendMessage()
sendText()
sendAttachment()
sendAudio()
sendImage()
sendVideo()
sendFile()
sendTemplate()
sendButtonTemplate()
sendGenericTemplate()
sendListTemplate()
sendOpenGraphTemplate()
sendMediaTemplate()
sendReceiptTemplate()
sendAirlineBoardingPassTemplate()
sendAirlineCheckinTemplate()
sendAirlineItineraryTemplate()
sendAirlineUpdateTemplate()
sendSenderAction()
markSeen()
typingOn()
typingOff()
passThreadControl()
passThreadControlToPageInbox()
takeThreadControl()
requestThreadControl()
associateLabel()
dissociateLabel()
LINE
sendText()
sendImage()
sendVideo()
sendAudio()
sendLocation()
sendSticker()
sendImagemap()
sendButtonTemplate()
sendConfirmTemplate()
sendCarouselTemplate()
sendImageCarouselTemplate()
reply()
replyText()
replyImage()
replyVideo()
replyAudio()
replyLocation()
replySticker()
replyImagemap()
replyButtonTemplate()
replyConfirmTemplate()
replyCarouselTemplate()
replyImageCarouselTemplate()
push()
pushText()
pushImage()
pushVideo()
pushAudio()
pushLocation()
pushSticker()
pushImagemap()
pushButtonTemplate()
pushConfirmTemplate()
pushCarouselTemplate()
pushImageCarouselTemplate()
linkRichMenu()
unlinkRichMenu()
Slack
sendText()
postMessage()
postEphemeral()
Telegram
sendText()
sendMessage()
sendPhoto()
sendAudio()
sendDocument()
sendSticker()
sendVideo()
sendVoice()
sendVideoNote()
sendMediaGroup()
sendLocation()
sendVenue()
sendContact()
sendChatAction()
editMessageText()
editMessageCaption()
editMessageReplyMarkup()
deleteMessage()
editMessageLiveLocation()
stopMessageLiveLocation()
forwardMessageFrom()
forwardMessageTo()
kickChatMember()
unbanChatMember()
restrictChatMember()
promoteChatMember()
exportChatInviteLink()
setChatPhoto()
deleteChatPhoto()
setChatTitle()
setChatDescription()
setChatStickerSet()
deleteChatStickerSet()
pinChatMessage()
unpinChatMessage()
leaveChat()
sendInvoice()
answerShippingQuery()
answerPreCheckoutQuery()
answerInlineQuery()
sendGame()
setGameScore()
Viber
sendMessage()
sendText()
sendPicture()
sendVideo()
sendFile()
sendContact()
sendLocation()
sendURL()
sendSticker()
sendCarouselContent()
sendComment()
sendPrivateReply()
sendLike()
Passing Function as Argument to Context Method
You can pass function as argument to handle time-specified or context-specified case, for example:
// Lazy executionB; // Use event informationB;
Use Template in String
You can use context
, session
, event
, state
to access values in your template string:
B;B;
Or use props
to access object values that provided as props when calling action:
Bcontext name: 'Super User' ;
Predicates
isTextMatch()
Creates a predicate function to return true when text matches.
const isTextMatch = ; context; // booleancontext; // boolean
isPayloadMatch()
Creates a predicate function to return true when payload matches.
const isPayloadMatch = ; context; // booleancontext; // boolean
hasStateEqual()
Creates a predicate function to return true when state matches.
const hasStateEqual = ; context; // booleancontext; // booleancontext; // boolean
not()
Creates a predicate function with not condition.
const not hasStateEqual = ; const predicate = ; ; // boolean
and()
Creates a predicate function with and condition.
const and hasStateEqual = ; const predicate = ); // boolean
or()
Creates a predicate function with or condition.
const or hasStateEqual = ; const predicate = ); // boolean
alwaysTrue
Creates a predicate function that always return true
.
const alwaysTrue = ; const predicate = ; ; // true
alwaysFalse
Creates a predicate function that always return false
.
const alwaysFalse = ; const predicate = ; ; // false
Event Predicates
Messenger
isMessage()
isText()
hasAttachment()
isImage()
isAudio()
isVideo()
isLocation()
isFile()
isFallback()
isSticker()
isLikeSticker()
isQuickReply()
isEcho()
isPostback()
isGamePlay()
isOptin()
isPayment()
isCheckoutUpdate()
isPreCheckout()
isRead()
isDelivery()
isPayload()
isPolicyEnforcement()
isAppRoles()
isStandby()
isPassThreadControl()
isTakeThreadControl()
isRequestThreadControl()
isRequestThreadControlFromPageInbox()
isFromCustomerChatPlugin()
isReferral()
isBrandedCamera()
LINE
isMessage()
isText()
isImage()
isVideo()
isAudio()
isLocation()
isSticker()
isFollow()
isUnfollow()
isJoin()
isLeave()
isPostback()
isPayload()
isBeacon()
isAccountLink()
Slack
isMessage()
isChannelsMessage()
isGroupsMessage()
isImMessage()
isMpimMessage()
isText()
isInteractiveMessage()
isAppUninstalled()
isChannelArchive()
isChannelCreated()
isChannelDeleted()
isChannelHistoryChanged()
isChannelRename()
isChannelUnarchive()
isDndUpdated()
isDndUpdated_user()
isEmailDomainChanged()
isEmojiChanged()
isFileChange()
isFileCommentAdded()
isFileCommentDeleted()
isFileCommentEdited()
isFileCreated()
isFileDeleted()
isFilePublic()
isFileShared()
isFileUnshared()
isGridMigrationFinished()
isGridMigrationStarted()
isGroupArchive()
isGroupClose()
isGroupHistoryChanged()
isGroupOpen()
isGroupRename()
isGroupUnarchive()
isImClose()
isImCreated()
isImHistoryChanged()
isImOpen()
isLinkShared()
isMemberJoinedChannel()
isMemberLeftChannel()
isPinAdded()
isPinRemoved()
isReactionAdded()
isReactionRemoved()
isStarAdded()
isStarRemoved()
isSubteamCreated()
isSubteamMembersChanged()
isSubteamSelfAdded()
isSubteamSelfRemoved()
isSubteamUpdated()
isTeamDomainChange()
isTeamJoin()
isTeamRename()
isTokensRevoked()
isUrlVerification()
isUserChange()
Telegram
isMessage()
isText()
isAudio()
isDocument()
isGame()
isPhoto()
isSticker()
isVideo()
isVoice()
isVideoNote()
isContact()
isLocation()
isVenue()
isEditedMessage()
isChannelPost()
isEditedChannelPost()
isInlineQuery()
isChosenInlineResult()
isCallbackQuery()
isPayload()
isShippingQuery()
isPreCheckoutQuery()
Viber
isMessage()
isText()
isPicture()
isVideo()
isFile()
isSticker()
isContact()
isURL()
isLocation()
isSubscribed()
isUnsubscribed()
isConversationStarted()
isDelivered()
isSeen()
isFailed()
isFeed()
isStatus()
isStatusAdd()
isStatusEdited()
isPost()
isPostRemove()
isComment()
isCommentAdd()
isCommentEdited()
isCommentRemove()
isLike()
isLikeAdd()
isLikeRemove()
isReaction()
isReactionAdd()
isReactionEdit()
isReactionRemove()
License
MIT © Yoctol