project-conversation¶
Account-manager messaging, hosted by the Bricks CRM (brickssas/CRM-PDP) and surfaced in BO Projets through an iframe. The API stores nothing: it returns ready-to-use embed URLs (CrmEmbedUrl, src/__new/lib/providers/crm/crm-embed-url.ts) and the admin's unread count (CrmApi.getChatUnreadCount); the provider owns the CRM front origin, embed paths and api key (env crm.frontUrl, crm.embedApiKey — Doppler CRM_FRONT_URL, CRM_EMBED_API_KEY).
Endpoints¶
All under AdminAuthGuard. The CRM matches email on the admin's login email (better_auth_user.email): the one key both sides share without a mapping table. Rights stay CRM-side (admin / business_developer / viewer, managed_by); the BO only asks whether the admin exists there. The CRM project key is our project id (projectExternalId), see src/__new/lib/providers/crm/README.md.
| Route | Returns | Used by |
|---|---|---|
GET …/access |
available + CRM role, or user-unknown |
sidebar entry, « Conversations projets » page, « Messagerie » button — the module is hidden when unknown |
GET …/all-conversations/embed |
{ url } → {CRM_FRONT_URL}/embed/conversations-all?sessionToken |
« Conversations projets » page |
GET …/:projectId/embed |
{ url } → {CRM_FRONT_URL}/embed/conversations?sessionToken |
« Messagerie » panel of the fiche Projet, fetched on open |
GET …/:projectId/unread-count |
available + unreadCount, or project-unknown / user-unknown |
badge on the « Messagerie » button, polled |
- The embed routes exchange the api key server-side (
/api/auth/embed/user-tokenoruser-token-all) and return a URL that carries only the 24 h session token. The BO browser never sees the key. The CRM hydratessessionTokenwithGET /api/auth/embed/user-session, and still accepts the oldapiKeyquery on those two pages so an existing iframe keeps opening. AsessionTokenURL cannot hydrate against a CRM that does not serveuser-sessionyet. - The BO keeps that URL for 23 h and does not refetch it on window focus or reconnect. A new token changes the iframe
srcand drops the open conversation. After 23 h the cache is gone, so the next open fetches once. accessanswers 200user-unknownfor an admin without a CRM account: the BO hides the module. The embed routes are only reached once access isavailable; an admin or a project the CRM does not know there is anApiException(500,crm.embed-user-not-found/crm.embed-project-not-found): no URL is returned, the BO shows its load error.unread-countstill answers 200project-unknown/user-unknownso the fiche can disable the button.unread-count(CrmApi.getChatUnreadCount) makes two CRM calls per poll: it exchanges the embed api key for a session token bound to the project (/api/auth/embed/user-token), then reads/api/chat/{crmProjectId}/unread-count. No cache of the token: the poll is a cold path.- The count is personal, the only semantics the CRM has: the admin's own unread porteur messages. A CRM
vieweralways gets0. - The sidebar total across projects lives in
bo-projects-pending-work(CrmApi.getGlobalChatUnreadCount): oneuser-token-allexchange, then/api/projects/conversation-summary/unread-count. There, a CRM HTTP or validation failure is logged and the count comes backnullinstead of a 500, so the BO's other counters still show. Missing CRM env stays a 500 (crm.config-missing). - Unknown to the CRM on
unread-countis a 200 withproject-unknown/user-unknown, never a 404: the fiche renders it (disabled button), and a polled query must not toast. Any other CRM failure is anApiException(500), silent on the BO side. - Missing env →
ApiExceptioncrm.config-missing(500), thrown by the provider.
Prerequisite CRM-side¶
The CRM must serve Content-Security-Policy: frame-ancestors 'self' https://bo-projet.bricks.co https://bo-projet.dev.bricks.co http://localhost:3000, otherwise the browser refuses the frame regardless of what BO Projets does. No postMessage is emitted by this embed: nothing to listen to.
Outbound calls¶
The same CrmApi also pings the CRM when a dossier changes — notifyProjectUpdated, over
crm.axios.ts (env crm.url, crm.embedApiKey — Doppler CRM_API_URL, CRM_EMBED_API_KEY,
sent as X-Api-Key). That write belongs to the project-financing-request module; this module
stays read-only.