TranscriptLoggerMiddleware set turnContext.Activity.From.Role (#1057)
This commit is contained in:
Родитель
06c3fdc0ed
Коммит
47777086d5
|
@ -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;
|
||||
|
@ -13,6 +14,7 @@ import java.time.ZoneId;
|
|||
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
|
||||
|
@ -57,7 +59,22 @@ public class TranscriptLoggerMiddleware implements Middleware {
|
|||
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
|
||||
|
|
|
@ -282,7 +282,7 @@ public class TranscriptMiddlewareTest {
|
|||
// 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);
|
||||
|
|
|
@ -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";
|
||||
}
|
Загрузка…
Ссылка в новой задаче