From 985fe08b462decf428f56082d951a8e045d5b0c9 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:37:44 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- .../examples/thermostat-bot/thermostat-bot.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 js/ui/botui/examples/thermostat-bot/thermostat-bot.js diff --git a/js/ui/botui/examples/thermostat-bot/thermostat-bot.js b/js/ui/botui/examples/thermostat-bot/thermostat-bot.js new file mode 100644 index 0000000..007fe79 --- /dev/null +++ b/js/ui/botui/examples/thermostat-bot/thermostat-bot.js @@ -0,0 +1,62 @@ +var botui = new BotUI('thermostat-bot'), + temperature = 30; + +function init() { + botui.message + .bot({ + delay: 700, + content: 'What would you like to do?' + }) + .then(function () { + return botui.action.button({ + delay: 1000, + action: [{ + text: 'Check temperature', + value: 'check' + }, { + text: 'Change temperature', + value: 'change' + }] + }) + }).then(function (res) { + if(res.value == 'change') { + changeTemp(); + } else { + botui.message.bot({ + delay: 1200, + content: 'Current temperature is: ' + temperature + ' degree' + }).then(init); + } + }); +} + +var changeTemp = function () { + botui.message + .bot({ + delay: 500, + content: 'Change the temperature to ...' + }) + .then(function () { + return botui.action.text({ + delay: 1000, + action: { + size: 10, + icon: 'thermometer-empty', + value: temperature, // show the current temperature as default + sub_type: 'number', + placeholder: '26' + } + }) + }).then(function (res) { + temperature = res.value; // save new value + return botui.message + .bot({ + delay: 1500, + loading: true, // pretend like we are doing something + content: 'temperature set to ' + res.value + }); + }).then(init); // loop to initial state +} + + +init();