Docs menu

Guide

Connecting your app

This page gets your app talking to the fakes: start the server, give the app its environment, point its SDK at channelstack, and tell the server where to deliver events. Your app's code doesn't change beyond a base-URL option its SDK already has.

Start the server#

npm i -D channelstack
npm i -g portless
npx channelstack
channelstack 0.0.0 · in-memory

  Control  https://channelstack.localhost/_channelstack
  echo     https://echo.localhost
  slack    https://slack.localhost
  github   https://github.localhost
  linear   https://linear.localhost
  notion   https://notion.localhost
  resend   https://resend.localhost
  google   https://google.localhost
  discord  https://discord.localhost
  openai   https://openai.localhost
  UI       https://channelstack.localhost/?login=…

  `channelstack env` prints tokens and URLs as .env lines

npx channelstack is short for npx channelstack start. It registers the *.localhost names with portless, which serves them over HTTPS. The UI line is a one-time link that signs one browser in; channelstack ui prints a fresh one. echo is an internal driver channelstack uses to test itself; you can ignore it. openai is the fake OpenAI, for your agent's model.

The server keeps everything in memory. Stop it with Ctrl+C, and the next start begins with an empty world.

Without portless#

If portless isn't installed, the server stops with portless isn't installed. Install it (npm install -g portless) or start with --no-portless. Without portless, everything is served over plain HTTP on one loopback port, with a path prefix per fake:

npx channelstack start --no-portless --port 4500

The fakes are then at http://127.0.0.1:4500/slack, /github, /linear, /notion, /resend, /google and /discord, the fake OpenAI at /openai/v1, and channelstack env prints those URLs instead. (googleapis keeps Gmail's paths at the root of whatever host it is given, so without portless Gmail's API is served at the server's root too, and GOOGLE_API_URL is http://127.0.0.1:4500/.) --port defaults to 4500 without portless; --port 0 picks a free port. Plain HTTP on loopback needs no certificate, so this is also the simplest way around TLS trust problems.

Give the app its environment#

channelstack env asks the running server for the lines your app needs and prints them in .env format:

npx channelstack env >> .env.local
SLACK_API_URL=https://slack.localhost/api/
SLACK_BOT_TOKEN=xoxb-…
SLACK_APP_TOKEN=xapp-…
SLACK_SIGNING_SECRET=…
GITHUB_API_URL=https://github.localhost
GITHUB_APP_ID=…
…

What it prints, per platform:

PlatformVariables
SlackSLACK_API_URL (ends in /api/), SLACK_BOT_TOKEN (xoxb-…), SLACK_APP_TOKEN (xapp-…, for Socket Mode), SLACK_SIGNING_SECRET
GitHubGITHUB_API_URL, GITHUB_APP_ID, GITHUB_APP_SLUG (my-agent), GITHUB_INSTALLATION_ID, GITHUB_BOT_USER_ID, GITHUB_PRIVATE_KEY, GITHUB_WEBHOOK_SECRET
LinearLINEAR_API_URL (ends in /graphql), LINEAR_ACCESS_TOKEN (lin_oauth_…), LINEAR_WEBHOOK_SECRET, LINEAR_CLIENT_ID, LINEAR_CLIENT_SECRET
NotionNOTION_BASE_URL, NOTION_TOKEN (ntn_…), NOTION_VERIFICATION_TOKEN
ResendRESEND_BASE_URL, RESEND_API_KEY (re_…), RESEND_WEBHOOK_SECRET (whsec_…), RESEND_FROM (my-agent <my-agent@acme.example>, the address it sends from)
GoogleGOOGLE_API_URL (the root for googleapis), GOOGLE_TOKEN_URL, GOOGLE_CERTS_URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET (GOCSPX-…), GOOGLE_REFRESH_TOKEN (1//0…), GMAIL_ADDRESS, GOOGLE_PUBSUB_TOPIC, GOOGLE_PUSH_SERVICE_ACCOUNT, GOOGLE_PUSH_AUDIENCE
DiscordDISCORD_API_URL (discord.js's rest.api), DISCORD_TOKEN, DISCORD_APPLICATION_ID, DISCORD_PUBLIC_KEY, DISCORD_GUILD_ID
The modelOPENAI_BASE_URL (ends in /v1), OPENAI_API_KEY (sk-proj-…), for the fake OpenAI

It also prints three ECHO_* lines for the internal driver. A platform that runs live prints nothing: there, the app uses its own real configuration.

GITHUB_PRIVATE_KEY is a PEM on one line, with \n for its line breaks, because an .env line is one line. Turn it back into a PEM in your app: GITHUB_PRIVATE_KEY.replaceAll("\\n", "\n"). Probot, Octokit's App auth and most deploy targets take the key this way.

Write the app so it uses an API URL only when the variable is set. Then the same code talks to the fake in tests and to the real platform in production.

Point each SDK at the fake#

Every platform SDK already has a base-URL option. These are the ones the reference agents use:

SDKOptionVariable
Bolt for JavaScriptclientOptions: { slackApiUrl }SLACK_API_URL
Bolt for Python, slack_sdkWebClient(base_url=…)SLACK_API_URL
Octokit, @octokit/restbaseUrlGITHUB_API_URL
ProbotbaseUrl in Probot.defaults(…)GITHUB_API_URL
@linear/sdkapiUrlLINEAR_API_URL
@notionhq/clientbaseUrlNOTION_BASE_URL
resendnone: it reads the variable itselfRESEND_BASE_URL
googleapisrootUrl in google.gmail({ … })GOOGLE_API_URL
google-auth-libraryendpoints in new OAuth2Client(…)GOOGLE_TOKEN_URL, GOOGLE_CERTS_URL
Chat SDK adapters (@chat-adapter/slack, /github, /linear)apiUrl, or read from the environmentSLACK_API_URL, GITHUB_API_URL, LINEAR_API_URL
discord.jsrest.api in new Client({ rest: { api } })DISCORD_API_URL
openai, @ai-sdk/openainone: they read the variables themselvesOPENAI_BASE_URL, OPENAI_API_KEY

Slack with Bolt#

import { App } from "@slack/bolt";

const { SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, SLACK_API_URL } = process.env;

const app = new App({
  token: SLACK_BOT_TOKEN,
  signingSecret: SLACK_SIGNING_SECRET,
  ...(SLACK_API_URL ? { clientOptions: { slackApiUrl: SLACK_API_URL } } : {}),
});

await app.start(3000);

In Python, give Bolt a WebClient with the base URL:

import os

from slack_bolt import App
from slack_sdk import WebClient

client = WebClient(
    token=os.environ["SLACK_BOT_TOKEN"],
    base_url=os.environ.get("SLACK_API_URL", "https://slack.com/api/"),
)
app = App(client=client, signing_secret=os.environ["SLACK_SIGNING_SECRET"])

GitHub with Octokit or Probot#

import { createAppAuth } from "@octokit/auth-app";
import { Octokit } from "@octokit/rest";

const { GITHUB_APP_ID, GITHUB_PRIVATE_KEY, GITHUB_API_URL } = process.env;
const privateKey = GITHUB_PRIVATE_KEY!.replaceAll("\\n", "\n");

const octokit = (installationId: number) =>
  new Octokit({
    authStrategy: createAppAuth,
    auth: { appId: GITHUB_APP_ID, privateKey, installationId },
    ...(GITHUB_API_URL ? { baseUrl: GITHUB_API_URL } : {}),
  });

With Probot, pass the same values to Probot.defaults:

import { Probot, Server } from "probot";

const { GITHUB_APP_ID, GITHUB_PRIVATE_KEY, GITHUB_WEBHOOK_SECRET, GITHUB_API_URL } = process.env;

const server = new Server({
  Probot: Probot.defaults({
    appId: GITHUB_APP_ID,
    privateKey: GITHUB_PRIVATE_KEY!.replaceAll("\\n", "\n"),
    secret: GITHUB_WEBHOOK_SECRET,
    ...(GITHUB_API_URL ? { baseUrl: GITHUB_API_URL } : {}),
  }),
  port: 3000,
  webhookPath: "/api/github/webhooks",
});

The fake serves the API both at the root (like api.github.com) and at /api/v3 (like GitHub Enterprise), because some SDKs assume the Enterprise layout once a host is set.

Linear and Notion#

import { LinearClient } from "@linear/sdk";
import notionClient from "@notionhq/client";

// @notionhq/client is CommonJS: Node gives it to an ES module as its default export.
const { Client } = notionClient;
const { LINEAR_ACCESS_TOKEN, LINEAR_API_URL, NOTION_TOKEN, NOTION_BASE_URL } = process.env;

const linear = new LinearClient({
  accessToken: LINEAR_ACCESS_TOKEN,
  ...(LINEAR_API_URL ? { apiUrl: LINEAR_API_URL } : {}),
});

const notion = new Client({
  auth: NOTION_TOKEN,
  ...(NOTION_BASE_URL ? { baseUrl: NOTION_BASE_URL } : {}),
});

Verify incoming webhooks with the secrets channelstack env printed: LINEAR_WEBHOOK_SECRET (for LinearWebhookClient or your own check of Linear-Signature), and NOTION_VERIFICATION_TOKEN (for verifyWebhookSignature and X-Notion-Signature).

Resend#

The resend SDK reads RESEND_BASE_URL on its own, so an agent on it needs no change: create the client with the key, and send from RESEND_FROM.

import { Resend } from "resend";

const { RESEND_API_KEY, RESEND_WEBHOOK_SECRET, RESEND_FROM } = process.env;
const resend = new Resend(RESEND_API_KEY);

Verify each webhook with resend.webhooks.verify and RESEND_WEBHOOK_SECRET: the fake signs the way Svix does, with svix-id, svix-timestamp and svix-signature. An email.received event carries the email's metadata only, so read the email with resend.emails.receiving.get(id), and answer with In-Reply-To and References set (Resend).

Google (Gmail)#

Give OAuth2Client the token endpoint and the certificates, and googleapis the root, per API: googleapis ignores google.options({ rootUrl }).

import { OAuth2Client } from "google-auth-library";
import { google } from "googleapis";

const env = process.env;
const auth = new OAuth2Client({
  clientId: env.GOOGLE_CLIENT_ID,
  clientSecret: env.GOOGLE_CLIENT_SECRET,
  endpoints: {
    ...(env.GOOGLE_TOKEN_URL ? { oauth2TokenUrl: env.GOOGLE_TOKEN_URL } : {}),
    ...(env.GOOGLE_CERTS_URL ? { oauth2FederatedSignonPemCertsUrl: env.GOOGLE_CERTS_URL } : {}),
  },
});
auth.setCredentials({ refresh_token: env.GOOGLE_REFRESH_TOKEN });
const gmail = google.gmail({ version: "v1", auth, ...(env.GOOGLE_API_URL ? { rootUrl: env.GOOGLE_API_URL } : {}) });

Watch the inbox with users.watch and GOOGLE_PUBSUB_TOPIC, check each push's token with auth.verifyIdToken({ idToken, audience: GOOGLE_PUSH_AUDIENCE }) and its email against GOOGLE_PUSH_SERVICE_ACCOUNT, and send with requestBody: { raw, threadId }: a media upload goes to Google's own host whatever rootUrl says (Google).

Discord with discord.js#

discord.js takes the REST API's base as rest.api; it finds the Gateway itself, from GET /gateway/bot, so the WebSocket goes to the fake too. Leave rest.api unset in production, where discord.js falls back to https://discord.com/api.

import { Client, GatewayIntentBits, Partials } from "discord.js";

const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages],
  partials: [Partials.Channel],
  ...(process.env.DISCORD_API_URL ? { rest: { api: process.env.DISCORD_API_URL } } : {}),
});
await client.login(process.env.DISCORD_TOKEN);

Register slash commands in DISCORD_GUILD_ID with DISCORD_APPLICATION_ID, and, for interactions over HTTP, check each request's X-Signature-Ed25519 against DISCORD_PUBLIC_KEY with verifyKey from discord-interactions. discord.js's Gateway client doesn't go through HTTPS_PROXY, so a discord.js bot uses rest.api, not proxy mode (Discord).

Chat SDK#

The Chat SDK's Slack, GitHub and Linear adapters read SLACK_API_URL, GITHUB_API_URL and LINEAR_API_URL from the environment on their own, or take an apiUrl option. With the lines from channelstack env in the app's environment, an app on the Chat SDK needs no change at all.

Tell the server where the app listens#

The server delivers each platform's events to one URL, which it reads from CHANNELSTACK_<CHANNEL>_WEBHOOK_URL when it starts:

CHANNELSTACK_SLACK_WEBHOOK_URL=http://localhost:3000/slack/events \
CHANNELSTACK_GITHUB_WEBHOOK_URL=http://localhost:3001/api/github/webhooks \
CHANNELSTACK_LINEAR_WEBHOOK_URL=http://localhost:3002/webhooks/linear \
CHANNELSTACK_NOTION_WEBHOOK_URL=http://localhost:3003/webhooks/notion \
CHANNELSTACK_RESEND_WEBHOOK_URL=http://localhost:3004/webhooks/resend \
CHANNELSTACK_GOOGLE_WEBHOOK_URL=http://localhost:3005/webhooks/google \
npx channelstack
VariableWhat arrives there
CHANNELSTACK_SLACK_WEBHOOK_URLEvents API requests, interactivity (block_actions, view_submission, view_closed), shortcuts and slash commands. Bolt handles all of them at /slack/events
CHANNELSTACK_GITHUB_WEBHOOK_URLApp webhooks, signed with X-Hub-Signature-256
CHANNELSTACK_LINEAR_WEBHOOK_URLWebhooks and AgentSessionEvents, signed with Linear-Signature
CHANNELSTACK_NOTION_WEBHOOK_URLIntegration webhooks, signed with X-Notion-Signature
CHANNELSTACK_RESEND_WEBHOOK_URLemail.received for mail to the agent, and email.sent, email.delivered and what else became of the mail it sent, signed the Svix way (svix-signature)
CHANNELSTACK_GOOGLE_WEBHOOK_URLPub/Sub pushes of Gmail's notifications, once the agent has called users.watch, each with an OIDC token for this URL in Authorization

Set only the ones your app uses. Any URL the server can reach works; a loopback URL is the simplest. The server reads these variables once, at start, so restart it to change one.

Without a URL (and, for Slack, without a Socket Mode connection), a fake sends nothing. People can still act, but nothing reaches the app, and msg.delivery is undefined. If a test sees no reply at all, check this first.

Slack in Socket Mode#

An app in Socket Mode connects out to Slack over a WebSocket and needs no URL at all. Leave CHANNELSTACK_SLACK_WEBHOOK_URL unset and give the app the app token:

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  appToken: process.env.SLACK_APP_TOKEN,
  socketMode: true,
  ...(process.env.SLACK_API_URL ? { clientOptions: { slackApiUrl: process.env.SLACK_API_URL } } : {}),
});

await app.start();

The app calls apps.connections.open with its xapp-… token, as it does against Slack, and the fake answers with a WebSocket URL of its own (wss://slack.localhost/link?…). Events, interactivity and slash commands then arrive over that connection, wrapped in Socket Mode envelopes that the app acknowledges.

A few things differ from HTTP delivery, as they do on Slack:

  • There is no signature to check: the connection is the app's own. The standard slack.bad-signature check passes without sending anything.
  • A retry carries retry_attempt and retry_reason in the envelope instead of headers.
  • slack.socketConnections tells a test how many connections the app had open when the test's slack fixture was made (a snapshot, not refreshed), and slack.fault({ type: "drop_socket" }) drops them to test reconnecting. See delivery and failures.

TLS trust per runtime#

With portless, the fakes are served over HTTPS with a certificate from portless's local CA. portless trust adds that CA to the system trust store, but not every runtime reads the system store. If your app fails with a certificate error, set what its runtime needs:

RuntimeWhat to set in the app's environment
Node 24 and laterNODE_USE_SYSTEM_CA=1, so Node reads the system store
Python with certifi (requests, httpx, slack_sdk)SSL_CERT_FILE and REQUESTS_CA_BUNDLE, pointing at a bundle of certifi's roots plus portless's CA
GoNothing on macOS (Go reads the keychain); SSL_CERT_FILE on Linux
Anything elseStart the server with --no-portless and use plain HTTP on loopback

In base-URL mode, channelstack env doesn't print these: set them yourself. portless doctor checks portless's own setup. Proxy mode is different: there, channelstack env --proxy prints the CA settings for channelstack's own proxy CA.

Secrets#

The fake tokens and signing secrets are random. The server generates them once per install and keeps them in ~/.channelstack/secrets.json (mode 0600), or under CHANNELSTACK_HOME if you set it. They stay the same across restarts, so the .env.local you wrote once keeps working.

To replace them all:

npx channelstack secrets rotate

Then restart the server and run channelstack env again, because the app's copy is now stale.

None of these values works anywhere but on your channelstack server. Still, keep .env.local out of version control, like any .env file. The control API's own bearer token is a separate secret in ~/.channelstack/server.json; channelstack env never prints it, so it never ends up in the app's environment.

Check the connection#

With the server and the app running, post as a person and read what came back:

npx channelstack slack say --as ana --in "#support" "@my-agent hi"
npx channelstack show
npx channelstack deliveries slack

show prints the latest conversation as a person would read it, and deliveries lists what the server sent the app and how the app answered each attempt. If the app answered, you're connected: go on to writing tests. If not, the dev loop and troubleshooting cover what to look at.

Suggest changes to this page