【问题标题】:Store conversation data with bot as entity into Azure storage table (Node.js)将与 bot 的对话数据作为实体存储到 Azure 存储表 (Node.js)
【发布时间】:2018-09-21 04:33:18
【问题描述】:

我目前正在研究 Bot,在我的项目中,我想存储 bot 数据(即用户、对话和私人对话属性包),基本上是用户输入和使用 Node.js 在 azure 存储中返回的响应。我可以登录控制台,但不能登录 azure 存储。

请告诉我如何实现上述概念。

【问题讨论】:

标签: node.js azure azure-storage botframework bots


【解决方案1】:

要在 Azure 表存储中存储对话状态数据,您可以轻松利用 Manage custom state data with Azure Table storage for Node.js

要存储整个对话消息历史记录,您可以利用 receivesend 中间件,添加自定义逻辑以将历史记录插入到 talbe 存储中。请考虑以下代码 sn-p:

bot.use({
    receive: (evt, next) => {
        console.log(evt);
        if (evt.type == 'message') {
            azureTableClient.insertOrReplace(evt.address.user.id + `-` + new Date().valueOf(), evt.type, `[USER to BOT]: ${evt.text}`, false, ((err, etag, res) => {
                if (err) {
                    console.log(er)
                }
            }))
        }
        next();
    },
    send: (evt, next) => {
        // console.log(evt);
        azureTableClient.insertOrReplace(evt.address.user.id + `-` + new Date().valueOf(), evt.type, `[BOT to USER]: ${evt.text}`, false, ((err, etag, res) => {
            if (err) {
                console.log(er)
            }
        }))
        next();
    }
})

【讨论】:

    猜你喜欢
    • 2016-09-19
    • 2020-02-24
    • 2020-12-21
    • 2018-01-11
    • 2013-10-14
    • 1970-01-01
    • 2012-12-20
    • 2016-10-17
    • 1970-01-01
    相关资源
    最近更新 更多