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?,
externalId: String?,
profileUrl: String?,
email: String?,
custom: CustomObject?,
status: String?,
type: String?,
): PNFuture<User>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
id | String | Yes | n/a | Unique user identifier. |
name | String | No | n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
externalId | String | No | n/a | User's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
profileUrl | String | No | n/a | URL of the user's profile picture. |
email | String | No | n/a | User's email address. |
custom | ObjectCustom | No | n/a | Any object of key-value pairs with supported data types. Filtering App Context data through the custom property is not recommended in SDKs. |
status | String | No | n/a | 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 status to mark users in your chat app as invited , active , or archived . |
type | String | No | n/a | 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 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
Type | Description |
---|---|
PNFuture<User> | PNFuture 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.
// create a custom object with the user's title and LinkedIn profile URL
val customAttributes = CustomObject().apply {
this["title"] = "Support Agent"
this["linkedin"] = "https://www.linkedin.com/in/support_agent_15"
}
// reference the "chat" object and invoke the "createUser()" method
chat.createUser(
id = "support_agent_15",
name = "John Doe",
externalId = null,
profileUrl = "https://example.com/avatar.jpg",
email = null,
custom = customAttributes,
status = null,
show all 23 lines