我有一个机器人在框架v4中使用c#.i要保存我的机器人到blob存储中的对话。我已经在azure上创建了一个容器来存储。我使用了与微软框架提供的示例相同的连接字符串,对话来自blob,其中包含我的姓名和年龄等信息。但当我在我的机器人上使用它时,在blob上创建了一个文件,但它没有任何对话data.Kindly来帮助我解决这个问题。这是我正在处理的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":[]}}}发布于 2019-12-30 12:35:32
用户消息应该是$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!");
}
}
}
}
}参考资料:
https://stackoverflow.com/questions/59499827
复制相似问题