Skip to main content
APIs involved: Webhooks, Agent Chat API, Configuration API This guide uses HubSpot as the example CRM. The pattern — receive a webhook when a chat closes, fetch the full thread, write to your system — applies to any CRM with an API.

Prerequisites

  • An agent access token with scopes webhooks--all:rw and chats--all:read. Create one in Text under Settings → API access → Personal access tokens.
  • A Node.js server that can receive HTTP POST requests. The URL must be publicly reachable over HTTPS — Text cannot deliver webhooks to localhost.
  • A HubSpot private app token with scopes crm.objects.contacts.write and crm.objects.notes.write. Create one in HubSpot under Settings → Integrations → Private Apps.
Testing locally? Use a tunnel tool like ngrok or localtunnel to expose your local server over HTTPS. Run ngrok http 3000 and use the generated URL (e.g. https://abc123.ngrok.io) as your webhook URL below.

Step 1: Set up the receiver

Before you register the webhook with Text, stand up the endpoint that will receive it. The code below is the minimal server — Steps 2 and 3 fill in what happens inside the handler.
Text expects a 200 response within a few seconds. If your handler takes longer (e.g. waiting on external APIs), respond 200 immediately and process asynchronously.

Step 2: Register the webhook

Once your server is running and reachable, run this command once from your terminal to tell Text where to deliver chat_deactivated events:
To verify the webhook was registered or to remove it later, go to Settings → Integrations → Webhooks in Text, or call list-webhooks and unregister-webhook. When an agent closes a chat, Text POSTs the following to your URL:

Step 3: Fetch the thread

Use chat_id and thread_id from the webhook to call get-chat. Passing thread_id returns that specific session rather than defaulting to the latest one — important when a customer has had multiple conversations.
The response contains everything you need to build a CRM record:
Events with type: "message" are the chat messages. statistics.agent_rating holds the CSAT score and comment if the customer left a rating.

Step 4: Push to HubSpot

Find or create a HubSpot contact from the customer’s email, then attach the transcript as a Note on their timeline. Find or create the contact
Build the transcript and attach it as a Note
The complete server Putting it all together — paste the helper functions from above into the same file:
After this runs, the contact’s HubSpot timeline shows a Note with the transcript and rating:

Going further

Custom properties let you push structured data beyond the transcript — ticket category, order ID, resolved status. Register a property namespace via the Configuration API, then write values with update-chat-properties during or after the chat. Those values appear on the chat object in the get-chat response. Real-time sync: to push messages as they arrive rather than when the chat ends, subscribe to incoming_event and push each message individually.