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

Commit 4dd06e0

Browse files
Skills implementation and Samples 80. Bot to Bot and 81. Dialog to Dialog (#1050)
* Push for backup * One more file. * SkillDialog complete * Skills updates to other areas. * Http Clients * Unit tests complete * Root bot and bug fixes * Corrected token issues for skill to skill * Skills fixes * Remove proxy setup. * Refactor SimpleRootBot * Refactor EchoSkillBot * Update readme.md files * Commit before merge with main. * Working DialogRootBot * Fixes for unit tests. * Initial DialogSkillBot * Sample 81 and skills fixes.
1 parent 13b647a commit 4dd06e0

File tree

140 files changed

+14073
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+14073
-644
lines changed

etc/bot-checkstyle.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<module name="SuppressWarningsFilter" />
8787

8888
<module name="TreeWalker">
89+
<!-- check for usage of literal equality "==" between string -->
90+
<module name="StringLiteralEquality"/>
91+
8992
<module name="SuppressWarningsHolder" />
9093
<module name="SuppressionCommentFilter"/>
9194

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {
8787
case ActivityTypes.INSTALLATION_UPDATE:
8888
return onInstallationUpdate(turnContext);
8989

90+
case ActivityTypes.END_OF_CONVERSATION:
91+
return onEndOfConversationActivity(turnContext);
92+
9093
case ActivityTypes.TYPING:
9194
return onTypingActivity(turnContext);
9295

@@ -565,6 +568,17 @@ protected CompletableFuture<Void> onInstallationUpdateRemove(TurnContext turnCon
565568
return CompletableFuture.completedFuture(null);
566569
}
567570

571+
/**
572+
* Override this in a derived class to provide logic specific to
573+
* ActivityTypes.END_OF_CONVERSATION activities.
574+
*
575+
* @param turnContext The context object for this turn.
576+
* @return A task that represents the work queued to execute.
577+
*/
578+
protected CompletableFuture<Void> onEndOfConversationActivity(TurnContext turnContext) {
579+
return CompletableFuture.completedFuture(null);
580+
}
581+
568582
/**
569583
* Override this in a derived class to provide logic specific to
570584
* ActivityTypes.Typing activities.

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials;
2727
import com.microsoft.bot.connector.authentication.MicrosoftGovernmentAppCredentials;
2828
import com.microsoft.bot.connector.authentication.SimpleCredentialProvider;
29+
import com.microsoft.bot.connector.authentication.SkillValidation;
2930
import com.microsoft.bot.connector.rest.RestConnectorClient;
3031
import com.microsoft.bot.connector.rest.RestOAuthClient;
3132
import com.microsoft.bot.schema.AadResourceUrls;
@@ -438,7 +439,10 @@ public CompletableFuture<InvokeResponse> processActivity(ClaimsIdentity identity
438439

439440
// The OAuthScope is also stored on the TurnState to get the correct
440441
// AppCredentials if fetching a token is required.
441-
String scope = getBotFrameworkOAuthScope();
442+
String scope = SkillValidation.isSkillClaim(identity.claims())
443+
? String.format("%s/.default", JwtTokenValidation.getAppIdFromClaims(identity.claims()))
444+
: getBotFrameworkOAuthScope();
445+
442446
context.getTurnState().add(OAUTH_SCOPE_KEY, scope);
443447

444448
pipelineResult = createConnectorClient(activity.getServiceUrl(), identity, scope)
@@ -493,6 +497,13 @@ private CompletableFuture<String> generateCallerId(ClaimsIdentity claimsIdentity
493497
return null;
494498
}
495499

500+
// Is the activity from another bot?
501+
if (SkillValidation.isSkillClaim(claimsIdentity.claims())) {
502+
return String.format("%s%s",
503+
CallerIdConstants.BOT_TO_BOT_PREFIX,
504+
JwtTokenValidation.getAppIdFromClaims(claimsIdentity.claims()));
505+
}
506+
496507
// Is the activity from Public Azure?
497508
if (channelProvider == null || channelProvider.isPublicAzure()) {
498509
return CallerIdConstants.PUBLIC_AZURE_CHANNEL;
@@ -1133,7 +1144,13 @@ public CompletableFuture<ConnectorClient> createConnectorClient(String serviceUr
11331144
}
11341145

11351146
if (botAppIdClaim != null) {
1136-
String scope = getBotFrameworkOAuthScope();
1147+
String scope = audience;
1148+
1149+
if (StringUtils.isBlank(audience)) {
1150+
scope = SkillValidation.isSkillClaim(claimsIdentity.claims())
1151+
? String.format("%s/.default", JwtTokenValidation.getAppIdFromClaims(claimsIdentity.claims()))
1152+
: getBotFrameworkOAuthScope();
1153+
}
11371154

11381155
return getAppCredentials(botAppIdClaim, scope)
11391156
.thenCompose(credentials -> getOrCreateConnectorClient(serviceUrl, credentials));
@@ -1236,8 +1253,8 @@ private CompletableFuture<AppCredentials> getAppCredentials(String appId, String
12361253
protected CompletableFuture<AppCredentials> buildAppCredentials(String appId, String scope) {
12371254
return credentialProvider.getAppPassword(appId).thenApply(appPassword -> {
12381255
AppCredentials credentials = channelProvider != null && channelProvider.isGovernment()
1239-
? new MicrosoftGovernmentAppCredentials(appId, appPassword, scope)
1240-
: new MicrosoftAppCredentials(appId, appPassword);
1256+
? new MicrosoftGovernmentAppCredentials(appId, appPassword, null, scope)
1257+
: new MicrosoftAppCredentials(appId, appPassword, null, scope);
12411258
return credentials;
12421259
});
12431260
}
@@ -1368,12 +1385,13 @@ public CompletableFuture<TokenResponse> getUserToken(TurnContext context, AppCre
13681385
));
13691386
}
13701387

1371-
OAuthClient client = createOAuthAPIClient(context, oAuthAppCredentials).join();
1372-
return client.getUserToken().getToken(
1388+
return createOAuthAPIClient(context, oAuthAppCredentials).thenCompose(client -> {
1389+
return client.getUserToken().getToken(
13731390
context.getActivity().getFrom().getId(),
13741391
connectionName,
13751392
context.getActivity().getChannelId(),
13761393
magicCode);
1394+
});
13771395
}
13781396

13791397
/**

0 commit comments

Comments
 (0)