Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
TranscriptLoggerMiddleware set turnContext.Activity.From.Role (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
tracyboehrer authored Mar 15, 2021
1 parent 06c3fdc commit 4777708
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.microsoft.bot.builder;

import com.microsoft.bot.schema.Activity;
import com.microsoft.bot.schema.ActivityEventNames;
import com.microsoft.bot.schema.ActivityTypes;
import com.microsoft.bot.schema.ChannelAccount;
import com.microsoft.bot.schema.RoleTypes;
Expand All @@ -13,6 +14,7 @@
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.commons.lang3.StringUtils;

/**
* When added, this middleware will log incoming and outgoing activities to a
Expand Down Expand Up @@ -57,7 +59,22 @@ public TranscriptLoggerMiddleware(TranscriptLogger withTranscriptLogger) {
public CompletableFuture<Void> onTurn(TurnContext context, NextDelegate next) {
// log incoming activity at beginning of turn
if (context.getActivity() != null) {
logActivity(Activity.clone(context.getActivity()), true);
if (context.getActivity().getFrom() == null) {
context.getActivity().setFrom(new ChannelAccount());
}

if (context.getActivity().getFrom().getProperties().get("role") == null
&& context.getActivity().getFrom().getRole() == null
) {
context.getActivity().getFrom().setRole(RoleTypes.USER);
}

// We should not log ContinueConversation events used by skills to initialize the middleware.
if (!(context.getActivity().isType(ActivityTypes.EVENT)
&& StringUtils.equals(context.getActivity().getName(), ActivityEventNames.CONTINUE_CONVERSATION))
) {
logActivity(Activity.clone(context.getActivity()), true);
}
}

// hook up onSend pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public final void Transcript_RolesAreFilled() {
// message. As demonstrated by the asserts after this TestFlow block
// the role attribute is present on the activity as it is passed to
// the transcript, but still missing inside the flow
Assert.assertNull(context.getActivity().getFrom().getRole());
Assert.assertNotNull(context.getActivity().getFrom().getRole());
conversationId[0] = context.getActivity().getConversation().getId();
context.sendActivity("echo:" + context.getActivity().getText()).join();
return CompletableFuture.completedFuture(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.bot.schema;

/**
* Define values for common event names used by activities of type
* ActivityTypes.Event.
*/
public final class ActivityEventNames {
private ActivityEventNames() {

}

/**
* The event name for continuing a conversation.
*/
public static final String CONTINUE_CONVERSATION = "ContinueConversation";

/**
* The event name for creating a conversation.
*/
public static final String CREATE_CONVERSATION = "CreateConversation";
}

0 comments on commit 4777708

Please sign in to comment.