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

Commit c4ec5ae

Browse files
committed
Removing .join from CompletableFuture call
1 parent 0ca0f8b commit c4ec5ae

1 file changed

Lines changed: 24 additions & 30 deletions

File tree

samples/52.teams-messaging-extensions-search-auth-config/src/main/java/com/microsoft/bot/sample/teamssearchauth/TeamsMessagingExtensionsSearchAuthConfigBot.java

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
import com.microsoft.bot.schema.*;
1414
import com.microsoft.bot.schema.teams.*;
1515
import com.microsoft.graph.models.extensions.Message;
16-
import java.io.InputStream;
17-
import java.io.UnsupportedEncodingException;
18-
import java.net.URLEncoder;
19-
import java.nio.charset.StandardCharsets;
20-
import java.util.concurrent.atomic.AtomicReference;
2116
import okhttp3.OkHttpClient;
2217
import okhttp3.Request;
2318
import okhttp3.Response;
@@ -29,9 +24,14 @@
2924
import org.springframework.stereotype.Component;
3025

3126
import java.io.IOException;
27+
import java.io.InputStream;
28+
import java.io.UnsupportedEncodingException;
29+
import java.net.URLEncoder;
30+
import java.nio.charset.StandardCharsets;
3231
import java.util.*;
3332
import java.util.concurrent.CompletableFuture;
3433
import java.util.concurrent.CompletionException;
34+
import java.util.concurrent.atomic.AtomicReference;
3535

3636
/**
3737
* This class implements the functionality of the Bot.
@@ -45,8 +45,6 @@
4545
@Component
4646
public class TeamsMessagingExtensionsSearchAuthConfigBot extends TeamsActivityHandler {
4747

48-
private String appId;
49-
private String appPassword;
5048
private String siteUrl;
5149
private String connectionName;
5250
private UserState userState;
@@ -56,8 +54,6 @@ public TeamsMessagingExtensionsSearchAuthConfigBot(
5654
Configuration configuration,
5755
UserState userState
5856
) {
59-
appId = configuration.getProperty("MicrosoftAppId");
60-
appPassword = configuration.getProperty("MicrosoftAppPassword");
6157
connectionName = configuration.getProperty("ConnectionName");
6258
siteUrl = configuration.getProperty("SiteUrl");
6359
userConfigProperty = userState.createProperty("UserConfiguration");
@@ -187,36 +183,34 @@ private CompletableFuture<MessagingExtensionResponse> emailExtensionQuery(
187183

188184
UserTokenProvider tokenProvider = (UserTokenProvider) turnContext.getAdapter();
189185
return tokenProvider.getUserToken(turnContext, connectionName, magicCode)
190-
.thenApply(response -> {
186+
.thenCompose(response -> {
191187
if (response == null || StringUtils.isEmpty(response.getToken())) {
192188
// There is no token, so the user has not signed in yet.
193-
String link = tokenProvider.getOauthSignInLink(turnContext, connectionName).join();
194-
//.thenApply(link -> {
195-
return new MessagingExtensionResponse() {{
196-
setComposeExtension(new MessagingExtensionResult() {{
197-
setType("auth");
198-
setSuggestedActions(
199-
new MessagingExtensionSuggestedAction() {{
200-
setAction(
201-
new CardAction() {{
202-
setType(ActionTypes.OPEN_URL);
203-
setValue(link);
204-
setTitle("Bot Service OAuth");
205-
}}
206-
);
207-
}}
208-
);
209-
}});
210-
}};
211-
//});
189+
return tokenProvider.getOauthSignInLink(turnContext, connectionName)
190+
.thenApply(link -> new MessagingExtensionResponse() {{
191+
setComposeExtension(new MessagingExtensionResult() {{
192+
setType("auth");
193+
setSuggestedActions(
194+
new MessagingExtensionSuggestedAction() {{
195+
setAction(
196+
new CardAction() {{
197+
setType(ActionTypes.OPEN_URL);
198+
setValue(link);
199+
setTitle("Bot Service OAuth");
200+
}}
201+
);
202+
}}
203+
);
204+
}});
205+
}});
212206
}
213207

214208
String search = "";
215209
if (query.getParameters() != null && !query.getParameters().isEmpty()) {
216210
search = (String) query.getParameters().get(0).getValue();
217211
}
218212

219-
return new MessagingExtensionResponse(searchMail(search, response.getToken()));
213+
return CompletableFuture.completedFuture(new MessagingExtensionResponse(searchMail(search, response.getToken())));
220214
});
221215
}
222216

0 commit comments

Comments
 (0)