bottender-compose
Advanced tools
Changelog
0.8.4 / 2018-04-26
setDisplayName
Changelog
0.8.3 / 2018-04-12
Changelog
0.8.2 / 2018-04-09
setDisplayName
:Assigns to the displayName
property on the action.
const { setDisplayName, sendText } = require('bottender-compose');
setDisplayName('sayHello', sendText('hello'));
// curry function
setDisplayName('sayHello')(sendText('hello'));
Changelog
0.8.0 / 2018-04-02
You can use context
, session
, event
, state
to access values in your template string:
B.sendText('Hi, {{session.user.first_name}} {{session.user.last_name}}');
B.sendText('Received: {{event.text}}');
B.sendText('State: {{state.xxx}}');
match
:Create a function that encapsulates value matching logic.
const { match, sendText } = require('bottender-compose');
bot.onEvent(
match('a', [
['a', sendText('You got a A')],
['b', sendText('You got a B')],
['c', sendText('You got a C')],
])
);
It accepts function with context
argument:
bot.onEvent(
match(context => context.state.answer, [
['a', sendText('You got a A')],
['b', sendText('You got a B')],
['c', sendText('You got a C')],
])
);
// curry function
const matchAnswer = match(context => context.state.answer);
bot.onEvent(
matchAnswer([
['a', sendText('You got a A')],
['b', sendText('You got a B')],
['c', sendText('You got a C')],
])
);
To assign default action, use _
as pattern:
const { _, match, sendText } = require('bottender-compose');
bot.onEvent(
match('a', [
['a', sendText('You got a A')],
['b', sendText('You got a B')],
['c', sendText('You got a C')],
[_, sendText('You got something')],
])
);
Changelog
0.7.0 / 2018-03-31
// curry branch
const trueConditionBranch = branch(context => true);
bot.onEvent(
trueConditionBranch(sendText('You are the lucky one.'), sendText('Too bad.'))
);
// curry repeat
const repeatFiveTimes = repeat(5);
bot.onEvent(repeatFiveTimes(sendText('This will be sent 5 times.')));
// curry tryCatch
const mayFailTryCatch = tryCatch(doSomethingMayFail());
bot.onEvent(mayFailTryCatch(sendText('Error Happened~~~~~~~~~~~!')));
const action = (context, ...otherArgs) => {};
Changelog
0.6.2 / 2018-03-22
telegram:
editMessageText
editMessageCaption
editMessageReplyMarkup
deleteMessage
editMessageLiveLocation
stopMessageLiveLocation
forwardMessageFrom
forwardMessageTo
[removed] remove useless
messenger:
getAssociatedLabels
line:
getLinkedRichMenu
Changelog
0.6.1 / 2018-03-21
messenger:
requestThreadControl
slack:
postEphemeral
telegram:
kickChatMember
unbanChatMember
restrictChatMember
promoteChatMember
exportChatInviteLink
setChatPhoto
deleteChatPhoto
setChatTitle
setChatDescription
setChatStickerSet
deleteChatStickerSet
pinChatMessage
unpinChatMessage
leaveChat
answerShippingQuery
answerPreCheckoutQuery
answerInlineQuery
Changelog
0.6.0 / 2018-03-21
You can pass function as argument to handle time-specified or context-specified case, for example:
// Lazy execution
B.sendText(() => `Now: ${new Date()}`);
// Use user information on context
B.sendText(
context =>
`${context.session.user.first_name} ${context.session.user.last_name}, You are the lucky one.`
);
// Use event information
B.sendText(context => `Received: ${context.event.text}`);
Changelog
0.5.1 / 2017-12-20
passThreadControl
passThreadControlToPageInbox
takeThreadControl
sendMediaGroup
sendInvoice
sendGame
setGameScore