Intercom Local Dev Loop
Overview
Set up a fast local development workflow for Intercom integrations with proper
test isolation, mocking strategies, and webhook tunneling. The loop has two
lanes: a mocked unit lane that runs offline with no token, and an integration
lane that talks to a real dev workspace and is skipped automatically when no
token is present.
Prerequisites
- Completed
intercom-install-auth setup
- Node.js 18+ with npm/pnpm
- A test/development Intercom workspace (separate from production)
Authentication
The client authenticates with a single Intercom bearer access token, issued per
workspace by the intercom-install-auth step. Read it from
process.env.INTERCOM_ACCESS_TOKEN (loaded from git-ignored .env.development);
never hardcode it. The mocked unit lane needs no token at all — pointing the loop
at a different dev workspace is only a matter of swapping the .env.development
value.
Instructions
Work through these steps to stand up the loop. The full, copy-paste-ready code
for every step lives in the implementation walkthrough.
Scaffold the project structure — an src/intercom/ module (singleton
client.ts, plus contacts.ts / conversations.ts / types.ts), a tests/
tree with a mocks/ factory, and three env files (.env.example committed,
.env.development and .env.test git-ignored). Use Write to create each
file. See implementation.md.
Configure environments — commit .env.example as the template and keep
real tokens in the git-ignored .env.development. See
implementation.md.
Write an environment-aware client singleton that reads the token, throws a
clear error when it is missing, and exposes a resetClient() for tests. The
skeleton:
// src/intercom/client.ts
import { IntercomClient } from "intercom-client";
let instance: IntercomClient | null = null;
export function getClient(): IntercomClient {
if (!instance) {
const token = process.env.INTERCOM_ACCESS_TOKEN;
if (!token) {
throw new Error(
"INTERCOM_ACCESS_TOKEN not set. Copy .env.example to .env.development"
);
}
instance = new IntercomClient({ token });
}
return instance;
}
export function resetClient(): void {
instance = null;
}
Build a mock client factory (tests/mocks/intercom.ts) covering contacts,
conversations, messages, admins, and tags with vi.fn() resolved values, so
the unit lane never touches the network. Full factory in
implementation.md.
Write mocked unit tests against the factory, asserting call arguments and
returned shapes. See implementation.md.
Tunnel webhooks with ngrok — run the local server, ngrok http 3000, and
register the HTTPS URL in Intercom Developer Hub. Use Bash(npx:*) for
ngrok. See implementation.md.
Wire package scripts (dev, test, test:watch, test:integration,
typecheck) — use Edit to add them to package.json, then drive the loop
with Bash(npm:*). See implementation.md.
Output
Following this skill produces a working local Intercom development loop:
- A scaffolded
src/intercom/ client module and tests/ tree with a reusable
mock factory.
- Three environment files — a committed
.env.example template plus git-ignored
.env.development / .env.test.
- An offline mocked unit test lane (
npm run test / test:watch) that runs with
no token and no network.
- A token-gated integration lane (
npm run test:integration) that is skipped
automatically when INTERCOM_ACCESS_TOKEN is absent.
- An ngrok webhook tunnel exposing the local server to Intercom's Developer Hub.
Error Handling
| Error |
Cause |
Solution |
INTERCOM_ACCESS_TOKEN not set |
Missing .env file |
Copy .env.example to .env.development |
| Port 3000 in use |
Another process |
lsof -i :3000 and kill, or change port |
| ngrok tunnel expired |
Free tier 2h limit |
Restart ngrok or use paid plan |
| Mock type mismatch |
SDK updated |
Regenerate mocks from SDK types |
rate_limit_exceeded in dev |
Dev workspace limits |
Add delays between integration tests |
Examples
A minimal mocked unit test (from
implementation.md):
it("should create a user contact", async () => {
const contact = await mockClient.contacts.create({
role: "user",
externalId: "user-123",
email: "test@example.com",
});
expect(contact.id).toBe("mock-contact-id");
expect(mockClient.contacts.create).toHaveBeenCalledOnce();
});
For the token-gated integration test pattern (describe.skipIf, live create +
cleanup) and the commands that drive each lane, see
the examples reference.
Resources
- Full implementation walkthrough — every step's complete code
- Integration examples — live-workspace test pattern and run commands
- intercom-client npm
- Vitest Documentation
- ngrok
- See
intercom-sdk-patterns for production-ready code patterns.
1---2name: intercom-local-dev-loop3description: Configure Intercom local development with testing, mocking, and hot reload. Use when setting up a development environment, writing tests against the Intercom API, or establishing a fast iteration cycle against a dev workspace. Trigger with phrases like "intercom dev setup", "intercom local development", "intercom dev environment", "develop with intercom", "test intercom locally".4license: MIT5---6# Intercom Local Dev Loop
7
8## Overview
9
10Set up a fast local development workflow for Intercom integrations with proper
11test isolation, mocking strategies, and webhook tunneling. The loop has two
12lanes: a mocked unit lane that runs offline with no token, and an integration
13lane that talks to a real dev workspace and is skipped automatically when no
14token is present.
15
16## Prerequisites
17
18- Completed `intercom-install-auth` setup
19- Node.js 18+ with npm/pnpm
20- A test/development Intercom workspace (separate from production)
21
22## Authentication
23
24The client authenticates with a single Intercom bearer access token, issued per
25workspace by the `intercom-install-auth` step. Read it from
26`process.env.INTERCOM_ACCESS_TOKEN` (loaded from git-ignored `.env.development`);
27never hardcode it. The mocked unit lane needs no token at all — pointing the loop
28at a different dev workspace is only a matter of swapping the `.env.development`
29value.
30
31## Instructions
32
33Work through these steps to stand up the loop. The full, copy-paste-ready code
34for every step lives in [the implementation walkthrough](references/implementation.md).
35
361. **Scaffold the project structure** — an `src/intercom/` module (singleton
37 `client.ts`, plus `contacts.ts` / `conversations.ts` / `types.ts`), a `tests/`
38 tree with a `mocks/` factory, and three env files (`.env.example` committed,
39 `.env.development` and `.env.test` git-ignored). Use **Write** to create each
40 file. See [implementation.md](references/implementation.md).
41
422. **Configure environments** — commit `.env.example` as the template and keep
43 real tokens in the git-ignored `.env.development`. See
44 [implementation.md](references/implementation.md).
45
463. **Write an environment-aware client singleton** that reads the token, throws a
47 clear error when it is missing, and exposes a `resetClient()` for tests. The
48 skeleton:
49
50 ```typescript
51 // src/intercom/client.ts
52 import { IntercomClient } from "intercom-client";
53
54 let instance: IntercomClient | null = null;
55
56 export function getClient(): IntercomClient {
57 if (!instance) {
58 const token = process.env.INTERCOM_ACCESS_TOKEN;
59 if (!token) {
60 throw new Error(
61 "INTERCOM_ACCESS_TOKEN not set. Copy .env.example to .env.development"
62 );
63 }
64 instance = new IntercomClient({ token });
65 }
66 return instance;
67 }
68
69 export function resetClient(): void {
70 instance = null;
71 }
72 ```
73
744. **Build a mock client factory** (`tests/mocks/intercom.ts`) covering contacts,
75 conversations, messages, admins, and tags with `vi.fn()` resolved values, so
76 the unit lane never touches the network. Full factory in
77 [implementation.md](references/implementation.md).
78
795. **Write mocked unit tests** against the factory, asserting call arguments and
80 returned shapes. See [implementation.md](references/implementation.md).
81
826. **Tunnel webhooks with ngrok** — run the local server, `ngrok http 3000`, and
83 register the HTTPS URL in Intercom Developer Hub. Use **Bash(npx:*)** for
84 ngrok. See [implementation.md](references/implementation.md).
85
867. **Wire package scripts** (`dev`, `test`, `test:watch`, `test:integration`,
87 `typecheck`) — use **Edit** to add them to `package.json`, then drive the loop
88 with **Bash(npm:*)**. See [implementation.md](references/implementation.md).
89
90## Output
91
92Following this skill produces a working local Intercom development loop:
93
94- A scaffolded `src/intercom/` client module and `tests/` tree with a reusable
95 mock factory.
96- Three environment files — a committed `.env.example` template plus git-ignored
97 `.env.development` / `.env.test`.
98- An offline mocked unit test lane (`npm run test` / `test:watch`) that runs with
99 no token and no network.
100- A token-gated integration lane (`npm run test:integration`) that is skipped
101 automatically when `INTERCOM_ACCESS_TOKEN` is absent.
102- An ngrok webhook tunnel exposing the local server to Intercom's Developer Hub.
103
104## Error Handling
105
106| Error | Cause | Solution |
107|-------|-------|----------|
108| `INTERCOM_ACCESS_TOKEN not set` | Missing .env file | Copy `.env.example` to `.env.development` |
109| Port 3000 in use | Another process | `lsof -i :3000` and kill, or change port |
110| ngrok tunnel expired | Free tier 2h limit | Restart ngrok or use paid plan |
111| Mock type mismatch | SDK updated | Regenerate mocks from SDK types |
112| `rate_limit_exceeded` in dev | Dev workspace limits | Add delays between integration tests |
113
114## Examples
115
116A minimal mocked unit test (from
117[implementation.md](references/implementation.md)):
118
119```typescript
120it("should create a user contact", async () => {
121 const contact = await mockClient.contacts.create({
122 role: "user",
123 externalId: "user-123",
124 email: "test@example.com",
125 });
126
127 expect(contact.id).toBe("mock-contact-id");
128 expect(mockClient.contacts.create).toHaveBeenCalledOnce();
129});
130```
131
132For the token-gated integration test pattern (`describe.skipIf`, live create +
133cleanup) and the commands that drive each lane, see
134[the examples reference](references/examples.md).
135
136## Resources
137
138- [Full implementation walkthrough](references/implementation.md) — every step's complete code
139- [Integration examples](references/examples.md) — live-workspace test pattern and run commands
140- [intercom-client npm](https://www.npmjs.com/package/intercom-client)
141- [Vitest Documentation](https://vitest.dev/)
142- [ngrok](https://ngrok.com/)
143- See `intercom-sdk-patterns` for production-ready code patterns.