Quickstart

Go from ChatAdmin token to a working widget in about fifteen minutes. Mint once per page load; identify logged-in users with userCode.

1. Configure environment

Store the long-lived widget token from ChatAdmin on your server only. Abort if it is empty — do not hardcode a fallback.

Environment

; .env (server only)
BOT_TENANT_TOKEN=<from ChatAdmin — never commit>
BOT_API_URL=https://bot.easygds.it
BOT_SYSTEM_NAME=TRAVELMATIC

2. Mint a session

Call POST /api/chat/token with the envelope described in Authentication. You receive an opaque signature.

Mint helper

<?php
function base64url_encode(string $data): string {
  return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}

function getMimmoSessionSignature(
  string $systemName,
  ?string $companyCode = null,
  string|int|null $userCode = null,
  ?string $userName = null
): ?string {
  $tenantToken = getenv('BOT_TENANT_TOKEN') ?: '';
  if ($tenantToken === '') {
    error_log('MIMMO: BOT_TENANT_TOKEN is empty');
    return null;
  }

  $payload = [
    'systemName' => $systemName,
    'jti'        => bin2hex(random_bytes(16)),
    'exp'        => time() + 300,
    'v'          => 3,
  ];
  if ($companyCode !== null && $companyCode !== '') {
    $payload['companyCode'] = (string) $companyCode; // never (int)
  }
  if ($userCode !== null && $userCode !== '') {
    $payload['userCode'] = $userCode; // number or string OK
  }
  if ($userName) {
    $payload['userName'] = $userName;
  }

  $innerPayload = base64url_encode(json_encode($payload, JSON_UNESCAPED_UNICODE));
  $innerToken   = base64url_encode($tenantToken);
  $body = json_encode(['data' => base64url_encode($innerPayload . '.' . $innerToken)]);

  $api = rtrim(getenv('BOT_API_URL') ?: 'https://bot.easygds.it', '/') . '/api/chat/token';
  $ch = curl_init($api);
  curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => $body,
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_TIMEOUT        => 5,
  ]);
  $response = curl_exec($ch);
  $http = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  if ($http !== 200 || !$response) return null;
  return json_decode($response, true)['signature'] ?? null;
}

3. Embed the widget

Load /chat-widget.js, then call Mimmo("init", …) with key tenantToken set to the mint signature.

Page embed

<?php if (!empty($_SESSION['userCode'])): ?>
<?php
  $sessionSignature = getMimmoSessionSignature(
    BOT_SYSTEM_NAME,
    isset($_SESSION['companyCode']) ? (string)$_SESSION['companyCode'] : null,
    $_SESSION['userCode'],
    $_SESSION['userName'] ?? null
  );
?>
<script src="<?= htmlspecialchars(BOT_API_URL) ?>/chat-widget.js"></script>
<script>
  window.Mimmo("init", {
    tenantToken: <?= json_encode($sessionSignature ?? '') ?>,
    systemName: <?= json_encode(BOT_SYSTEM_NAME) ?>
  });
</script>
<?php endif; ?>

4. Verify

  1. Open a logged-in page gated on userCode (not userId).
  2. Confirm the widget loads and greets the expected system branding.
  3. Send a test message. If mint returns 503, check Mimmo GET /api/health — Redis must be ok.

Next: dig into concepts or the API reference.