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

Commit

Permalink
Added TeamsInfo.fetchMeetingInfo (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
tracyboehrer authored Jun 17, 2021
1 parent 104b7e8 commit 5a9d1cf
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.microsoft.bot.schema.Serialization;
import com.microsoft.bot.schema.teams.ChannelInfo;
import com.microsoft.bot.schema.teams.ConversationList;
import com.microsoft.bot.schema.teams.MeetingInfo;
import com.microsoft.bot.schema.teams.TeamDetails;
import com.microsoft.bot.schema.teams.TeamsChannelAccount;
import com.microsoft.bot.schema.teams.TeamsChannelData;
Expand Down Expand Up @@ -269,6 +270,24 @@ public static CompletableFuture<TeamsMeetingParticipant> getMeetingParticipant(
);
}

/**
* Gets the information for the given meeting id.
* @param turnContext Turn context.
* @param meetingId The BASE64-encoded id of the Teams meeting.
* @return Meeting Details.
*/
public static CompletableFuture<MeetingInfo> getMeetingInfo(TurnContext turnContext, String meetingId) {
if (StringUtils.isEmpty(meetingId) && turnContext.getActivity().teamsGetMeetingInfo() != null) {
meetingId = turnContext.getActivity().teamsGetMeetingInfo().getId();
}

if (StringUtils.isEmpty(meetingId)) {
return illegalArgument("TeamsInfo.getMeetingInfo: method requires a meetingId");
}

return getTeamsConnectorClient(turnContext).getTeams().fetchMeetingInfo(meetingId);
}

private static CompletableFuture<List<TeamsChannelAccount>> getMembers(
ConnectorClient connectorClient,
String conversationId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
import com.microsoft.bot.schema.Pair;
import com.microsoft.bot.schema.teams.ChannelInfo;
import com.microsoft.bot.schema.teams.ConversationList;
import com.microsoft.bot.schema.teams.MeetingDetails;
import com.microsoft.bot.schema.teams.MeetingInfo;
import com.microsoft.bot.schema.teams.TeamDetails;
import com.microsoft.bot.schema.teams.TeamInfo;
import com.microsoft.bot.schema.teams.TeamsChannelAccount;
import com.microsoft.bot.schema.teams.TeamsChannelData;
import com.microsoft.bot.schema.teams.TeamsMeetingInfo;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -176,6 +179,31 @@ public void TestGetChannels() {
handler.onTurn(turnContext).join();
}

@Test
public void TestGetMeetingInfo() {
String baseUri = "https://test.coffee";
MicrosoftAppCredentials credentials = MicrosoftAppCredentials.empty();
ConnectorClient connectorClient = getConnectorClient(baseUri, credentials);

Activity activity = new Activity(ActivityTypes.MESSAGE);
activity.setText("Test-GetMeetingInfoAsync");
activity.setChannelId(Channels.MSTEAMS);
TeamsChannelData data = new TeamsChannelData();
data.setMeeting(new TeamsMeetingInfo("meeting-id"));
activity.setChannelData(data);

TurnContext turnContext = new TurnContextImpl(new SimpleAdapter(), activity);
turnContext.getTurnState().add(BotFrameworkAdapter.CONNECTOR_CLIENT_KEY, connectorClient);
turnContext.getTurnState().add(
BotFrameworkAdapter.TEAMSCONNECTOR_CLIENT_KEY,
getTeamsConnectorClient(connectorClient.baseUrl(), credentials)
);
turnContext.getActivity().setServiceUrl("https://test.coffee");

ActivityHandler handler = new TestTeamsActivityHandler();
handler.onTurn(turnContext).join();
}

private class TestBotFrameworkAdapter extends BotFrameworkAdapter {

public TestBotFrameworkAdapter(CredentialProvider withCredentialProvider) {
Expand Down Expand Up @@ -213,6 +241,9 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {
case "Test-SendMessageToTeamsChannelAsync":
return callSendMessageToTeamsChannel(turnContext);

case "Test-GetMeetingInfoAsync":
return callTeamsInfoGetMeetingInfo(turnContext);

default:
Assert.fail();
}
Expand Down Expand Up @@ -308,6 +339,16 @@ private CompletableFuture<Void> callGetChannels(TurnContext turnContext) {

return CompletableFuture.completedFuture(null);
}

private CompletableFuture<Void> callTeamsInfoGetMeetingInfo(TurnContext turnContext) {
MeetingInfo meeting = TeamsInfo.getMeetingInfo(turnContext, null).join();

Assert.assertEquals("meeting-id", meeting.getDetails().getId());
Assert.assertEquals("organizer-id", meeting.getOrganizer().getId());
Assert.assertEquals("meetingConversationId-1", meeting.getConversation().getId());

return CompletableFuture.completedFuture(null);
}
}

private static ConnectorClient getConnectorClient(String baseUri, AppCredentials credentials) {
Expand Down Expand Up @@ -412,6 +453,24 @@ private static TeamsConnectorClient getTeamsConnectorClient(
CompletableFuture.completedFuture(details)
);

// fetchTeamDetails
MeetingInfo meetingInfo = new MeetingInfo();
MeetingDetails meetingDetails = new MeetingDetails();
meetingDetails.setId("meeting-id");
meetingInfo.setDetails(meetingDetails);

TeamsChannelAccount organizer = new TeamsChannelAccount();
organizer.setId("organizer-id");
meetingInfo.setOrganizer(organizer);

ConversationAccount conversationAccount = new ConversationAccount();
conversationAccount.setId("meetingConversationId-1");
meetingInfo.setConversation(conversationAccount);

Mockito.when(mockOperations.fetchMeetingInfo(Mockito.anyString())).thenReturn(
CompletableFuture.completedFuture(meetingInfo)
);

TeamsConnectorClient mockConnectorClient = Mockito.mock(TeamsConnectorClient.class);
Mockito.when(mockConnectorClient.getTeams()).thenReturn(mockOperations);
Mockito.when(mockConnectorClient.baseUrl()).thenReturn(baseUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.microsoft.bot.connector.teams.TeamsOperations;
import com.microsoft.bot.restclient.ServiceResponse;
import com.microsoft.bot.schema.teams.ConversationList;
import com.microsoft.bot.schema.teams.MeetingInfo;
import com.microsoft.bot.schema.teams.TeamDetails;
import com.microsoft.bot.schema.teams.TeamsMeetingParticipant;
import okhttp3.ResponseBody;
Expand Down Expand Up @@ -162,6 +163,39 @@ private ServiceResponse<TeamsMeetingParticipant> fetchParticipantDelegate(
.build(response);
}

/**
* Fetches Teams meeting participant details.
* @param meetingId Teams meeting id
* @return TeamsParticipantChannelAccount
*/
@Override
public CompletableFuture<MeetingInfo> fetchMeetingInfo(String meetingId) {
return service.fetchMeetingInfo(
meetingId, client.getAcceptLanguage(), client.getUserAgent()
)
.thenApply(responseBodyResponse -> {
try {
return fetchMeetingInfoDelegate(responseBodyResponse).body();
} catch (ErrorResponseException e) {
throw e;
} catch (Throwable t) {
throw new ErrorResponseException("fetchMeetingInfo", responseBodyResponse);
}
});
}

private ServiceResponse<MeetingInfo> fetchMeetingInfoDelegate(
Response<ResponseBody> response
) throws ErrorResponseException, IOException, IllegalArgumentException {
return client.restClient()
.responseBuilderFactory()
.<MeetingInfo, ErrorResponseException>newInstance(client.serializerAdapter())
.register(HttpURLConnection.HTTP_OK, new TypeToken<MeetingInfo>() {
}.getType())
.registerError(ErrorResponseException.class)
.build(response);
}

/**
* The interface defining all the services for TeamsOperations to be used by
* Retrofit to perform actually REST calls.
Expand Down Expand Up @@ -196,5 +230,14 @@ CompletableFuture<Response<ResponseBody>> fetchParticipant(
@Header("accept-language") String acceptLanguage,
@Header("User-Agent") String userAgent
);

@Headers({ "Content-Type: application/json; charset=utf-8",
"x-ms-logging-context: com.microsoft.bot.schema.Teams fetchMeetingInfo" })
@GET("v1/meetings/{meetingId}")
CompletableFuture<Response<ResponseBody>> fetchMeetingInfo(
@Path("meetingId") String meetingId,
@Header("accept-language") String acceptLanguage,
@Header("User-Agent") String userAgent
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.microsoft.bot.connector.teams;

import com.microsoft.bot.schema.teams.ConversationList;
import com.microsoft.bot.schema.teams.MeetingInfo;
import com.microsoft.bot.schema.teams.TeamDetails;

import com.microsoft.bot.schema.teams.TeamsMeetingParticipant;
Expand Down Expand Up @@ -48,4 +49,15 @@ CompletableFuture<TeamsMeetingParticipant> fetchParticipant(
String participantId,
String tenantId
);

/**
* Fetches information related to a Teams meeting.
* @param meetingId Meeting Id.
* @return The details related to a team.
*/
default CompletableFuture<MeetingInfo> fetchMeetingInfo(String meetingId) {
CompletableFuture<MeetingInfo> result = new CompletableFuture<>();
result.completeExceptionally(new Exception("fetchMeetingInfo not implemented"));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.bot.schema.teams;

import com.fasterxml.jackson.annotation.JsonProperty;

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

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

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

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

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

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

@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() {
return msGraphResourceId;
}

/**
* Sets the MsGraphResourceId, used specifically for MS Graph API calls.
*
* @param withMsGraphResourceId The MsGraphResourceId, used specifically for MS
* Graph API calls.
*/
public void setMsGraphResourceId(String withMsGraphResourceId) {
msGraphResourceId = withMsGraphResourceId;
}

/**
* Gets the meeting's scheduled start time, in UTC.
*
* @return The meeting's scheduled start time, in UTC.
*/
public String 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) {
scheduledStartTime = withScheduledStartTime;
}

/**
* Gets the meeting's scheduled end time, in UTC.
*
* @return The meeting's scheduled end time, in UTC.
*/
public String 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) {
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() {
return type;
}

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

0 comments on commit 5a9d1cf

Please sign in to comment.