我正在尝试使用botui,这是一个用于显示聊天机器人的JavaScript框架。
botui documentation建议可以从input types listed here的sub_type
中选择
我希望能够使用它来选择一个图像文件(使用sub_type: 'file'
),然后对其执行操作(base64对其进行编码并发送信息)。在示例代码中,我尝试使用以下方式仅发送有关图像的一些信息(DOMString according to this documentation)作为后续消息:
content: 'Image information: ' + res.value
有人可以建议如何将有关文件的信息放入代码中,以便我可以使用它吗?
The code can be seen on JSFiddle
或此处的html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="https://unpkg.com/botui/build/botui.min.css" />
<link rel="stylesheet" href="https://unpkg.com/botui/build/botui-theme-default.css" />
<meta name="description" content="bot.">
</head>
<body>
<div class="botui-app-container" id="bot">
<bot-ui></bot-ui>
</div>
<script src="https://cdn.jsdelivr.net/vue/latest/vue.min.js"></script>
<script src="https://unpkg.com/botui/build/botui.js"></script>
<script src="./bot.js"></script>
</body>
</html>
和这里的js:
var botui = new BotUI('bot');
info_0_1 = `Hi, how are you?`
info_0_2 = `I hope you are well`
var askReference = function () {
displayMessage(2000, 'Please select an image file:')
.then(function () {
return botui.action.text({
delay: 1000,
action: {
sub_type: 'file',
accept: 'image/*'
}
})
}).then(function (res) {
botui.message
.bot({
delay: 100,
content: 'Image information: ' + res.value
});
reference = res.value; // save address
});
}
const displayMessage = (delay, content) => {
return botui.message.bot({
delay,
photo: '/imgs/bot.jpg',
content
})
};
const displayMessages = () => {
return displayMessage(0, info_0_1)
.then(displayMessage(1000, info_0_2))
};
var main = function () {
displayMessages()
.then(askReference)
}
main()