> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paddockai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Connectors

> Link your agents to Slack, GitHub, or any service: a webhook URL whose function routes events into sessions, and an outbound side that delivers what agents send.

A connector is your project's link to one other service, such as a Slack workspace or a GitHub repository. It has a name, unique in the project, and one side or both:

* The **inbound** side is a webhook URL, `https://webhook.paddock.build/con_...`. A function runs on every request to it: it verifies the request, answers a handshake, or accepts it with a list of **routes**, each a message for one agent's session. paddock records the request and delivers the routes; you run no server in between.
* The **outbound** side lets agents speak. An agent calls the `send` tool with a key such as `slack-acme:C0123ABCD`, and the connector's deliver function posts the message, with credentials the sandbox never sees. See [Sending messages](https://docs.paddockai.dev/guides/outbox.md).

```mermaid theme={null}
sequenceDiagram
  participant Sender as Sender (any service)
  participant Hook as webhook.paddock.build
  participant Fn as Inbound function
  participant Session as Agent's session
  Sender->>Hook: POST /con_... { event }
  Hook->>Fn: handle(req, ctx)
  Fn-->>Hook: { accept: true, deliver: [routes] }
  Hook-->>Sender: 202 { deliveryId }
  Hook->>Session: find or create the session by its key, send the message
```

## Create a connector

```go Go theme={null}
connector, err := client.Connectors.Create(ctx, paddock.ConnectorCreate{
	Name:    "github-acme-web",
	Inbound: &paddock.InboundCreate{},
	Secret:  os.Getenv("GITHUB_WEBHOOK_SECRET"),
})
if err != nil {
	return err
}
_, err = connector.Functions.Set(ctx, paddock.SideInbound, paddock.FunctionSet{
	Runtime: paddock.RuntimeNodeJS,
	Preset:  "github",
	Params:  map[string]string{"agent": agent.ID, "repository": "acme/web", "mention": "@reviewer"},
})
if err != nil {
	return err
}
fmt.Println(connector.Inbound.URL) // https://webhook.paddock.build/con_...
```

```python Python theme={null}
import os

connector = client.connectors.create(
    {"name": "github-acme-web", "inbound": {}, "secret": os.environ["GITHUB_WEBHOOK_SECRET"]}
)
connector.functions.set(
    "inbound",
    runtime="nodejs24.x",
    preset="github",
    params={"agent": agent.id, "repository": "acme/web", "mention": "@reviewer"},
)
assert connector.inbound is not None
print(connector.inbound.url)  # https://webhook.paddock.build/con_...
```

```ts TypeScript theme={null}
const connector = await paddock.connectors.create({
  name: "github-acme-web",
  inbound: {},
  secret: process.env.GITHUB_WEBHOOK_SECRET,
});
await connector.functions.set("inbound", {
  runtime: "nodejs24.x",
  preset: "github",
  params: { agent: agent.id, repository: "acme/web", mention: "@reviewer" },
});
console.log(connector.inbound?.url); // https://webhook.paddock.build/con_...
```

From a terminal, the [CLI](https://docs.paddockai.dev/platform/cli.md#connectors) does the same, the secret read from standard input so that it never lands in your shell history:

```bash theme={null}
paddock connectors create github-acme-web --preset github \
  --param agent=agt_01h455vb4pex5vsknk084sn02q --param repository=acme/web --param mention=@reviewer
printf %s "$GITHUB_WEBHOOK_SECRET" | paddock connectors secrets set github-acme-web default
```

Give the sender the URL and the same secret. The Python SDK takes requests as dictionaries spelled as the API spells them, or as the models in `paddockai.types`.

| Field | Meaning |
| - | - |
| `name` | Lowercase letters, digits, and `-`, 1 to 64 characters, not starting or ending with `-`; unique in the project and fixed at creation. `connectors.get` takes the name or the ID |
| `inbound` | Present: the connector has a webhook URL |
| `outbound` | Present: agents may send through it; `rateLimit.perMinute`, 1 to 600, default 60 |
| `secret` | The `default` secret, 16 to 256 printable characters; generated when omitted |

The URL is unguessable, and only the inbound function decides what a request must prove. A side without a function is inert: the inbound side answers every request `503`, and the outbound side refuses every send.

## Inbound functions

The inbound function is one file of Node.js or Python, or a [preset](#presets). It sees each request as the sender sent it, with the connector's secrets, and answers one of three ways:

| Answer | Meaning | The sender gets |
| - | - | - |
| `{ accept: true, dedupeKey?, deliver }` | Accepted, with up to 20 routes; none for an event that matters to no one | `202 { deliveryId }`, or `200` for a duplicate |
| `{ respond: { status, headers?, body? } }` | A handshake, such as Slack's `url_verification` | The answer as given |
| `{ accept: false, reason? }` | Rejected, such as a wrong signature | `401` |

A thrown error, an answer outside these shapes, or a timeout is `503`, so the sender retries. [Connector functions](https://docs.paddockai.dev/guides/connector-functions.md) has the whole contract, the runtimes, and the limits.

```js theme={null}
// runtime nodejs24.x
import { createHmac, timingSafeEqual } from "node:crypto";

export default async function handle(req, ctx) {
  const got = Buffer.from(req.headers["x-signature"] ?? "");
  const want = Buffer.from(createHmac("sha256", ctx.secret).update(req.body).digest("hex"));
  if (got.length !== want.length || !timingSafeEqual(got, want)) {
    return { accept: false, reason: "x-signature does not match" };
  }
  const event = JSON.parse(req.body.toString("utf8"));
  if (event.type !== "ticket.created") return { accept: true, deliver: [] };
  return {
    accept: true,
    dedupeKey: event.id,
    deliver: [
      {
        agent: ctx.params.agent,
        sessionKey: `customer-${event.data.customer}`,
        message: `Ticket ${event.data.id} was opened: ${event.data.title}`,
      },
    ],
  };
}
```

### Routes

Each route is one message for one agent:

| Field | Meaning |
| - | - |
| `agent` | The agent's ID; an agent that is not an active agent of the project fails only this route |
| `sessionKey` | 1 to 500 bytes: the agent's session with this key, found or created; `null` for a new session |
| `message` | The message, 1 byte to 100 KB |
| `replyKey` | Optional: where the agent's answers in that session go, such as `slack-acme:C0123ABCD/1763600000.123456` (see [reply routing](https://docs.paddockai.dev/guides/outbox.md#reply-routing)) |
| `replyTo`, `matchOnly` | Optional: find the session whose sent message this event answers; with `matchOnly`, deliver only to it |
| `settings` | `cwd`, `systemPrompt`, and `metadata` for a session the route creates |

A route with a session key reaches the agent's active session whose `connectorKey` metadata equals the key, or creates one with that metadata and the route's settings. So every event about one pull request lands in one conversation, with the agent's earlier work in context. Two routes with one key for one agent reach the same session, each with its own message. Find a key's session with a metadata filter:

```go Go theme={null}
for s, err := range client.Sessions.List(ctx, paddock.ProjectSessionList{
	Metadata: map[string]string{"connectorKey": "acme/web#42"},
}) {
	if err != nil {
		return err
	}
	fmt.Println(s.ID)
}
```

```python Python theme={null}
for s in client.sessions.list(metadata={"connectorKey": "acme/web#42"}):
    print(s.id)
```

```ts TypeScript theme={null}
for await (const s of paddock.sessions.list({ metadata: { connectorKey: "acme/web#42" } })) {
  console.log(s.id);
}
```

## Presets

A preset is stock code for one service, in both runtimes. Setting a side's function from a preset copies its code and default params; you set the secrets it reads and fill its params. While the code is still the preset's, `functionSummary.presetCode` is `true` and the console edits the params as a form; edit the code and it is yours.

| Preset | Inbound | Outbound | Secrets |
| - | - | - | - |
| `route-all` | Routes every event to one agent by the routing params below | — | `default`, only with `signatureHeader` set |
| `github` | Pull requests and mentions, below | — | `default`, the webhook secret |
| `slack` | Mentions, thread replies, and slash commands, below | Messages to channels and threads | `default`, the signing secret; `bot_token`, the bot's `xoxb-` token |
| `stripe`, `hubspot-v2`, `hubspot-v3`, `shopify`, `linear`, `standard-webhooks` | Verifies the service's signature, then routes by the routing params | — | `default` |
| `webhook` | — | Signed POSTs (Standard Webhooks) to the param `url` | `default`, the signing key |
| `email-ses` | — | Email through Amazon SES; params `region`, `from`, `subject` | `aws_access_key_id`, `aws_secret_access_key` |

`connectors.functionPresets()` returns every preset with its code and the params it declares. Every inbound preset that verifies a signature also accepts a secret named `previous`, so you can rotate without dropping requests: set the old value as `previous`, rotate `default`, and delete `previous` once the sender has the new one.

**Routing params** of `route-all` and the signature presets:

| Param | Meaning |
| - | - |
| `agent` | Required: the agent's ID |
| `session` | `new` (default): a new session per event; `one`: one session for every event; `field`: the session keyed by the value at `sessionField` |
| `sessionField` | A dotted path into the JSON body, such as `data.object.customer` |
| `message` | `json` (default): the event's JSON in a message; `field`: the text at `messageField` |
| `dedupeField` | A dotted path whose value is the dedupe key; default the preset's own, none for `route-all` |
| `signatureHeader`, `signaturePrefix` | `route-all` only: require the hex HMAC-SHA256 of the body with `default`, after the prefix, in that header |

**`github`**: params `agent`, `repository` (`owner/name`; empty, any), `reviewEvents` (default `opened,synchronize,reopened`), `drafts` (default `false`), and `mention`. A pull request event with one of those actions goes to the session `{repository}#{number}`, asking for a review; a new comment on a pull request containing the mention, not written by a bot, goes to the same session, asking for an answer. Any other event, `ping` among them, is accepted with no route. Set the webhook's content type to `application/json` and its events to pull requests and issue comments.

**`slack`**: params `agent`, `mentions`, and `threadReplies` (both default `true`). A mention goes to the session of its thread, with the thread as its reply key, so the agent's `send` without a key answers in the thread; a thread reply not mentioning the bot reaches only a session that wrote in that thread; a slash command starts a new session that answers in its channel.

## Test a function

`connector.functions.test` runs the saved function, or a draft, on a sample request exactly as a real one runs, and shows the answer a sender would get, the dedupe key, the routes, and what the code logged. It records and delivers nothing.

```go Go theme={null}
res, err := connector.Functions.Test(ctx, paddock.SideInbound, paddock.FunctionTestRequest{
	Event: &paddock.FunctionTestEvent{
		Headers: map[string]string{"X-GitHub-Event": "ping", "X-Hub-Signature-256": "sha256=..."},
		Body:    `{"zen":"Keep it logically awesome."}`,
	},
})
if err != nil {
	return err
}
fmt.Println(res.Result, *res.Answer, len(res.Routes), res.Logs)
```

```python Python theme={null}
res = connector.functions.test(
    "inbound",
    event={
        "headers": {"X-GitHub-Event": "ping", "X-Hub-Signature-256": "sha256=..."},
        "body": '{"zen":"Keep it logically awesome."}',
    },
)
print(res.result, res.answer, res.routes, res.logs)
```

```ts TypeScript theme={null}
const res = await connector.functions.test("inbound", {
  event: {
    headers: { "X-GitHub-Event": "ping", "X-Hub-Signature-256": "sha256=..." },
    body: '{"zen":"Keep it logically awesome."}',
  },
});
console.log(res.result, res.answer, res.routes, res.logs);
```

With the CLI, put the sample request in a JSON file and run `paddock connectors fn test github-acme-web --side inbound --request ping.json`, adding `--file handler.mjs` to try a draft.

Pass `deliveryId` instead of `event` to run a recorded request again, `replay: true` to run it as a replay would, and `draft: { runtime, code, params }` to try code before you set it.

## Deliveries

Every request to the URL is a **delivery**, recorded before the sender is answered, with one outcome per route.

```go Go theme={null}
for d, err := range connector.Deliveries.List(ctx, paddock.DeliveryList{Status: "pending"}) {
	if err != nil {
		return err
	}
	for _, o := range d.Outcomes {
		fmt.Println(d.ID, o.Position, o.Status, o.WaitingFor)
	}
}
```

```python Python theme={null}
for d in connector.deliveries.list(status="pending"):
    for o in d.outcomes:
        print(d.id, o.position, o.status, o.waiting_for)
```

```ts TypeScript theme={null}
for await (const d of connector.deliveries.list({ status: "pending" })) {
  for (const o of d.outcomes) console.log(d.id, o.position, o.status, o.waitingFor);
}
```

| Delivery status | Meaning |
| - | - |
| `pending` | Some route is still being delivered |
| `done` | Every route's outcome is final; an accepted request with no route is `done` at once |
| `rejected` | Never accepted: `invalid_body` (over 1 MiB), `no_function`, `function_rejected`, `function_error`, or `function_timeout` |
| `handshake` | The function answered with `respond` |

| Outcome status | Meaning |
| - | - |
| `pending` | Waiting for its turn, or retried after a passing failure; `waitingFor` names the earlier delivery for its key |
| `delivered` | The message is in the session, with `sessionId`, `messageId`, and `seq` |
| `unmatched` | A `matchOnly` route whose reply match found no session |
| `failed` | `agent_not_found`, `invalid_settings`, or `unavailable` after the last retry |

What a delivery promises:

* **Exactly once.** Each delivered route appends one message, however often an attempt is retried.
* **Deduplication.** A request with the dedupe key the function returned, or without one the same body, as a delivery the connector already has is answered `200` with that delivery's ID and recorded nowhere. A rejected request is never deduplicated against.
* **Retries.** A passing failure is retried up to 5 attempts, 30 seconds, 2, 8, and 32 minutes apart; each attempt runs only the routes still pending.
* **Order.** Routes for one agent and session key are delivered in the order their requests arrived; a route to a new session never waits.

`connector.deliveries.get` adds the request as received: its method, URL, headers, and body.

### Replay

`connector.deliveries.replay(id)` runs the **current** inbound function again on a recorded request, for real, as a new delivery with `replayOf` set. Deduplication never drops it, and its routes are what the code returns now, so a fixed function can redo what an earlier version got wrong. The function sees `ctx.replay = { receivedAt }`, the first delivery's receipt time, and every preset measures a signature's timestamp against it. A handshake cannot be replayed.

## Update and delete

`connectors.update(id, { inbound, outbound })` sets which sides exist and the outbound rate limit: a side kept keeps its function and URL, and a side left out is removed with its function. `connectors.delete(id)` deletes both functions, then the connector: its URL answers `404` at once, its deliveries and outbox messages are removed, and the sessions it created stay.

| Secret operation | Meaning |
| - | - |
| `connector.secret.get({ name? })` | Reveals a secret; `name` defaults to `default` |
| `connector.secret.rotate({ name?, secret? })` | Sets a secret at once, given or generated, creating it when missing |
| `connector.secret.delete({ name })` | Removes a secret other than `default` |

A connector has at most 5 secrets, shared by both sides. Only these operations return a value; nothing else does, logs and errors included.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.