コード例 #1
0
        public async Task ActivityAddTest()
        {
            var loggedActivities = new IActivity[5];
            var activities       = new List <IActivity>();

            for (var i = 0; i < 5; i++)
            {
                var a = CreateActivity(i, i, ConversationIds);
                await _transcriptStore.LogActivityAsync(a);

                activities.Add(a);
                loggedActivities[i] = _transcriptStore.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[i]).Result.Items[0];
            }
            Assert.AreEqual(5, loggedActivities.Length);
        }
コード例 #2
0
        public async Task NullBlobTest()
        {
            AzureBlobTranscriptStore store = null;

            await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                       await store.LogActivityAsync(CreateActivity(0, 0, ConversationIds)));

            await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                       await store.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[0]));
        }
コード例 #3
0
ファイル: QnABot.cs プロジェクト: nickyjt16/tawk2botv2
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            await _myTranscripts.LogActivityAsync(turnContext.Activity);

            List <string> storedTranscripts = new List <string>();
            PagedResult <Microsoft.Bot.Builder.TranscriptInfo> pagedResult = null;
            var pageSize = 0;

            do
            {
                pagedResult = await _myTranscripts.ListTranscriptsAsync("emulator", pagedResult?.ContinuationToken);

                pageSize = pagedResult.Items.Count();

                // transcript item contains ChannelId, Created, Id.
                // save the channelIds found by "ListTranscriptsAsync" to a local list.
                foreach (var item in pagedResult.Items)
                {
                    storedTranscripts.Add(item.Id);
                }
            } while (pagedResult.ContinuationToken != null);

            var httpClient = _httpClientFactory.CreateClient();

            var qnaMaker = new QnAMaker(new QnAMakerEndpoint
            {
                KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
                EndpointKey     = _configuration["QnAEndpointKey"],
                Host            = _configuration["QnAEndpointHostName"]
            },
                                        null,
                                        httpClient);

            _logger.LogInformation("Calling QnA Maker");

            var options = new QnAMakerOptions {
                Top = 1
            };

            // The actual call to the QnA Maker service.
            var response = await qnaMaker.GetAnswersAsync(turnContext, options);

            if (response != null && response.Length > 0)
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
            }
            else
            {
                await turnContext.SendActivityAsync(MessageFactory.Text("I'll just pass your information to a human and we'll get look into your query. Please wait..."), cancellationToken);
            }
        }
コード例 #4
0
        public async Task NullBlobTest()
        {
            if (StorageEmulatorHelper.CheckEmulator())
            {
                ContainerInit();
                AzureBlobTranscriptStore store = null;

                await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                           await store.LogActivityAsync(CreateActivity(0, 0, ConversationIds)));

                await Assert.ThrowsExceptionAsync <NullReferenceException>(async() =>
                                                                           await store.GetTranscriptActivitiesAsync(ChannelId, ConversationIds[0]));
            }
        }
コード例 #5
0
ファイル: DialogBot.cs プロジェクト: sineadfarrell/Nasoto-Bot
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (ConversationData.PromptedUserForName)
            {
                ConversationData.PromptedUserForName = false;
                await turnContext.SendActivityAsync($"Bye");
            }
            else
            {
                // 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!");
                    }
                }
                await _myTranscripts.LogActivityAsync(turnContext.Activity);

                List <string> storedTranscripts = new List <string>();
                PagedResult <Microsoft.Bot.Builder.TranscriptInfo> pagedResult = null;
                var pageSize = 0;
                do
                {
                    pagedResult = await _myTranscripts.ListTranscriptsAsync("emulator", pagedResult?.ContinuationToken);

                    pageSize = pagedResult.Items.Count();

                    // transcript item contains ChannelId, Created, Id.
                    // save the channelIds found by "ListTranscriptsAsync" to a local list.
                    foreach (var item in pagedResult.Items)
                    {
                        storedTranscripts.Add(item.Id);
                    }
                } while (pagedResult.ContinuationToken != null);


                Logger.LogInformation("Running dialog with Message Activity.");

                // Run the Dialog with the new message Activity.
                await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);
            }
        }