[yotroy.cool]给博客配置botui添加对话交互框架-以halo博客为例

1 篇文章 0 订阅
1 篇文章 0 订阅

个人博客https://www.yotroy.cool/,欢迎关注我哦~

============================================================

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/LIlGG_Sakura/source/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 +'。感谢你来看我!'
                });
        })
}

============================================================

未经作者授权,禁止转载;如需转载,请标明出处。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值