Set User ID
最新の更新:2024-11-06

Set User ID

Developers can set a unique identity ID for Bot users across different channels (e.g., website, APP, LiveChat). This user ID (UserId) allows for user identity association across channels, enabling cross-channel user identity merging, business queries via Tools, maintenance of user attributes, and chat records. Specific application scenarios are as follows:

  • Tools: When the AI Bot calls Tools to make a request to the developer's business API, it will include the UserId in the Header to facilitate user identity recognition by the developer.
  • User Attributes: Once the developer sets the UserId, user attribute information will be attributed to that UserId.
  • Chat Logs: Once the developer sets the UserId, the chat logs between the user and the Bot will be attributed to that UserId.
  • Event Callback: Once the developer sets the UserId, the event callback generated in the iframe/widget will report this information to GA4/webhook.

⚠️ The user ID (UserId) should be the unique identity identifier of the user within the developer's business system. Through this UserId, business data information such as the user's VIP level, user tags, and user orders can be queried.

API Set User ID

When developers integrate Bot capabilities via API to provide services to users, they usually need to create a conversation ID (conversation_id) for different users as the basic carrier for providing AI services. The prerequisite for creating a conversation_id is that a user ID must be set first.

curl -X POST https://api.gptbots.ai/v1/conversation \ -H 'Authorization: Bearer your_apikey' \ -H 'Content-Type: application/json' \ -d '{ "user_id": "your_user_id" // Note: Supports Bot developers in setting custom user IDs }'
          curl -X POST https://api.gptbots.ai/v1/conversation \ 
  -H 'Authorization: Bearer your_apikey' \ 
  -H 'Content-Type: application/json' \ 
  -d '{
        "user_id": "your_user_id" // Note: Supports Bot developers in setting custom user IDs
}'

        
このコードブロックは、フローティングウィンドウに表示されます

For methods and detailed guidelines on creating conversation_id, please refer to Create Conversation.

Bubble Widget Set User ID

When developers use the Bubble Widget method to integrate Bot into their website to provide services, they can set the user ID through the API interface provided by the GPTBots Bubble Widget SDK while the website user is logged in.

window.ChatBot.setUserId("your_user_id") // Note: Supports Bot developers in setting custom user IDs
          window.ChatBot.setUserId("your_user_id")
// Note: Supports Bot developers in setting custom user IDs

        
このコードブロックは、フローティングウィンドウに表示されます

For more detailed operational guidelines, please refer to Bubble Widget - Advanced Usage.

iframe Set User ID

When developers use the iframe method to integrate Bot into their website to provide services, they can set the user ID through the iframe method provided by GPTBots while the website user is logged in.

  • Solution 1: The webpage embedded iframe address rule is: iframe_url+?user_id=your_user_id

    Note: Supports Bot developers in setting user identity ID, if not set, the default user identity ID generated by GPTBots will be used

  • Solution 2: Dynamically set the user ID through javascript code
Array.from(document.getElementsByTagName('iframe')).filter(iframe => iframe.src.includes('gptbots')).forEach(iframe => iframe.contentWindow.postMessage('{"type":"UserId","data":"your_user_id"}', '*'))
          Array.from(document.getElementsByTagName('iframe')).filter(iframe => iframe.src.includes('gptbots')).forEach(iframe => iframe.contentWindow.postMessage('{"type":"UserId","data":"your_user_id"}', '*'))

        
このコードブロックは、フローティングウィンドウに表示されます

Note: The above is an example for dynamically setting userId in iframe mode, replace your_user_id with the actual userId For more detailed operational guidelines, please refer to iframe - Advanced Usage

LiveChat Set User ID

When developers use the LiveChat Widget to provide customer service to website users and simultaneously use GPTBots AI Bot to provide customer service, they can achieve identity integration between Bot users and website logged-in users by setting the user ID. While the website user is logged in, the user ID can be set via the API interface provided by the LiveChat Widget SDK.

LiveChatWidget.call("set_session_variables", { user_id: "your_user_id" // Identity ID after website user login });
          LiveChatWidget.call("set_session_variables", {
    user_id: "your_user_id"  // Identity ID after website user login
});

        
このコードブロックは、フローティングウィンドウに表示されます