✦ Chat Service

Integration guide

Add team chat to any software in three steps. Each tenant only sees its own employees.

1 · Create an app

In /admin, create an app for your software and add its origin (for example https://crm.example.com). You get a public app key and a private secret.

2 · Add a token endpoint to your backend

It returns { "token": "…" } for the logged-in user. The token is an HS256 JWT signed with the app secret. The tenant comes from your server, so a user can never switch tenants.

// Node / Next.js (jsonwebtoken or jose)
jwt.sign({ sub: String(user.id), tenant_id: String(user.tenantId), tenant_name: tenant.name,
           name: user.fullName, email: user.email, avatar: user.photoUrl, title: user.designation },
         process.env.CHAT_APP_SECRET, { issuer: process.env.CHAT_APP_KEY, expiresIn: "1h" });
// PHP / Laravel  (sdk/php/ChatService.php)
$chat = new ChatService('https://chat.crmeuroworld.com', env('CHAT_APP_KEY'), env('CHAT_APP_SECRET'));
return response()->json(['token' => $chat->createUserToken(
    ['id' => $user->tenant_id, 'name' => $tenant->name],
    ['id' => $user->id, 'name' => $user->name, 'title' => $user->designation]
)]);

3 · Load the widget

<script src="https://chat.crmeuroworld.com/widget.js"
        data-app-key="pk_xxx"
        data-token-url="/api/chat-token" async></script>

Or use the JavaScript API:

ChatService.init({ appKey: "pk_xxx", getToken: () => fetch("/api/chat-token").then(r => r.json()).then(d => d.token),
                   primaryColor: "#0f766e", theme: "light", browserNotifications: true });
ChatService.openChat({ userId: "42" });           // deep link by YOUR user id
ChatService.on("unread", ({ count, missedCalls }) => updateBadge(count));

Sync employees (recommended)

Push each tenant's roster so colleagues appear before they first open the chat:

POST https://chat.crmeuroworld.com/api/v1/server/users/sync
X-App-Key: pk_xxx
Authorization: Bearer <secret>

{ "tenant": { "id": "12", "name": "Acme" },
  "users": [{ "id": "7", "name": "Ali Khan", "title": "Manager" }],
  "deactivateMissing": true }

Also available: POST /api/v1/server/tokens (mint a token without a JWT library) and POST /api/v1/server/tenants (suspend a tenant). Webhooks: message.created, call.missed, signed with X-Chat-Signature.