Skip to main content

Overview

Our identity verification system allows you to:
  • Securely pass user information to chatbots
  • Connect interactions to actual user accounts
  • Track user history and interactions

How It Works

  1. Generate a secret key for your workspace in the TeamAI dashboard
  2. On your server, create an HMAC-SHA256 hash of a user’s ID using this secret
  3. Send the user ID and hash to your frontend
  4. Use the TeamAI SDK’s identify method to verify the user
Never expose your secret key in client-side code. Always generate the hash on your server.

Obtaining the User Hash

The secret key is generated in the TeamAI dashboard under Settings > Identity Verification. Use this key to generate a hash on your server:
// Node.js example
const crypto = require("crypto");

const secret = "your_workspace_secret"; // Your verification secret key
const userId = "user_123"; // A unique identifier for your user

const hash = crypto.createHmac("sha256", secret).update(userId).digest("hex");

Identity Method

Use the identify method to verify user identity:
const chatbotInstance = tai.getInstance("YOUR_ASSISTANT_ID");

chatbotInstance.identify({
  user_id: "user-123",
  user_hash: "computed-hash-from-server",
  user_metadata: { 
    name: "John Doe",
    email: "[email protected]",
    company: "Acme Inc"
  }
});

Parameters

PropertyTypeRequiredDescription
user_idstringYesUnique identifier for the user
user_hashstringYesServer-generated HMAC SHA-256 hash of the user_id
user_metadataobjectNoAdditional user information (max 1000 characters total)
The user_metadata object can include any user attributes you want to make available to your chatbot, such as name, email, or custom fields.

Complete Example

This example shows how to implement identity verification in a real application:
// On your server (Node.js example)
app.get('/api/auth/chatbot-identity', isAuthenticated, (req, res) => {
  const userId = req.user.id;
  const secret = process.env.TEAMAI_VERIFICATION_SECRET;
  
  // Generate the hash using HMAC SHA-256
  const hash = crypto.createHmac("sha256", secret).update(userId).digest("hex");
  
  // Return the data to your frontend
  res.json({
    userId: userId,
    userHash: hash
  });
});

// On your frontend
window.addEventListener("teamAIChatbotReady", async function() {
  const chatbotInstance = tai.getInstance("YOUR_ASSISTANT_ID");

  try {
    // Fetch identity verification data from your server
    const response = await fetch('/api/auth/chatbot-identity');
    const { userId, userHash } = await response.json();
    
    // Verify user identity
    chatbotInstance.identify({
      user_id: userId,
      user_hash: userHash,
      user_metadata: {
        name: userProfile.name,
        email: userProfile.email,
        plan: userProfile.subscription
      }
    });
    
    console.log('User identity verified successfully');
  } catch (error) {
    console.error('Identity verification failed:', error);
  }
});

Security Considerations

  • Never expose your verification secret key in client-side code
  • Always generate the hash on your server
  • Use HTTPS for all communication between your server and client
  • The user_id should be a unique identifier that doesn’t change for each user
  • Consider using a UUID or database ID rather than personally identifiable information

Troubleshooting

If identity verification fails:
  1. Make sure you’re using the correct environment for your test (local vs production)
  2. Verify that the user ID in your hash generation matches the one you’re passing to identify()
  3. Check the browser console for any error messages from the SDK
  4. Enable debug mode by adding ?teamAIDebug=true to your URL to see detailed logs