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

Added Teams meeting start/end #1260

Merged
merged 6 commits into from
Jun 25, 2021
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ public static CompletableFuture<TeamsMeetingParticipant> getMeetingParticipant(
);
}

/**
* Gets the information for the given meeting id.
* @param turnContext Turn context.
* @return Meeting Details.
*/
public static CompletableFuture<MeetingInfo> getMeetingInfo(TurnContext turnContext) {
return getMeetingInfo(turnContext, null);
}

/**
* Gets the information for the given meeting id.
* @param turnContext Turn context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import com.microsoft.bot.schema.ConversationReference;
import com.microsoft.bot.schema.ConversationResourceResponse;
import com.microsoft.bot.schema.ResourceResponse;
import com.microsoft.bot.schema.Serialization;
import com.microsoft.bot.schema.teams.AppBasedLinkQuery;
import com.microsoft.bot.schema.teams.ChannelInfo;
import com.microsoft.bot.schema.teams.FileConsentCardResponse;
import com.microsoft.bot.schema.teams.FileUploadInfo;
import com.microsoft.bot.schema.teams.MeetingEndEventDetails;
import com.microsoft.bot.schema.teams.MeetingStartEventDetails;
import com.microsoft.bot.schema.teams.MessagingExtensionAction;
import com.microsoft.bot.schema.teams.MessagingExtensionActionResponse;
import com.microsoft.bot.schema.teams.MessagingExtensionQuery;
Expand All @@ -39,6 +42,7 @@
import com.microsoft.bot.schema.teams.TeamInfo;
import com.microsoft.bot.schema.teams.TeamsChannelAccount;
import com.microsoft.bot.schema.teams.TeamsChannelData;
import java.io.IOException;
import org.apache.commons.lang3.NotImplementedException;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -857,6 +861,80 @@ public void TestSigninVerifyState() {
);
}

@Test
public void TestOnEventActivity() {
// Arrange
Activity activity = new Activity(ActivityTypes.EVENT);
activity.setChannelId(Channels.DIRECTLINE);

TurnContext turnContext = new TurnContextImpl(new SimpleAdapter(), activity);

// Act
TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

// Assert
Assert.assertEquals(1, bot.record.size());
Assert.assertEquals("onEventActivity", bot.record.get(0));
}

@Test
public void TestMeetingStartEvent() throws IOException {
// Arrange
Activity activity = new Activity(ActivityTypes.EVENT);
activity.setChannelId(Channels.MSTEAMS);
activity.setName("application/vnd.microsoft.meetingStart");
activity.setValue(Serialization.jsonToTree("{\"StartTime\": \"2021-06-05T00:01:02.0Z\"}"));

AtomicReference<List<Activity>> activitiesToSend = new AtomicReference<>();

TurnContext turnContext = new TurnContextImpl(
new SimpleAdapter(activitiesToSend::set),
activity
);

// Act
TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

// Assert
Assert.assertEquals(2, bot.record.size());
Assert.assertEquals("onEventActivity", bot.record.get(0));
Assert.assertEquals("onTeamsMeetingStart", bot.record.get(1));

Assert.assertNotNull(activitiesToSend.get());
Assert.assertEquals(1, activitiesToSend.get().size());
Assert.assertTrue(activitiesToSend.get().get(0).getText().contains("00:01:02"));
}

@Test
public void TestMeetingEndEvent() throws IOException {
// Arrange
Activity activity = new Activity(ActivityTypes.EVENT);
activity.setChannelId(Channels.MSTEAMS);
activity.setName("application/vnd.microsoft.meetingEnd");
activity.setValue(Serialization.jsonToTree("{\"EndTime\": \"2021-06-05T01:02:03.0Z\"}"));

AtomicReference<List<Activity>> activitiesToSend = new AtomicReference<>();

TurnContext turnContext = new TurnContextImpl(
new SimpleAdapter(activitiesToSend::set),
activity
);

// Act
TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

// Assert
Assert.assertEquals(2, bot.record.size());
Assert.assertEquals("onEventActivity", bot.record.get(0));
Assert.assertEquals("onTeamsMeetingEnd", bot.record.get(1));
Assert.assertNotNull(activitiesToSend.get());
Assert.assertEquals(1, activitiesToSend.get().size());
Assert.assertTrue(activitiesToSend.get().get(0).getText().contains("1:02:03"));
}

private static class NotImplementedAdapter extends BotAdapter {

@Override
Expand Down Expand Up @@ -1209,6 +1287,34 @@ protected CompletableFuture<Void> onTeamsTeamUnarchived(
record.add("onTeamsTeamUnarchived");
return super.onTeamsTeamUnarchived(channelInfo, teamInfo, turnContext);
}

@Override
protected CompletableFuture<Void> onEventActivity(
TurnContext turnContext
) {
record.add("onEventActivity");
return super.onEventActivity(turnContext);
}

@Override
protected CompletableFuture<Void> onTeamsMeetingStart(
MeetingStartEventDetails meeting,
TurnContext turnContext
) {
record.add("onTeamsMeetingStart");
return turnContext.sendActivity(meeting.getStartTime().toString())
.thenCompose(resourceResponse -> super.onTeamsMeetingStart(meeting, turnContext));
}

@Override
protected CompletableFuture<Void> onTeamsMeetingEnd(
MeetingEndEventDetails meeting,
TurnContext turnContext
) {
record.add("onTeamsMeetingEnd");
return turnContext.sendActivity(meeting.getEndTime().toString())
.thenCompose(resourceResponse -> super.onTeamsMeetingEnd(meeting, turnContext));
}
}

private static ConnectorClient getConnectorClient(String baseUri, AppCredentials credentials) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.type.TypeBindings;
Expand Down Expand Up @@ -143,7 +144,8 @@ private static ObjectMapper initializeObjectMapper(ObjectMapper mapper) {
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.databind.node.ArrayNode;
Expand All @@ -27,6 +28,7 @@ private Serialization() {
static {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
objectMapper.findAndRegisterModules();

// NOTE: Undetermined if we should accommodate non-public fields. The normal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,27 @@
package com.microsoft.bot.schema.teams;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.OffsetDateTime;

/**
* Specific details of a Teams meeting.
*/
public class MeetingDetails {
@JsonProperty(value = "id")
private String id;

public class MeetingDetails extends MeetingDetailsBase {
@JsonProperty(value = "msGraphResourceId")
private String msGraphResourceId;

@JsonProperty(value = "scheduledStartTime")
private String scheduledStartTime;
private OffsetDateTime scheduledStartTime;

@JsonProperty(value = "scheduledEndTime")
private String scheduledEndTime;

@JsonProperty(value = "joinUrl")
private String joinUrl;

@JsonProperty(value = "title")
private String title;
private OffsetDateTime scheduledEndTime;

@JsonProperty(value = "type")
private String type;

/**
* Initializes a new instance.
*/
public MeetingDetails() {
}

/**
* Gets the meeting's Id, encoded as a BASE64 String.
*
* @return The meeting's Id, encoded as a BASE64 String.
*/
public String getId() {
return id;
}

/**
* Sets the meeting's Id, encoded as a BASE64 String.
*
* @param withId The meeting's Id, encoded as a BASE64 String.
*/
public void setId(String withId) {
id = withId;
}

/**
* Gets the MsGraphResourceId, used specifically for MS Graph API calls.
*
*
* @return The MsGraphResourceId, used specifically for MS Graph API calls.
*/
public String getMsGraphResourceId() {
Expand All @@ -65,7 +33,7 @@ public String getMsGraphResourceId() {

/**
* Sets the MsGraphResourceId, used specifically for MS Graph API calls.
*
*
* @param withMsGraphResourceId The MsGraphResourceId, used specifically for MS
* Graph API calls.
*/
Expand All @@ -75,79 +43,43 @@ public void setMsGraphResourceId(String withMsGraphResourceId) {

/**
* Gets the meeting's scheduled start time, in UTC.
*
*
* @return The meeting's scheduled start time, in UTC.
*/
public String getScheduledStartTime() {
public OffsetDateTime getScheduledStartTime() {
return scheduledStartTime;
}

/**
* Sets the meeting's scheduled start time, in UTC.
*
*
* @param withScheduledStartTime The meeting's scheduled start time, in UTC.
*/
public void setScheduledStartTime(String withScheduledStartTime) {
public void setScheduledStartTime(OffsetDateTime withScheduledStartTime) {
scheduledStartTime = withScheduledStartTime;
}

/**
* Gets the meeting's scheduled end time, in UTC.
*
*
* @return The meeting's scheduled end time, in UTC.
*/
public String getScheduledEndTime() {
public OffsetDateTime getScheduledEndTime() {
return scheduledEndTime;
}

/**
* Sets the meeting's scheduled end time, in UTC.
*
*
* @param withScheduledEndTime The meeting's scheduled end time, in UTC.
*/
public void setScheduledEndTime(String withScheduledEndTime) {
public void setScheduledEndTime(OffsetDateTime withScheduledEndTime) {
scheduledEndTime = withScheduledEndTime;
}

/**
* Gets the URL used to join the meeting.
*
* @return The URL used to join the meeting.
*/
public String getJoinUrl() {
return joinUrl;
}

/**
* Sets the URL used to join the meeting.
*
* @param withJoinUrl The URL used to join the meeting.
*/
public void setJoinUrl(String withJoinUrl) {
joinUrl = withJoinUrl;
}

/**
* Gets the title of the meeting.
*
* @return The title of the meeting.
*/
public String getTitle() {
return title;
}

/**
* Sets the title of the meeting.
*
* @param withTitle The title of the meeting.
*/
public void setTitle(String withTitle) {
title = withTitle;
}

/**
* Gets the meeting's type.
*
*
* @return The meeting's type.
*/
public String getType() {
Expand All @@ -156,7 +88,7 @@ public String getType() {

/**
* Sets the meeting's type.
*
*
* @param withType The meeting's type.
*/
public void setType(String withType) {
Expand Down
Loading