Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}