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 @@ -11,6 +11,7 @@ private TelemetryConstants() {

}

public static final String ATTACHMENTSPROPERTY = "attachments";
public static final String CHANNELIDPROPERTY = "channelId";
public static final String CONVERSATIONIDPROPERTY = "conversationId";
public static final String CONVERSATIONNAMEPROPERTY = "conversationName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ protected CompletableFuture<Void> onDeleteActivity(Activity activity) {
* {@link BotTelemetryClient#trackEvent} method for the
* BotMessageReceived event.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
protected CompletableFuture<Map<String, String>> fillReceiveEventProperties(
Activity activity,
Map<String, String> additionalProperties
Expand Down Expand Up @@ -217,6 +218,14 @@ protected CompletableFuture<Map<String, String>> fillReceiveEventProperties(
if (!StringUtils.isEmpty(activity.getSpeak())) {
properties.put(TelemetryConstants.SPEAKPROPERTY, activity.getSpeak());
}

if (activity.getAttachments() != null && activity.getAttachments().size() > 0) {
try {
properties.put(TelemetryConstants.ATTACHMENTSPROPERTY,
Serialization.toString(activity.getAttachments()));
} catch (JsonProcessingException e) {
}
}
}

populateAdditionalChannelProperties(activity, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.microsoft.bot.connector.Channels;
import com.microsoft.bot.schema.Activity;
import com.microsoft.bot.schema.ActivityTypes;
import com.microsoft.bot.schema.Attachment;
import com.microsoft.bot.schema.ChannelAccount;
import com.microsoft.bot.schema.ResourceResponse;
import com.microsoft.bot.schema.Serialization;
Expand Down Expand Up @@ -528,6 +529,45 @@ public void Telemetry_AdditionalProps() {
);
}

@Test
public void Telemetry_LogAttachments() throws JsonProcessingException {
BotTelemetryClient mockTelemetryClient = mock(BotTelemetryClient.class);
TestAdapter adapter = new TestAdapter(Channels.MSTEAMS).use(
new TelemetryLoggerMiddleware(mockTelemetryClient, true)
);

TeamInfo teamInfo = new TeamInfo();
teamInfo.setId("teamId");
teamInfo.setName("teamName");

Activity activity = MessageFactory.text("test");
ChannelAccount from = new ChannelAccount();
from.setId("userId");
from.setName("userName");
from.setAadObjectId("aadId");
activity.setFrom(from);
Attachment attachment = new Attachment();
attachment.setContent("Hello World");
attachment.setContentType("test/attachment");
attachment.setName("testname");
activity.setAttachment(attachment);

new TestFlow(adapter).send(activity).startTest().join();

verify(mockTelemetryClient).trackEvent(
eventNameCaptor.capture(),
propertiesCaptor.capture()
);
List<String> eventNames = eventNameCaptor.getAllValues();
List<Map<String, String>> properties = propertiesCaptor.getAllValues();

Assert.assertEquals(TelemetryLoggerConstants.BOTMSGRECEIVEEVENT, eventNames.get(0));
String loggedAttachment = properties.get(0).get("attachments");
String originalAttachment = Serialization.toString(activity.getAttachments());
Assert.assertTrue(StringUtils.equals(loggedAttachment, originalAttachment));
}


@Test
public void Telemetry_LogTeamsProperties() throws JsonProcessingException {
BotTelemetryClient mockTelemetryClient = mock(BotTelemetryClient.class);
Expand Down