You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/communication-services/concepts/raw-id-use-cases.md
+52-45Lines changed: 52 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ CommunicationIdentifier has the following advantages:
24
24
- Allows using a switch case by type to address different application flows.
25
25
- Allows restricting communication to specific types.
26
26
27
-
On top of these advantages, the ability to instantiate a *CommunicationIdentifier*from Raw ID and being able to retrieve an underlying Raw ID of a *CommunicationIdentifier* of a certain type (for example, `MicrosoftTeamsUserIdentifier`, `PhoneNumberIdentifier`, etc.) makes the following scenarios easier to implement:
27
+
On top of this, the *CommunicationIdentifier* and the derived types (`MicrosoftTeamsUserIdentifier`, `PhoneNumberIdentifier`, etc.) can be converted to its string representation (Raw ID), making the following scenarios easier to implement:
28
28
- Extract identifier details from Raw IDs and use them to call other APIs (such as the Microsoft Graph API) to provide a rich experience for communication participants.
29
29
- Store identifiers in a database and use them as keys.
You can find more platform-specific examples in the following article: [Understand identifier types](./identifiers.md)
52
52
53
53
## Storing CommunicationIdentifier in a database
54
-
Depending on your scenario, you may want to store CommunicationIdentifier in a database. Each type of CommunicationIdentifier has an underlying Raw ID, which is stable, globally unique, and deterministic. The guaranteed uniqueness allows choosing it as a key in the storage. You can map ACS users' IDs to the users coming from the Contoso identity provider.
54
+
One of the typical jobs that may be required from you is mapping ACS users to users coming from Contoso user database or identity provider. This is usually achieved by adding an extra column or field in Contoso user DB or Identity Provider. However, given the characteristics of the Raw ID (stable, globally unique, and deterministic), you may as well choose it as a primary key for the user storage.
55
55
56
56
Assuming a `ContosoUser` is a class that represents a user of your application, and you want to save it along with a corresponding CommunicationIdentifier to the database. The original value for a `CommunicationIdentifier` can come from the Communication Identity, Calling or Chat APIs or from a custom Contoso API but can be represented as a `string` data type in your programming language no matter what the underlying type is:
57
57
@@ -93,53 +93,61 @@ public void GetFromDatabase()
93
93
It will return `CommunicationUserIdentifier`, `PhoneNumberIdentifier`, `MicrosoftTeamsUserIdentifier` or `UnknownIdentifier` based on the identifier type.
94
94
95
95
## Storing CommunicationIdentifier in collections
96
-
If your scenario requires working with several *CommunicationIdentifier* objects in memory, you may want to store them in a collection (dictionary, list, hash set, etc.). A collection is useful, for example, for maintaining a list of call or chat participants. As the hashing logic relies on the value of a Raw ID, you can use *CommunicationIdentifier* in collections that require elements to have a reliable hashing behavior. The following examples demonstrate adding *CommunicationIdentifier* objects to different types of collections and checking if they're contained in a collection by instantiating new identifiers from a Raw ID value. The same approach also works for identifiers that are converted to an *UnknownIdentifier* type. This type is reserved for any new types of identifiers that might be introduced in the future, to maintain the compatibility in older SDK versions.
96
+
If your scenario requires working with several *CommunicationIdentifier* objects in memory, you may want to store them in a collection (dictionary, list, hash set, etc.). A collection is useful, for example, for maintaining a list of call or chat participants. As the hashing logic relies on the value of a Raw ID, you can use *CommunicationIdentifier* in collections that require elements to have a reliable hashing behavior. The following examples demonstrate adding *CommunicationIdentifier* objects to different types of collections and checking if they're contained in a collection by instantiating new identifiers from a Raw ID value.
97
+
98
+
The following example shows how Raw ID can be used as a key in a dictionary to store user's messages:
// Implement custom flow for a new communication user.
147
+
if (users.Contains(CommunicationIdentifier.FromRawId("4:+14255550123"))){
148
+
//...
149
+
}
150
+
}
143
151
```
144
152
145
153
Another use case is using Raw IDs in mobile applications to identify participants. You can inject the participant view data for remote participant if you want to handle this information locally in the UI library without sending it to Azure Communication Services.
@@ -165,26 +173,26 @@ callComposite.events.onRemoteParticipantJoined = { identifiers in
165
173
```
166
174
167
175
## Using Raw ID as key in REST API paths
168
-
When designing a REST API, you can have endpoints that have a unique identifier for your application user in a form of a Raw ID string. If the identifier consists of several parts (like ObjectID, cloud name, etc. if you're using `MicrosoftTeamsUserIdentifier`), using Raw ID allows you to address the entity in the URL path instead of passing the whole composite object as a JSON in the body. So that you can have a more intuitive REST CRUD API.
176
+
When designing a REST API, you can have endpoints that either accept a `CommunicationIdentifier` or a Raw ID string. If the identifier consists of several parts (like ObjectID, cloud name, etc. if you're using `MicrosoftTeamsUserIdentifier`), you might need to pass it in the request body. However, using Raw ID allows you to address the entity in the URL path instead of passing the whole composite object as a JSON in the body. So that you can have a more intuitive REST CRUD API.
- Deserializing to the right identifier type (based on which you can adjust the flow of your app).
183
-
- Extracting details of identifiers (such as an oid for `msteamsuser`).
191
+
- Extracting details of identifiers (such as an oid for `MicrosoftTeamsUserIdentifier`).
184
192
185
193
The example shows both benefits:
186
194
- The type allows you to decide where to take the avatar from.
187
-
- The decomposed details allow you to query the api in the right way.
195
+
- The decomposed details allow you to query the API in the right way.
188
196
189
197
```csharp
190
198
publicvoidExtractIdentifierDetails()
@@ -210,9 +218,9 @@ public void ExtractIdentifierDetails()
210
218
You can access properties or methods for a specific *CommunicationIdentifier* type that is stored in a Contoso database in a form of a string (Raw ID).
211
219
212
220
## Using Raw IDs as key in UI frameworks
213
-
It's possible to use Raw ID of an identifier as a key in UI components to track a certain user and avoid unnecessary re-rendering and API calls.
221
+
It's possible to use Raw ID of an identifier as a key in UI components to track a certain user and avoid unnecessary re-rendering and API calls. In the example, we're changing the order of how users are rendered in a list. In real world, we might want to show new users first or re-order users based on some condition (for example, hand raised). For the sake of simplicity, the following example just reverses the order in which the users are rendered.
0 commit comments