bottender-compose
Advanced tools
Changelog
0.12.2 / 2018-09-05
use param
to access object values that provided as sencond argument when calling action:
B.sendText('User: {{param.name}}')(context, { name: 'Super User' });
Changelog
0.12.1 / 2018-09-05
attachOptions
.Changelog
0.12.0 / 2018-09-05
attachOptions
:attachOptions
Attaches additional options to the action.
const { attachOptions, sendText } = require('bottender-compose');
bot.onEvent(
attachOptions({ tag: 'ISSUE_RESOLUTION' }, sendText('Issue Resolved'))
);
// curry function
const attachIssueResolutionTag = attachOptions({ tag: 'ISSUE_RESOLUTION' });
bot.onEvent(attachIssueResolutionTag(sendText('Issue Resolved')));
Changelog
0.11.0 / 2018-08-27
isTextMatch
Creates a predicate function to return true when text matches.
const { isTextMatch } = require('bottender-compose');
isTextMatch('abc')(context); // boolean
isTextMatch(/abc/)(context); // boolean
isPayloadMatch
Creates a predicate function to return true when payload matches.
const { isPayloadMatch } = require('bottender-compose');
isPayloadMatch('abc')(context); // boolean
isPayloadMatch(/abc/)(context); // boolean
hasStateEqual
Creates a predicate function to return true when state matches.
const { hasStateEqual } = require('bottender-compose');
hasStateEqual('x', 1)(context); // boolean
hasStateEqual('x.y.z', 1)(context); // boolean
hasStateEqual('x', { y: { z: 1 } })(context); // boolean
not
Creates a predicate function with not condition.
const { not, hasStateEqual } = require('bottender-compose');
const predicate = not(hasStateEqual('x', 1));
predicate(context); // boolean
and
Creates a predicate function with and condition.
const { and, hasStateEqual } = require('bottender-compose');
const predicate = and([
isTextMatch('abc'),
hasStateEqual('x', 1))
]);
predicate(context) // boolean
or
Creates a predicate function with or condition.
const { or, hasStateEqual } = require('bottender-compose');
const predicate = or([
isTextMatch('abc'),
hasStateEqual('x', 1))
]);
predicate(context) // boolean
alwaysTrue
Creates a predicate function that always return true
.
const { alwaysTrue } = require('bottender-compose');
const predicate = alwaysTrue();
predicate(context); // true
alwaysFalse
Creates a predicate function that always return false
.
const { alwaysFalse } = require('bottender-compose');
const predicate = alwaysFalse();
predicate(context); // false
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
isMessage
isText
isImage
isVideo
isAudio
isLocation
isSticker
isFollow
isUnfollow
isJoin
isLeave
isPostback
isPayload
isBeacon
isAccountLink
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
isMessage
isText
isAudio
isDocument
isGame
isPhoto
isSticker
isVideo
isVoice
isVideoNote
isContact
isLocation
isVenue
isEditedMessage
isChannelPost
isEditedChannelPost
isInlineQuery
isChosenInlineResult
isCallbackQuery
isPayload
isShippingQuery
isPreCheckoutQuery
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
Changelog
0.10.3 / 2018-08-08
Changelog
0.10.2 / 2018-07-25
{{user.xxx}}
in template.Changelog
0.10.1 / 2018-05-16
Changelog
0.10.0 / 2018-05-16
Changelog
0.9.1 / 2018-05-07
B.series([
B.log('sending hello'),
B.info('sending hello'),
B.warn('sending hello'),
B.error('sending hello'),
B.sendText('hello'),
]);
It supports template too.
B.series([
B.log('user: {{ session.user.id }} x: {{ state.x }}'),
B.sendText('hello'),
]);
You can use your owner adapter for the logger:
const { log, info, warn, error } = B.createLogger({
log: debug('log'),
info: debug('info'),
warn: debug('warn'),
error: debug('error'),
});
B.series([log('sending hello'), B.sendText('hello')]);
Changelog
0.9.0 / 2018-05-06
effect
:const { effect } = require('bottender-compose');
bot.onEvent(
effect(
// function has side effects
async context => {
await doSomeSideEffects();
return {
derivedState: {
x: 1,
},
derivedParam: {
y: 2,
},
};
},
// action
async (context, param) => {
console.log(context.state.x); // 1
console.log(param.y); // 2
}
)
);