javascript - 没有从机器人模拟器获取数据到 blob 存储?
问题描述
我有一个使用 c# 在框架 v4 中制作的机器人。我想将对话从我的机器人保存到 blob 存储中。我已经在天蓝色的存储中创建了一个容器。我在 Microsoft 框架提供的示例中使用了相同的连接字符串,对话通过 blob 进行,其中包含我的姓名和年龄等信息。但是当我将它与我的机器人一起使用时,会在 blob 上创建一个文件,但它没有任何对话数据。请帮助我解决这个问题。这是我正在处理 blob 的文件
{"$type":"System.Collections.Concurrent.ConcurrentDictionary`2[[System.String,
System.Private.CoreLib],[System.Object, System.Private.CoreLib]],
System.Collections.Concurrent","DialogState":
{"$type":"Microsoft.Bot.Builder.Dialogs.DialogState,
Microsoft.Bot.Builder.Dialogs","dialogStack":
{"$type":"System.Collections.Generic.List`1[[Microsoft.Bot.Builder.Dialogs.DialogInstance,
Microsoft.Bot.Builder.Dialogs]], System.Private.CoreLib","$values":[]}}}
解决方案
用户消息应该在$values
,就像
"$values":["a boy","two boys","3 boys"]
请确保您已将用户消息保存到您的存储中。
await _myStorage.WriteAsync(changes, cancellationToken);
ActivityHandler 如下:
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Builder.Azure;
using System.Linq;
namespace Microsoft.BotBuilderSamples.Bots
{
public class EchoBot : ActivityHandler
{
private static readonly AzureBlobStorage _myStorage = new AzureBlobStorage("XXX", "mybotuserlogs");
// Create local Memory Storage.
//private static readonly MemoryStorage _myStorage = new MemoryStorage();
// Create cancellation token (used by Async Write operation).
public CancellationToken cancellationToken { get; private set; }
// Class for storing a log of utterances (text of messages) as a list.
public class UtteranceLog : IStoreItem
{
// A list of things that users have said to the bot
public List<string> UtteranceList { get; } = new List<string>();
// The number of conversational turns that have occurred
public int TurnNumber { get; set; } = 0;
// Create concurrency control where this is used.
public string ETag { get; set; } = "*";
}
// Echo back user input.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
// preserve user input.
var utterance = turnContext.Activity.Text;
// make empty local logitems list.
UtteranceLog logItems = null;
// see if there are previous messages saved in storage.
try
{
string[] utteranceList = { "UtteranceLog" };
logItems = _myStorage.ReadAsync<UtteranceLog>(utteranceList).Result?.FirstOrDefault().Value;
}
catch
{
// Inform the user an error occured.
await turnContext.SendActivityAsync("Sorry, something went wrong reading your stored messages!");
}
// If no stored messages were found, create and store a new entry.
if (logItems is null)
{
// add the current utterance to a new object.
logItems = new UtteranceLog();
logItems.UtteranceList.Add(utterance);
// set initial turn counter to 1.
logItems.TurnNumber++;
// Show user new user message.
await turnContext.SendActivityAsync($"{logItems.TurnNumber}: The list is now: {string.Join(", ", logItems.UtteranceList)}");
// Create Dictionary object to hold received user messages.
var changes = new Dictionary<string, object>();
{
changes.Add("UtteranceLog", logItems);
}
try
{
// Save the user message to your Storage.
await _myStorage.WriteAsync(changes, cancellationToken);
}
catch
{
// Inform the user an error occured.
await turnContext.SendActivityAsync("Sorry, something went wrong storing your message!");
}
}
// Else, our Storage already contained saved user messages, add new one to the list.
else
{
// add new message to list of messages to display.
logItems.UtteranceList.Add(utterance);
// increment turn counter.
logItems.TurnNumber++;
// show user new list of saved messages.
await turnContext.SendActivityAsync($"{logItems.TurnNumber}: The list is now: {string.Join(", ", logItems.UtteranceList)}");
// Create Dictionary object to hold new list of messages.
var changes = new Dictionary<string, object>();
{
changes.Add("UtteranceLog", logItems);
};
try
{
// Save new list to your Storage.
await _myStorage.WriteAsync(changes, cancellationToken);
}
catch
{
// Inform the user an error occured.
await turnContext.SendActivityAsync("Sorry, something went wrong storing your message!");
}
}
}
}
}
参考:
推荐阅读
- python - 无法从 pandas_ml 的“sklearn.preprocessing”导入名称“Imputer”
- java - 哪个更优化?多条记录还是一条带有 CLOB 列的记录?
- php - 使用 composer Windows 10 安装 laravel 时出错
- python - 如何将多个值关联到一个字典键?
- java - Compiler says variable has not been initialized
- influxdb - “高基数”字段(或标签)上的 InfluxDB WHERE 子句
- scala - spark scala 将嵌套数据框转换为嵌套数据集
- javascript - 在反应应用程序中安装 Node fs 模块或以其他方式创建目录列表?
- emotion - 何时使用样式化组件与何时在情感中使用 css 道具?
- php - 如何获取我刚刚添加的 id?