Create users

CreateUser() 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:

public CreateUser(
string userId,
ChatUserData additionalData
)

public class ChatUserData
{
public string Username { get; set; } = string.Empty;
public string ExternalId { get; set; } = string.Empty;
public string ProfileUrl { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string CustomDataJson { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
}

Input

ParameterTypeRequiredDefaultDescription
userIdstringYesn/aUnique user identifier.
UsernamestringNon/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.
CustomDataJsonstringNon/aJSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the CustomDataJson 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
UserReturned object containing the new user data.

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.

// Define the custom data for the user
var userData = new ChatUserData
{
Username = "Support Agent",
ExternalId = null, // Assuming no external ID is needed
ProfileUrl = "https://example.com/avatar.png",
Email = "agent@example.com", // Assuming an email is needed
CustomDataJson = "{ \"title\": \"Customer Support Agent\", \"linkedin_profile\": \"https://www.linkedin.com/in/support-agent\" }",
Status = "active", // Assuming the status is Active
Type = "support" // Assuming the user type is support
};

// Create the user with the specified ID and custom data
var user = chat.CreateUser("support_agent_15", userData);
Last updated on