首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有从机器人仿真器获取数据到blob存储?

没有从机器人仿真器获取数据到blob存储?
EN

Stack Overflow用户
提问于 2019-12-27 19:04:28
回答 1查看 354关注 0票数 1

我有一个机器人在框架v4中使用c#.i要保存我的机器人到blob存储中的对话。我已经在azure上创建了一个容器来存储。我使用了与微软框架提供的示例相同的连接字符串,对话来自blob,其中包含我的姓名和年龄等信息。但当我在我的机器人上使用它时,在blob上创建了一个文件,但它没有任何对话data.Kindly来帮助我解决这个问题。这是我正在处理的blob文件

代码语言:javascript
复制
{"$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":[]}}}
EN

回答 1

Stack Overflow用户

发布于 2019-12-30 12:35:32

用户消息应该是$values格式的,就像

代码语言:javascript
复制
"$values":["a boy","two boys","3 boys"]

请确保您已将用户消息保存到您的存储区。

代码语言:javascript
复制
await _myStorage.WriteAsync(changes, cancellationToken);

ActivityHandler如下:

代码语言:javascript
复制
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!");
                }
            }

        }
    }
}

参考资料:

Write directly to storage

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59499827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档