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
- Blueprint
- C++ / Input parameters
Chat->CreateUser(
FString UserID,
FPubnubChatUserData UserData
);
Parameter | Type | Required | Description |
---|---|---|---|
UserID | FString | Yes | Unique user identifier. |
UserData | FPubnubChatUserData | Yes | Additional user data. |
FPubnubChatUserData
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
UserName | FString | No | n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
ExternalID | FString | 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 | FString | No | n/a | URL of the user's profile picture. |
Email | FString | No | n/a | User's email address. |
CustomDataJson | FString | No | n/a | JSON 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. |
Status | FString | 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 | FString | 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 |
---|---|
UPubnubUser* | Returned object containing the new user data. |
Errors
If you try to create a user without providing their ID, you will receive the ID is required
error. If you try to create a user that already exists, you will receive the User with this ID already exists
error.
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.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
// Define user data
FString UserID = "UniqueUser123";
FPubnubChatUserData UserData;
UserData.UserName = "JohnDoe";
UserData.ExternalID = "External123";
UserData.ProfileUrl = "http://example.com/profile/johndoe.jpg";
show all 22 lines