-
Notifications
You must be signed in to change notification settings - Fork 4
Customize user details
Since Kaleyra Video solution treats users of a company referring to them only via anonymous identifiers, in order to display users details on sdk integrations (chat widget, Android and iOS SDks) a set of client-side APIs named as User Details Providers is available.
A user alias is a unique identifier used to map your users in the Kaleyra Video ecosystem. Those identifiers cannot describe your users properly so if you would like to display in-chat or in-call users adequately you must provide details for user alias with UserDetailsProvider interface shown below.
UserDetailsProvider userDetailsProvider = new UserDetailsProvider() {
@Override
public void onUserDetailsRequested(@NonNull List<String> userAliases, @NonNull Completion<Iterable<UserDetails>> completion) {
ArrayList<UserDetails> details = new ArrayList<>();
// fetch asynchronously data on your local or network storage for each user alias
for(String userAlias : userAliases) {
details.add(new UserDetails.Builder(userAlias)
.withDisplayName("display name")
.withImageUri("https://www.example.com/user_image.png") // or .withImageUrl("url") or .withResId(resId)
.withNickName("nickname")
.withFirstName("name")
.withLastName("last name")
.withEmail("email")
.build());
}
// provide results to the OnUserDetailsListener object
completion.success(userDetailsIterable);
}
});
BandyerSDK.getInstance().setUserDetailsProvider(userDetailsProvider);
A caching version of User Details Provider is now shipped with the SDK. The CachedUserDetailsProvider extends the UserDetails Provider and will cache at runtime previous request preventing the integrating app's logic be called again with same parameters.
Since every client had to provide a User Details Provider implementation in order to obtain user display name and image customization on the client call and chat UIs, has now been released a new convenient and centralized way to achieve the same result.
We refer to this newly released API as Server Side User Details Provider.
In order to enable this functionality you must specify a valid user_details_provider_url
through the company update rest API.
The provider url, if defined, will be used as an endpoint to request the details of the users through an http post request whenever a client needs to display some user details.
As mentioned above, the best use case scenario for the Server Side User Details Provider implementation is represented by those integrations that relay on an heterogeneous usage of client sdks (e.g. mobile sdks alongside chat widget implementation). Using the Server Side User Details Provider will result in a more concise (and less error prone too) way to display users information. Furthermore it not will be necessary to implement the User Details Provider APIs for the client SDKs.
Despite what has been mentioned, the User Details Provider will be maintained for those integrations that cannot relay on webhook implementations.
More details about the REST integration of the Server Side User Details Provider can be found here.
In order to use the Server Side User Details Provider on Android, once implemented the REST integration, it will uniquely needed to remove the provider user details provider on the BandyerSDK singleton, if previously set.
N.B If a Server Side User Details Provider webhook has been defined server side, remember that the provider and formatter implemented by the client have more priority over the server side, so be careful as the client side implementation of the User Details Provider API will override the user details coming from the Server Side User Details Provider.
Once user aliases are retrieved from your local or network storage with UserDetailsProvider, provide a formatter to display users textual info. The main advantage of using UserDetailsFormatter is that display data can be customized based on the context that has requested the display, so for example the display of a user can differ when has to be printed on a notification or on the ringing activity. FormatContext object describes which module (call or chat) has requested the user to display, so you can change how user details are displayed.
UserDetailsFormatter userDetailsFormatter = new UserDetailsFormatter() {
@NonNull
@Override
public String format(@NonNull UserDetails userDetails, @NonNull FormatContext context) {
if (context.getComponent() instanceof BandyerComponent.CallComponent)
if (context.isNotification())
return userDetails.getNickName();
else
return userDetails.getEmail();
else return userDetails.getFirstName() + " " +userDetails.getLastName();
}
});
BandyerSDK.getInstance().setUserDetailsFormatter(userDetailsFormatter);