Mon 21 Jul 22:43:21 CEST 2025
This commit is contained in:
parent
7b2fa63216
commit
d49c075a95
86
js/ui/botui/examples/delivery-bot/delivery-bot.js
Normal file
86
js/ui/botui/examples/delivery-bot/delivery-bot.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
var botui = new BotUI('delivery-bot'),
|
||||
address = 'House 1, First Ave.';
|
||||
|
||||
botui.message
|
||||
.bot('Where would you like the package to be delivered?')
|
||||
.then(function () {
|
||||
return botui.action.button({
|
||||
delay: 1000,
|
||||
addMessage: false, // so we could the address in message instead if 'Existing Address'
|
||||
action: [{
|
||||
text: 'Existing Address',
|
||||
value: 'exist'
|
||||
}, {
|
||||
text: 'Add New Address',
|
||||
value: 'new'
|
||||
}]
|
||||
})
|
||||
}).then(function (res) {
|
||||
if(res.value == 'exist') {
|
||||
botui.message.human({
|
||||
delay: 500,
|
||||
content: address
|
||||
});
|
||||
end();
|
||||
} else {
|
||||
botui.message.human({
|
||||
delay: 500,
|
||||
content: res.text
|
||||
});
|
||||
askAddress();
|
||||
}
|
||||
});
|
||||
|
||||
var askAddress = function () {
|
||||
botui.message
|
||||
.bot({
|
||||
delay: 500,
|
||||
content: 'Please write your address below:'
|
||||
})
|
||||
.then(function () {
|
||||
return botui.action.text({
|
||||
delay: 1000,
|
||||
action: {
|
||||
size: 30,
|
||||
icon: 'map-marker',
|
||||
value: address, // show the saved address if any
|
||||
placeholder: 'Address'
|
||||
}
|
||||
})
|
||||
}).then(function (res) {
|
||||
botui.message
|
||||
.bot({
|
||||
delay: 500,
|
||||
content: 'New address: ' + res.value
|
||||
});
|
||||
|
||||
address = res.value; // save address
|
||||
|
||||
return botui.action.button({
|
||||
delay: 1000,
|
||||
action: [{
|
||||
icon: 'check',
|
||||
text: 'Confirm',
|
||||
value: 'confirm'
|
||||
}, {
|
||||
icon: 'pencil',
|
||||
text: 'Edit',
|
||||
value: 'edit'
|
||||
}]
|
||||
})
|
||||
}).then(function (res) {
|
||||
if(res.value == 'confirm') {
|
||||
end();
|
||||
} else {
|
||||
askAddress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var end = function () {
|
||||
botui.message
|
||||
.bot({
|
||||
delay: 1000,
|
||||
content: 'Thank you. Your package will shipped soon.'
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user