简体   繁体   English

没有从机器人模拟器获取数据到 Blob 存储?

[英]Not geting data from bot emulator into blob storage?

i have a bot made in framework v4 using c#.i want to save the conversation from my bot into blob store.我有一个使用 c# 在框架 v4 中制作的机器人。我想将对话从我的机器人保存到 Blob 存储中。 I have create a container into storage on azure.我已经在 azure 上创建了一个容器到存储中。 I used the same connection string with the samples provided by Microsoft framework, the conversation is coming over blob having information like my name and age.我使用了与 Microsoft 框架提供的示例相同的连接字符串,对话来自包含我的姓名和年龄等信息的 blob。 But when i am using it with my bot , a file is create over the blob but it doesnot have any conversation data.Kindly help me out with this.但是当我将它与我的机器人一起使用时,会在 blob 上创建一个文件,但它没有任何对话数据。请帮助我解决这个问题。 Here is file i am getting over the 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":[]}}}

The user message should be in $values , just like用户消息应该在$values ,就像

"$values":["a boy","two boys","3 boys"]

Please make sure you have saved the user message to your storage.请确保您已将用户消息保存到您的存储中。

await _myStorage.WriteAsync(changes, cancellationToken);

The ActivityHandler is as below: 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!");
                }
            }

        }
    }
}

Reference:参考:

Write directly to storage 直接写入存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM