Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Der Befehl bleibt in einer Zeile. Scrollen Sie horizontal, um ihn vor dem Kopieren vollständig zu prüfen.
Sie bevorzugen eine lokale Kopie? Laden Sie die Dateien herunter, die SkillsMP derzeit vorliegen.
SKILL.md wird angezeigt
SKILL.md
Quellanweisungen · Schreibgeschützte Vorschau
name
azure-communication-common-java
description
Azure Communication Services common utilities for Java. Use when working with CommunicationTokenCredential, user identifiers, token refresh, or shared authentication across ACS services.
import com.azure.communication.common.CommunicationTokenCredential;
// Simple static token - no refreshStringuserToken="<user-access-token>";
CommunicationTokenCredentialcredential=newCommunicationTokenCredential(userToken);
// Use with Chat, Calling, etc.ChatClient ()
.endpoint()
.credential(credential)
.buildClient();
chatClient
=
new
ChatClientBuilder
"https://<resource>.communication.azure.com"
Proactive Token Refresh (Long-lived Clients)
import com.azure.communication.common.CommunicationTokenRefreshOptions;
import java.util.concurrent.Callable;
// Token refresher callback - called when token is about to expire
Callable<String> tokenRefresher = () -> {
// Call your server to get a fresh tokenreturn fetchNewTokenFromServer();
};
// With proactive refreshCommunicationTokenRefreshOptionsrefreshOptions=newCommunicationTokenRefreshOptions(tokenRefresher)
.setRefreshProactively(true) // Refresh before expiry
.setInitialToken(currentToken); // Optional initial tokenCommunicationTokenCredentialcredential=newCommunicationTokenCredential(refreshOptions);
Async Token Refresh
import java.util.concurrent.CompletableFuture;
// Async token fetcher
Callable<String> asyncRefresher = () -> {
CompletableFuture<String> future = fetchTokenAsync();
return future.get(); // Block until token is available
};
CommunicationTokenRefreshOptionsoptions=newCommunicationTokenRefreshOptions(asyncRefresher)
.setRefreshProactively(true);
CommunicationTokenCredentialcredential=newCommunicationTokenCredential(options);
import com.azure.communication.common.CommunicationUserIdentifier;
// Create identifier for ACS userCommunicationUserIdentifieruser=newCommunicationUserIdentifier("8:acs:resource-id_user-id");
// Get raw IDStringrawId= user.getId();
import com.azure.communication.common.MicrosoftTeamsUserIdentifier;
// Teams user identifierMicrosoftTeamsUserIdentifierteamsUser=newMicrosoftTeamsUserIdentifier("<teams-user-id>")
.setCloudEnvironment(CommunicationCloudEnvironment.PUBLIC);
// For anonymous Teams usersMicrosoftTeamsUserIdentifieranonymousTeamsUser=newMicrosoftTeamsUserIdentifier("<teams-user-id>")
.setAnonymous(true);
UnknownIdentifier
import com.azure.communication.common.UnknownIdentifier;
// For identifiers of unknown typeUnknownIdentifierunknown=newUnknownIdentifier("some-raw-id");
Identifier Parsing
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationIdentifierModel;
// Parse raw ID to appropriate typepublic CommunicationIdentifier parseIdentifier(String rawId) {
if (rawId.startsWith("8:acs:")) {
returnnewCommunicationUserIdentifier(rawId);
} elseif (rawId.startsWith("4:")) {
Stringphone= rawId.substring(2);
returnnewPhoneNumberIdentifier(phone);
} elseif (rawId.startsWith("8:orgid:")) {
StringteamsId= rawId.substring(8);
returnnewMicrosoftTeamsUserIdentifier(teamsId);
} else {
returnnewUnknownIdentifier(rawId);
}
}
// Clean up when done
credential.close();
// Or use try-with-resourcestry (CommunicationTokenCredentialcred=newCommunicationTokenCredential(options)) {
// Use credential
chatClient.doSomething();
}
Cloud Environments
import com.azure.communication.common.CommunicationCloudEnvironment;
// Available environmentsCommunicationCloudEnvironmentpublicCloud= CommunicationCloudEnvironment.PUBLIC;
CommunicationCloudEnvironmentgovCloud= CommunicationCloudEnvironment.GCCH;
CommunicationCloudEnvironmentdodCloud= CommunicationCloudEnvironment.DOD;
// Set on Teams identifierMicrosoftTeamsUserIdentifierteamsUser=newMicrosoftTeamsUserIdentifier("<user-id>")
.setCloudEnvironment(CommunicationCloudEnvironment.GCCH);