𝖄𝕺🌎𝕿𝕽𝕺¥

𝖄𝕺🌎𝕿𝕽𝕺¥

𝕴 𝖉𝖔 𝖒𝖆𝖌𝖎𝖈
github

给博客配置botui添加对话交互框架-以halo博客为例

Botui#

GitHub - botui/botui: 🤖 A JavaScript framework to create conversational UIs

配置#

参考官方 Github 文档,现提供 halo 博客的解决方案,演示效果及其代码放在文末。

配置<head>#

【后台 - 系统 - 其他设置 - 自定义内容页 head】

<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" />

配置内容页#

在内容页键入如下即可应用

<div class="botui-app-container" id="example"><!-- id要对应 -->
  <bot-ui></bot-ui>
</div>
<script src="https://cdn.jsdelivr.net/vue/2.0.5/vue.min.js"></script>
<script src="https://unpkg.com/botui/build/botui.js"></script>
<script src="/themes/source/botui/example.js"><!-- 交互js文件位置 -->//
</script>

其中交互 js 文件位置请自行修改,希望及时备份防止更新时被误删。

交互 js 文档#

接下来就是配置 js 交互文件了,这个还是得有一定 coding 基础。参考以下:
官方文档https://docs.botui.org/
Github 例子https://github.com/botui/botui-examples

bug#

在点击按钮等情况下会出现翻页情况

效果浏览#

如未显示请刷新页面。
example1

//example1
var botui = new BotUI('example1');//name要与id对应

botui.message.add({
  content: 'Hello World from bot!'
});

botui.message.add({
  human: true,
  content: 'Hello World from human!'
});

example2

//info
var botui = new BotUI('info');

botui.message.add({
    content: '!'
});

botui.message
    .bot({
        delay: 1000,
        content: 'Hi, 你好呀!'
    }).then(function () {
        return botui.action.button({
            delay: 1000,
            action: [{
                text: 'Hi',
                value: 'hi'
        },{
                text: '......',
                value: 'no_reply'
        }]
    })
}).then(function (res) {
    if(res.value == 'hi') {
        showReminderInput();
    } else {
        botui.message.bot('屁颠屁颠逃走了');
    }
});

var showReminderInput = function () {
    botui.message
        .bot({
            delay: 500,
            content: '我叫Lil Troy,你叫什么呀?'
        }).then(function () {
            return botui.action.text({
                delay: 3000,
                action:{
                    placeholder:'键入你的名字'
                }
            })
        }).then(function (user_name){
            botui.message
                .bot({
                    delay: 500,
                    content: '你好呀,' + user_name.value +'。感谢你来看我!'
                });
        })
}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。