Generating Chat API Token

The Chat API token is crucial for authenticating API requests.

Step-by-Step Guide

  1. Generate Token: In the app settings, click on "Generate API Token".
  2. Copy Token: Copy the generated token for use in your application.

Generate from your backend

You can generate the token directly from your backend. Here is an example in various languages:

// Example code for generating a token in Node.js
const jwt = require('jsonwebtoken');

function generateChatApiToken(appId, signingKey, userIdentity) {
  const payload = {
    iss: appId,
    sub: userIdentity,
    exp: Math.floor(Date.now() / 1000) + (365 * 24 * 60 * 60) // 1 year
  };

  try {
    const token = jwt.sign(payload, signingKey);
    return token;
  } catch (err) {
    console.error('Error generating token:', err);
    return null;
  }
}

// Example usage
const appId = 'your_app_id';
const signingKey = 'your_signing_key';
const userIdentity = 'user_identity';

const token = generateChatApiToken(appId, signingKey, userIdentity);
console.log('Generated Token:', token);