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

Commit 5a9d1cf

Browse files
authored
Added TeamsInfo.fetchMeetingInfo (#1233)
1 parent 104b7e8 commit 5a9d1cf

File tree

6 files changed

+379
-0
lines changed

6 files changed

+379
-0
lines changed

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/teams/TeamsInfo.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.microsoft.bot.schema.Serialization;
1818
import com.microsoft.bot.schema.teams.ChannelInfo;
1919
import com.microsoft.bot.schema.teams.ConversationList;
20+
import com.microsoft.bot.schema.teams.MeetingInfo;
2021
import com.microsoft.bot.schema.teams.TeamDetails;
2122
import com.microsoft.bot.schema.teams.TeamsChannelAccount;
2223
import com.microsoft.bot.schema.teams.TeamsChannelData;
@@ -269,6 +270,24 @@ public static CompletableFuture<TeamsMeetingParticipant> getMeetingParticipant(
269270
);
270271
}
271272

273+
/**
274+
* Gets the information for the given meeting id.
275+
* @param turnContext Turn context.
276+
* @param meetingId The BASE64-encoded id of the Teams meeting.
277+
* @return Meeting Details.
278+
*/
279+
public static CompletableFuture<MeetingInfo> getMeetingInfo(TurnContext turnContext, String meetingId) {
280+
if (StringUtils.isEmpty(meetingId) && turnContext.getActivity().teamsGetMeetingInfo() != null) {
281+
meetingId = turnContext.getActivity().teamsGetMeetingInfo().getId();
282+
}
283+
284+
if (StringUtils.isEmpty(meetingId)) {
285+
return illegalArgument("TeamsInfo.getMeetingInfo: method requires a meetingId");
286+
}
287+
288+
return getTeamsConnectorClient(turnContext).getTeams().fetchMeetingInfo(meetingId);
289+
}
290+
272291
private static CompletableFuture<List<TeamsChannelAccount>> getMembers(
273292
ConnectorClient connectorClient,
274293
String conversationId

libraries/bot-builder/src/test/java/com/microsoft/bot/builder/teams/TeamsInfoTests.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
import com.microsoft.bot.schema.Pair;
3030
import com.microsoft.bot.schema.teams.ChannelInfo;
3131
import com.microsoft.bot.schema.teams.ConversationList;
32+
import com.microsoft.bot.schema.teams.MeetingDetails;
33+
import com.microsoft.bot.schema.teams.MeetingInfo;
3234
import com.microsoft.bot.schema.teams.TeamDetails;
3335
import com.microsoft.bot.schema.teams.TeamInfo;
3436
import com.microsoft.bot.schema.teams.TeamsChannelAccount;
3537
import com.microsoft.bot.schema.teams.TeamsChannelData;
38+
import com.microsoft.bot.schema.teams.TeamsMeetingInfo;
3639
import org.junit.Assert;
3740
import org.junit.Test;
3841
import org.junit.runner.RunWith;
@@ -176,6 +179,31 @@ public void TestGetChannels() {
176179
handler.onTurn(turnContext).join();
177180
}
178181

182+
@Test
183+
public void TestGetMeetingInfo() {
184+
String baseUri = "https://test.coffee";
185+
MicrosoftAppCredentials credentials = MicrosoftAppCredentials.empty();
186+
ConnectorClient connectorClient = getConnectorClient(baseUri, credentials);
187+
188+
Activity activity = new Activity(ActivityTypes.MESSAGE);
189+
activity.setText("Test-GetMeetingInfoAsync");
190+
activity.setChannelId(Channels.MSTEAMS);
191+
TeamsChannelData data = new TeamsChannelData();
192+
data.setMeeting(new TeamsMeetingInfo("meeting-id"));
193+
activity.setChannelData(data);
194+
195+
TurnContext turnContext = new TurnContextImpl(new SimpleAdapter(), activity);
196+
turnContext.getTurnState().add(BotFrameworkAdapter.CONNECTOR_CLIENT_KEY, connectorClient);
197+
turnContext.getTurnState().add(
198+
BotFrameworkAdapter.TEAMSCONNECTOR_CLIENT_KEY,
199+
getTeamsConnectorClient(connectorClient.baseUrl(), credentials)
200+
);
201+
turnContext.getActivity().setServiceUrl("https://test.coffee");
202+
203+
ActivityHandler handler = new TestTeamsActivityHandler();
204+
handler.onTurn(turnContext).join();
205+
}
206+
179207
private class TestBotFrameworkAdapter extends BotFrameworkAdapter {
180208

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

244+
case "Test-GetMeetingInfoAsync":
245+
return callTeamsInfoGetMeetingInfo(turnContext);
246+
216247
default:
217248
Assert.fail();
218249
}
@@ -308,6 +339,16 @@ private CompletableFuture<Void> callGetChannels(TurnContext turnContext) {
308339

309340
return CompletableFuture.completedFuture(null);
310341
}
342+
343+
private CompletableFuture<Void> callTeamsInfoGetMeetingInfo(TurnContext turnContext) {
344+
MeetingInfo meeting = TeamsInfo.getMeetingInfo(turnContext, null).join();
345+
346+
Assert.assertEquals("meeting-id", meeting.getDetails().getId());
347+
Assert.assertEquals("organizer-id", meeting.getOrganizer().getId());
348+
Assert.assertEquals("meetingConversationId-1", meeting.getConversation().getId());
349+
350+
return CompletableFuture.completedFuture(null);
351+
}
311352
}
312353

313354
private static ConnectorClient getConnectorClient(String baseUri, AppCredentials credentials) {
@@ -412,6 +453,24 @@ private static TeamsConnectorClient getTeamsConnectorClient(
412453
CompletableFuture.completedFuture(details)
413454
);
414455

456+
// fetchTeamDetails
457+
MeetingInfo meetingInfo = new MeetingInfo();
458+
MeetingDetails meetingDetails = new MeetingDetails();
459+
meetingDetails.setId("meeting-id");
460+
meetingInfo.setDetails(meetingDetails);
461+
462+
TeamsChannelAccount organizer = new TeamsChannelAccount();
463+
organizer.setId("organizer-id");
464+
meetingInfo.setOrganizer(organizer);
465+
466+
ConversationAccount conversationAccount = new ConversationAccount();
467+
conversationAccount.setId("meetingConversationId-1");
468+
meetingInfo.setConversation(conversationAccount);
469+
470+
Mockito.when(mockOperations.fetchMeetingInfo(Mockito.anyString())).thenReturn(
471+
CompletableFuture.completedFuture(meetingInfo)
472+
);
473+
415474
TeamsConnectorClient mockConnectorClient = Mockito.mock(TeamsConnectorClient.class);
416475
Mockito.when(mockConnectorClient.getTeams()).thenReturn(mockOperations);
417476
Mockito.when(mockConnectorClient.baseUrl()).thenReturn(baseUri);

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/rest/RestTeamsOperations.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.microsoft.bot.connector.teams.TeamsOperations;
1212
import com.microsoft.bot.restclient.ServiceResponse;
1313
import com.microsoft.bot.schema.teams.ConversationList;
14+
import com.microsoft.bot.schema.teams.MeetingInfo;
1415
import com.microsoft.bot.schema.teams.TeamDetails;
1516
import com.microsoft.bot.schema.teams.TeamsMeetingParticipant;
1617
import okhttp3.ResponseBody;
@@ -162,6 +163,39 @@ private ServiceResponse<TeamsMeetingParticipant> fetchParticipantDelegate(
162163
.build(response);
163164
}
164165

166+
/**
167+
* Fetches Teams meeting participant details.
168+
* @param meetingId Teams meeting id
169+
* @return TeamsParticipantChannelAccount
170+
*/
171+
@Override
172+
public CompletableFuture<MeetingInfo> fetchMeetingInfo(String meetingId) {
173+
return service.fetchMeetingInfo(
174+
meetingId, client.getAcceptLanguage(), client.getUserAgent()
175+
)
176+
.thenApply(responseBodyResponse -> {
177+
try {
178+
return fetchMeetingInfoDelegate(responseBodyResponse).body();
179+
} catch (ErrorResponseException e) {
180+
throw e;
181+
} catch (Throwable t) {
182+
throw new ErrorResponseException("fetchMeetingInfo", responseBodyResponse);
183+
}
184+
});
185+
}
186+
187+
private ServiceResponse<MeetingInfo> fetchMeetingInfoDelegate(
188+
Response<ResponseBody> response
189+
) throws ErrorResponseException, IOException, IllegalArgumentException {
190+
return client.restClient()
191+
.responseBuilderFactory()
192+
.<MeetingInfo, ErrorResponseException>newInstance(client.serializerAdapter())
193+
.register(HttpURLConnection.HTTP_OK, new TypeToken<MeetingInfo>() {
194+
}.getType())
195+
.registerError(ErrorResponseException.class)
196+
.build(response);
197+
}
198+
165199
/**
166200
* The interface defining all the services for TeamsOperations to be used by
167201
* Retrofit to perform actually REST calls.
@@ -196,5 +230,14 @@ CompletableFuture<Response<ResponseBody>> fetchParticipant(
196230
@Header("accept-language") String acceptLanguage,
197231
@Header("User-Agent") String userAgent
198232
);
233+
234+
@Headers({ "Content-Type: application/json; charset=utf-8",
235+
"x-ms-logging-context: com.microsoft.bot.schema.Teams fetchMeetingInfo" })
236+
@GET("v1/meetings/{meetingId}")
237+
CompletableFuture<Response<ResponseBody>> fetchMeetingInfo(
238+
@Path("meetingId") String meetingId,
239+
@Header("accept-language") String acceptLanguage,
240+
@Header("User-Agent") String userAgent
241+
);
199242
}
200243
}

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/teams/TeamsOperations.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package com.microsoft.bot.connector.teams;
1212

1313
import com.microsoft.bot.schema.teams.ConversationList;
14+
import com.microsoft.bot.schema.teams.MeetingInfo;
1415
import com.microsoft.bot.schema.teams.TeamDetails;
1516

1617
import com.microsoft.bot.schema.teams.TeamsMeetingParticipant;
@@ -48,4 +49,15 @@ CompletableFuture<TeamsMeetingParticipant> fetchParticipant(
4849
String participantId,
4950
String tenantId
5051
);
52+
53+
/**
54+
* Fetches information related to a Teams meeting.
55+
* @param meetingId Meeting Id.
56+
* @return The details related to a team.
57+
*/
58+
default CompletableFuture<MeetingInfo> fetchMeetingInfo(String meetingId) {
59+
CompletableFuture<MeetingInfo> result = new CompletableFuture<>();
60+
result.completeExceptionally(new Exception("fetchMeetingInfo not implemented"));
61+
return result;
62+
}
5163
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.bot.schema.teams;
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
/**
9+
* Specific details of a Teams meeting.
10+
*/
11+
public class MeetingDetails {
12+
@JsonProperty(value = "id")
13+
private String id;
14+
15+
@JsonProperty(value = "msGraphResourceId")
16+
private String msGraphResourceId;
17+
18+
@JsonProperty(value = "scheduledStartTime")
19+
private String scheduledStartTime;
20+
21+
@JsonProperty(value = "scheduledEndTime")
22+
private String scheduledEndTime;
23+
24+
@JsonProperty(value = "joinUrl")
25+
private String joinUrl;
26+
27+
@JsonProperty(value = "title")
28+
private String title;
29+
30+
@JsonProperty(value = "type")
31+
private String type;
32+
33+
/**
34+
* Initializes a new instance.
35+
*/
36+
public MeetingDetails() {
37+
}
38+
39+
/**
40+
* Gets the meeting's Id, encoded as a BASE64 String.
41+
*
42+
* @return The meeting's Id, encoded as a BASE64 String.
43+
*/
44+
public String getId() {
45+
return id;
46+
}
47+
48+
/**
49+
* Sets the meeting's Id, encoded as a BASE64 String.
50+
*
51+
* @param withId The meeting's Id, encoded as a BASE64 String.
52+
*/
53+
public void setId(String withId) {
54+
id = withId;
55+
}
56+
57+
/**
58+
* Gets the MsGraphResourceId, used specifically for MS Graph API calls.
59+
*
60+
* @return The MsGraphResourceId, used specifically for MS Graph API calls.
61+
*/
62+
public String getMsGraphResourceId() {
63+
return msGraphResourceId;
64+
}
65+
66+
/**
67+
* Sets the MsGraphResourceId, used specifically for MS Graph API calls.
68+
*
69+
* @param withMsGraphResourceId The MsGraphResourceId, used specifically for MS
70+
* Graph API calls.
71+
*/
72+
public void setMsGraphResourceId(String withMsGraphResourceId) {
73+
msGraphResourceId = withMsGraphResourceId;
74+
}
75+
76+
/**
77+
* Gets the meeting's scheduled start time, in UTC.
78+
*
79+
* @return The meeting's scheduled start time, in UTC.
80+
*/
81+
public String getScheduledStartTime() {
82+
return scheduledStartTime;
83+
}
84+
85+
/**
86+
* Sets the meeting's scheduled start time, in UTC.
87+
*
88+
* @param withScheduledStartTime The meeting's scheduled start time, in UTC.
89+
*/
90+
public void setScheduledStartTime(String withScheduledStartTime) {
91+
scheduledStartTime = withScheduledStartTime;
92+
}
93+
94+
/**
95+
* Gets the meeting's scheduled end time, in UTC.
96+
*
97+
* @return The meeting's scheduled end time, in UTC.
98+
*/
99+
public String getScheduledEndTime() {
100+
return scheduledEndTime;
101+
}
102+
103+
/**
104+
* Sets the meeting's scheduled end time, in UTC.
105+
*
106+
* @param withScheduledEndTime The meeting's scheduled end time, in UTC.
107+
*/
108+
public void setScheduledEndTime(String withScheduledEndTime) {
109+
scheduledEndTime = withScheduledEndTime;
110+
}
111+
112+
/**
113+
* Gets the URL used to join the meeting.
114+
*
115+
* @return The URL used to join the meeting.
116+
*/
117+
public String getJoinUrl() {
118+
return joinUrl;
119+
}
120+
121+
/**
122+
* Sets the URL used to join the meeting.
123+
*
124+
* @param withJoinUrl The URL used to join the meeting.
125+
*/
126+
public void setJoinUrl(String withJoinUrl) {
127+
joinUrl = withJoinUrl;
128+
}
129+
130+
/**
131+
* Gets the title of the meeting.
132+
*
133+
* @return The title of the meeting.
134+
*/
135+
public String getTitle() {
136+
return title;
137+
}
138+
139+
/**
140+
* Sets the title of the meeting.
141+
*
142+
* @param withTitle The title of the meeting.
143+
*/
144+
public void setTitle(String withTitle) {
145+
title = withTitle;
146+
}
147+
148+
/**
149+
* Gets the meeting's type.
150+
*
151+
* @return The meeting's type.
152+
*/
153+
public String getType() {
154+
return type;
155+
}
156+
157+
/**
158+
* Sets the meeting's type.
159+
*
160+
* @param withType The meeting's type.
161+
*/
162+
public void setType(String withType) {
163+
type = withType;
164+
}
165+
}

0 commit comments

Comments
 (0)