1313import com .microsoft .bot .schema .*;
1414import com .microsoft .bot .schema .teams .*;
1515import 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 ;
2116import okhttp3 .OkHttpClient ;
2217import okhttp3 .Request ;
2318import okhttp3 .Response ;
2924import org .springframework .stereotype .Component ;
3025
3126import java .io .IOException ;
27+ import java .io .InputStream ;
28+ import java .io .UnsupportedEncodingException ;
29+ import java .net .URLEncoder ;
30+ import java .nio .charset .StandardCharsets ;
3231import java .util .*;
3332import java .util .concurrent .CompletableFuture ;
3433import java .util .concurrent .CompletionException ;
34+ import java .util .concurrent .atomic .AtomicReference ;
3535
3636/**
3737 * This class implements the functionality of the Bot.
4545@ Component
4646public 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