Create users

The createUser() method creates a new user (User object) with a unique User ID.

Requires App Context

To store data about users, you must enable App Context for your app's keyset in the Admin Portal.

Method signature

This method takes the following parameters:

chat.createUser(
id: String,
name: String? = nil,
externalId: String? = nil,
profileUrl: String? = nil,
email: String? = nil,
custom: [String: JSONCodableScalar]? = nil,
status: String? = nil,
type: String? = nil,
completion: ((Swift.Result<UserImpl, Error>) -> Void)? = nil
)

Input

ParameterTypeRequiredDefaultDescription
idStringYesn/aUnique user identifier.
nameStringNon/aDisplay name for the user (must not be empty or consist only of whitespace characters).
externalIdStringNon/aUser's identifier in an external system. You can use it to match id with a similar identifier from an external database.
profileUrlStringNon/aURL of the user's profile picture.
emailStringNon/aUser's email address.
customString: JSONCodableScalarNon/aJSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs.
statusStringNon/aTag 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 status to mark users in your chat app as invited, active, or archived.
typeStringNon/aTag 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 type to group users by their roles in your app, such as moderator, player, or support-agent.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Output

TypeDescription
UserImplUserImpl containing the newly created user object.

Basic usage

Create a user with an ID of support_agent_15. Specify their name, avatar, and custom attributes, such as their title and the LinkedIn profile URL.

let customAttributes: [String: JSONCodableScalar] = [
"title": "Support Agent",
"linkedin": "https://www.linkedin.com/in/support_agent_15"
]

// Create PubNub configuration
let pubNubConfiguration = PubNubConfiguration(
publishKey: "your-publish-key",
subscribeKey: "your-subscribe-key",
userId: "your-user-id"
// Add other required parameters
)

// Create Chat configuration
let chatConfiguration = ChatConfiguration()
show all 53 lines
Last updated on