# User Identity

When users log in or log out of the app, make sure to synchronize the status with AIHelp to confirm or reset the user identity.


# login()

When users log into the app, synchronize the user ID with AIHelp so that we can generate a identity token for them.

AIHelpSupport::login("THIS IS YOUR USER ID");

Alternatively, you can achieve other capabilities by configuring LoginConfig, such as other user information, enterprise-level identity authorization, login status callback, etc.:


LoginConfig loginConfig = LoginConfigBuilder()
        .setUserId("THIS IS YOUR USER ID")

# logout

When users log out, call this method to clear the current logged-in user information to ensure the accuracy of the guest identity after logging out.


# Event

# Logging in

You can register the USER_LOGIN event to keep track of the logging in status for current user:

        [](const char *jsonData, Acknowledge ignored) {
            // `jsonData`: { "code": 1, "message": "Success" }

The code field for jsonData can be one of:

  • 1 for success;
  • -1 for invalid user id;
  • -2 for failure, check the message field for more information;

# Authentication

If you intend to authenticate user by your side by configuring setEnterpriseAuth, the ENTERPRISE_AUTH event will be triggered when login API is invoked.

And you should register the event and authenticate the user, and then pass the retrieved user token back to us via the ack callback.

        [](const char *ignored, Acknowledge ack) {
            std::async(std::launch::async, [jsonData, ack]() {
                ack(EventType::ENTERPRISE_AUTH, "{\"token\":\"this is your token\"}");

For compatibility purposes, the data passed back to AIHelp should be in JSON format. The user token should be stored under the key token.

# Definition

# loginConfig

  • Type: LoginConfig
  • Details: Required. Encapsulation of optional configuration items for login.

# userId

  • Type: String
  • Default: A random number generated by the user's device
  • Details: Required. Unique user identifier, cannot be an empty string, 0, or -1.

# userConfig

  • Type: UserConfig
  • Default: null
  • Details: Optional. User information configuration items, including username, server ID, user tags, and other custom data. Besides logging in, you can also call updateUserInfo API to update user information whenever you need.
  • Code example:


    UserConfig userConfig = UserConfigBuilder()
            .setCustomData("{'total_recharge': 10000, 'level': 34}")
    LoginConfig loginConfig = new LoginConfig.Builder()
            .setUserId("THIS IS YOUR USER ID")

# isEnterpriseAuth


Enterprise-level identity authorization should generate tokens by the pre-defined rules, please contact us for more information.

  • Type: boolean
  • Default: false
  • Details: Optional. You need to register the EventType.ENTERPRISE_AUTH event to obtain the user token if you enable this field.
  • Code example:


    LoginConfig loginConfig = LoginConfigBuilder()
            .setUserId("THIS IS YOUR USER ID")
Last Updated: 7/7/2024, 10:13:59 AM