# 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.

# API

# 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 = new LoginConfig.Builder()
        .SetUserId("THIS IS YOUR USER ID")
        .SetUserConfig(...)
        .SetEnterpriseAuth(...)
        .Build();
AIHelpSupport.Login(loginConfig);

# 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.

AIHelpSupport.Logout();

# Event

# Logging in

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

AIHelpSupport.RegisterAsyncEventListener(AIHelp.EventType.UserLogin, 
    (jsonData, 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.

AIHelpSupport.RegisterAsyncEventListener(AIHelp.EventType.EnterpriseAuth, 
    async (ignored, ack) => {
        await Task.Delay(1000);
        ack("{\"token\":\"this is your async 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 = new UserConfig.Builder()
            .SetUserName("AIHelper")
            .SetServerId("s-101")
            .SetUserTags("vip1,suggestion")
            .SetCustomData("{'total_recharge': 10000, 'level': 34}")
            .Build();
    
    LoginConfig loginConfig = new LoginConfig.Builder()
            .SetUserId("THIS IS YOUR USER ID")
            .SetUserConfig(userConfig)
            .Build();
    
    AIHelpSupport.Login(loginConfig);
    

# EnterpriseAuth

Note

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.EnterpriseAuth event to obtain the user token if you enable this field.
  • Code example:


     



    LoginConfig loginConfig = new LoginConfig.Builder()
        .setUserId("THIS IS YOUR USER ID")
        .setEnterpriseAuth(true)
        .Build();
    AIHelpSupport.Login(loginConfig);
    
Last Updated: 7/7/2024, 10:13:59 AM