Microsoft Bot Framework:保存聊天记录 [英] Microsoft Bot Framework: Saving the chat history

查看:116
本文介绍了Microsoft Bot Framework:保存聊天记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用bot框架创建了一个简单的聊天机器人,并且现在我试图将bot的聊天记录保存在本地设备上.我已经使用fs将用户输入的值/参数保存到文件中.例如:他们的名字.

I've created a simple chatbot using bot framework and i'm trying to save the bot's chat history locally on my device for now. I've used fs to save the values/arguments the user enters, into a file. For e.g.: their name.

但是,我想包含整个聊天对话,即用户发送的消息和漫游器给出的回复.我尝试使用fs.appendFile(filename, session, function(err)捕获这些对话框,但它仅在文件中显示[Object object].

However, I want to include the whole chat conversation i.e. the message the user sends and the reply the bot gives. I tried using fs.appendFile(filename, session, function(err) to capture those dialogs but it just displays [Object object] in the file.

如何捕获整个聊天记录?或者至少是用户发送的任何内容?

How can I capture the whole chat history? Or at least whatever the user has sent?

我的代码示例:

var restify = require('restify');
var builder = require('botbuilder');


//=========================================================
// Bot Setup
//=========================================================

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat bot
var connector = new builder.ChatConnector({
    appId: ''
    appPassword: ''
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());

server.get('/', restify.serveStatic({
 directory: __dirname,
 default: '/index.html'
}));


var fs = require("fs");
var filename = 'chathistory.json';

//=========================================================
// Bots Dialogs
//=========================================================

var test="test";

bot.dialog('/', new builder.IntentDialog()
    .matchesAny([/hi/i, /hello/i], [
        function (session) {
            session.send('Hi, I am your chatbot.');
    session.beginDialog('/step2')
    },

    bot.dialog('/step2', [
     function (session) {
    builder.Prompts.text(session,'What is your name?');
     },
     function(session, args, next) {
        test="  , "  +args.response;
        fs.appendFile(filename, test, function(err){
        });
         session.send('Hello, ' + args.response + '. How may I help you today?');
         name = args.response;
         session.endConversation();
     }
    ])
    ])
);

推荐答案

捕获用户输入和机器人输入的一种方法是使用middleware.看看 middlewareLogging 示例,其中正在展示日志记录方案.

One way to capture user input and bot input is using middleware. Take a look at the middlewareLogging sample, where the logging scenario is being showcased.

这篇关于Microsoft Bot Framework:保存聊天记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆