Intercom Deployment

Deploy a CustomGPT Agent into Intercom's Messenger

This process is completed in two steps, meaning two separate Zaps that work together to accomplish a CustomGPT Agent's deployment into Intercom's Messenger.

πŸš€ Step 1: Intercom β†’ CustomGPT Conversation Mapping

This first Zap sets up the β€œconversation handoff” system so Intercom conversations can be linked to CustomGPT sessions. Here is the link to the template.


What this Zap Does

When a new Intercom conversation starts, it:

  • Captures the Intercom conversation details.
  • Creates a new CustomGPT conversation (so the AI has a fresh context).
  • Stores the mapping between Intercom Conversation ID and CustomGPT Conversation ID (so Step 2 can find it later).

How to Use It

  1. Click β€œTry this Zap” from the shared link.
  2. Connect Intercom
    • Authorize Zapier to access your Intercom account.
    • This lets Zapier watch for new conversations.
  3. Connect CustomGPT
    • Authorize Zapier to use your CustomGPT project/agent.
    • This allows the Zap to create a new CustomGPT conversation.
  4. Connect Storage by Zapier (or Tables)
    • This step saves the mapping.
    • Key = intercom:{conversation_id}
    • Value = session_id

Why This Step Matters

Without this Zap, Step 2 (the reply automation) won’t know which CustomGPT conversation to continue.

Think of this as the β€œaddress book” that ties Intercom threads to CustomGPT threads.


βœ… After Step 1 is Live

Every time a new user conversation starts in Intercom:

  • A matching conversation is created in CustomGPT.
  • The IDs are stored so you can look them up later.
  • Now Step 2 can take over for ongoing replies, since it can pull the right CustomGPT conversation ID from storage.

πŸ“˜ Guide 2: Intercom ↔ CustomGPT Automated Reply Zap

This Zap takes a user’s reply in Intercom, finds the correct CustomGPT conversation, processes the message through CustomGPT, sanitizes the response, and replies back in Intercom. It also has safe-guards (filters, fallback branches, sanitization) to ensure clean execution.


1. Trigger β€” Intercom: Contact Replied

  • App: Intercom
  • Event: Contact Replied
  • Purpose: Fires whenever a user responds in an Intercom conversation.
  • Output: Conversation ID, author details, etc.

2. Intercom: Reply to Conversation (Optional Acknowledgement)

  • Purpose: Immediately acknowledge the user so they don’t wait in silence.
  • Reply Type: Admin Reply
  • Reply Body: e.g. Hang on… thinking…
  • Admin ID: Choose the bot/admin account to reply as.

3. Storage by Zapier: Get Value

  • Purpose: Retrieve the CustomGPT conversation ID linked to this Intercom conversation.
  • Key: intercom:{Conversation ID} (from Step 1).
  • Output: The stored session_id (from your Step-1 Zap mapping).

4. Intercom: API Request (Beta)

  • HTTP Method: GET
  • URL: https://api.intercom.io/conversations/{{Conversation ID}}
  • Query Parameters:
    • display_as=plaintext
    • include=conversation_parts
  • Purpose: Fetch the full conversation with message parts in plain text.

5. Code by Zapier: Run JavaScript

  • Input: conversation_json = Response Body from Step 4.
  • Purpose: Extract the latest valid end-user message.
const raw = inputData.conversation_json;
const convo = (typeof raw === 'string') ? JSON.parse(raw) : raw;
const parts = (convo.conversation_parts && convo.conversation_parts.conversation_parts) || [];
const stats = convo.statistics || {};
const lcr = Number(stats.last_contact_reply_at || 0);

let msg = '', partId = '', ts = '';

// prefer exact timestamp match to last_contact_reply_at
for (let i = parts.length - 1; i >= 0; i--) {
  const p = parts[i] || {};
  const a = (p.author && p.author.type || '').toLowerCase();
  const t = (p.part_type || '').toLowerCase();
  const b = (p.body || '').trim();
  if (a === 'user' && t === 'comment' && b && Number(p.created_at || 0) === lcr) {
    msg = b; partId = String(p.id || ''); ts = String(p.created_at || ''); break;
  }
}
// fallback: newest→oldest user comment with body
if (!msg) {
  for (let i = parts.length - 1; i >= 0; i--) {
    const p = parts[i] || {};
    const a = (p.author && p.author.type || '').toLowerCase();
    const t = (p.part_type || '').toLowerCase();
    const b = (p.body || '').trim();
    if (a === 'user' && t === 'comment' && b) { msg = b; partId = String(p.id||''); ts = String(p.created_at||''); break; }
  }
}
// last resort: top-level source
if (!msg && convo.source) {
  const s = convo.source;
  if ((s.author && s.author.type || '').toLowerCase() === 'user' && (s.body || '').trim()) {
    msg = (s.body || '').trim(); partId = 'source'; ts = String(convo.updated_at || '');
  }
}
return { user_message: msg, matched_part_id: partId, matched_created_at: ts };
  • Outputs used: user_message (to send to CustomGPT).

6. Filter by Zapier: Guardrail

  • Conditions:
    • 5. User Message β†’ Exists
    • 5. User Message β†’ Does not exactly match (blank)
  • Purpose: Only proceed if there is a real user message. Prevents bot loops or empty values.
  • If fails: Zap runs the Error path.

7. CustomGPT: Send Message

  • Project Name: Intercom Test Agent
  • Conversation Name: Value from Step 3 (session_id)
  • Lang: English
  • Message Text: Step 5 β†’ user_message
  • Purpose: Forward the latest user reply into the correct GPT conversation.

8. Formatter by Zapier: Clean CustomGPT Output (Success Path)

  • Transform: Convert HTML to Markdown (or strip HTML if you prefer plain text)
  • Input: CustomGPT response text
  • Purpose: Prevent Intercom chat from breaking due to HTML tags.

9. Intercom: Reply to Conversation (Success Path)

  • Conversation ID: From Step 1
  • Reply Type: Admin Reply
  • Reply Body: Sanitized CustomGPT response (from Step 8)
  • Purpose: Deliver the AI’s clean response back to the user.

10. Error Path (when Filter fails or GPT fails)

  • Intercom β†’ Reply to Conversation: Acknowledge inability (e.g., β€œLooping in a teammate…”).
  • CustomGPT β†’ Send Message (optional retry): If you want a backup path.
  • Formatter β†’ Sanitize: Clean any backup message.
  • Intercom β†’ Reply to Conversation: Send fallback message to the user.

βœ… End-to-End Flow Recap

  1. Trigger when a user replies in Intercom
  2. Optionally send an immediate β€œthinking” reply
  3. Retrieve the mapped GPT conversation ID
  4. Pull the full Intercom conversation in plain text
  5. Extract the latest user message via Javascript
  6. Filter out empties or system messages
  7. Send the clean message to CustomGPT
  8. Sanitize GPT’s output
  9. Reply back in Intercom as the bot/admin
  10. Error path β†’ escalate to human with a clean fallback

⚑ With this Zap, you’ve built a robust Intercom β†’ CustomGPT auto-responder that:

  • Keeps sessions consistent
  • Ensures only real user messages get passed
  • Strips rich HTML safely
  • Provides a clean handoff when AI can’t answer