Manage user updates
Update user details and receive real-time update events.
Requires App Context
Enable App Context in the Admin Portal to store user data.
Update user details
Edit user metadata with update() or updateUser().
update()- call on aUserobject (no ID needed)updateUser()- call on aChatobject (requires user ID)
Method signature
These methods take the following parameters:
-
update()1user.update(
2 name: String? = nil,
3 externalId: String? = nil,
4 profileUrl: String? = nil,
5 email: String? = nil,
6 custom: [String: JSONCodableScalar]? = nil,
7 status: String? = nil,
8 type: String? = nil
9) async throws -> UserImpl -
updateUser()1chat.updateUser(
2 id: String,
3 name: String? = nil,
4 externalId: String? = nil,
5 profileUrl: String? = nil,
6 email: String? = nil,
7 custom: [String: JSONCodableScalar]? = nil,
8 status: String? = nil,
9 type: String? = nil
10) async throws -> UserImpl
Input
id#- Required in update()
- No
- Required in updateUser()
- Yes
name#- Display name for the user (must not be empty or consist only of whitespace characters).
- Required in update()
- No
- Required in updateUser()
- No
externalId#- User's identifier in an external system. You can use it to match
idwith a similar identifier from an external database.- Required in update()
- No
- Required in updateUser()
- No
profileUrl#- URL of the user's profile picture.
- Required in update()
- No
- Required in updateUser()
- No
email#- User's email address.
- Required in update()
- No
- Required in updateUser()
- No
custom#- JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the
customproperty is not recommended in SDKs.- Required in update()
- No
- Required in updateUser()
- No
status#- Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use
statusto mark users in your chat app asinvited,active, orarchived.- Required in update()
- No
- Required in updateUser()
- No
type#- Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use
typeto group users by their roles in your app, such asmoderator,player, orsupport-agent.- Required in update()
- No
- Required in updateUser()
- No
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Output
UserImpl#- Returned object containing the updated user metadata.
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Change the link to the user's support_agent_15 LinkedIn profile to https://www.linkedin.com/mkelly_vp2.
-
update()1 -
updateUser()1
Get user updates
Receive real-time updates when a User object is edited with onUpdated(), or be notified when it is deleted with onDeleted().
You can also use user.stream.updates() and user.stream.deletions() for AsyncStream-based equivalents.
For monitoring multiple users at once, streamUpdatesOn() remains available.
Deprecation
streamUpdates() is deprecated. Use onUpdated() and onDeleted() (closure-based) or user.stream.updates() and user.stream.deletions() (AsyncStream-based) instead.
Method signature
-
onUpdated()— closure called when the user metadata changes1user.onUpdated(
2 callback: @escaping (UserImpl) -> Void
3) -> AutoCloseable -
onDeleted()— closure called when the user is deleted1user.onDeleted(
2 callback: @escaping () -> Void
3) -> AutoCloseable -
streamUpdatesOn()(static) — monitors multiple users1UserImpl.streamUpdatesOn(users: [UserImpl]) -> AsyncStream<[UserImpl]>
Input
callback(inonUpdated) required#- Closure called with the updated user whenever its metadata changes.
callback(inonDeleted) required#- Closure called when the user is deleted.
users(instreamUpdatesOn) required#- A collection of
UserImplobjects for which you want to get updates.
Output
AutoCloseable#- An object you must retain. When released or closed, the listener stops.
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Get updates on support_agent_15.
- Closure
- AsyncStream
1
1
Watch multiple users
Get updates on multiple user objects at once.
- Closure
- AsyncStream
1
1