---
title: "Connector Triggers"
description: "Connector Triggers can start an agent session and send it user messages, each event once while Dex Server keeps its request ID. This page covers the TypeScript packages, the request IDs of both targets, their limits, durable delivery from Slack, session graph bindings, and tests without a provider."
canonical_url: "https://docs.superdurable.io/reference/agents/connector-triggers/"
source: "docs/reference/agents/connector-triggers.mdx"
locale: "en"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Connector Triggers

Connector Triggers can start an agent session and send it user messages.
[Start and feed sessions from Connector Triggers](https://docs.superdurable.io/agent-frameworks/sessions.md#connector-triggers)
explains the pattern. This page covers the TypeScript packages, the request
IDs of both targets, their limits, durable delivery from Slack, session graph
bindings, and tests without a provider. Since 0.6.7, the first release that accepts
`@superdurable/connectors-sdk` 0.10. The
[Slack thread agent example](https://github.com/superdurable/dex/tree/main/examples/typescript/slack-thread-agent)
uses everything on this page.

<a id="packages"></a>

## Packages

| Package                        | Version         | What the pattern needs from it                                                                                                           |
| ------------------------------ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `@superdurable/connectors-sdk` | 0.10.1 or later | `newDexRPCTriggerTarget` sends one request ID for every delivery of an event, and takes `rpcName`.                                       |
| `@superdurable/dex`            | 1.45.4 or later | `requestId` of `RPCInvokeOptions`. See [RPC request IDs](https://docs.superdurable.io/reference/server/runtime-data.md#rpc-request-ids). |
| `@superdurable/dex-agents`     | 0.6.7 or later  | Accepts `@superdurable/connectors-sdk` 0.10 as a peer. The example is tested with 0.6.8.                                                 |

`@superdurable/dex-agents` 0.6.8 has an exact peer dependency on
`@superdurable/dex` 1.45.3. `@superdurable/connector-slack` 0.6.0 depends on
`@superdurable/connectors-sdk` 0.10.0 exactly. Add npm `overrides` so that one
copy of each package resolves to the version you declare:

```json
{
  "dependencies": {
    "@superdurable/connector-slack": "0.6.0",
    "@superdurable/connectors-sdk": "0.10.1",
    "@superdurable/dex": "1.45.4",
    "@superdurable/dex-agents": "0.6.8"
  },
  "overrides": {
    "@superdurable/connectors-sdk": "$@superdurable/connectors-sdk",
    "@superdurable/dex": "$@superdurable/dex"
  }
}
```

Check the result with `npm ls @superdurable/dex @superdurable/connectors-sdk`.
Each package should appear once, with the others marked `deduped`.

<a id="start-target"></a>

## Start target

`newDexFlowTriggerTarget` starts the session Flow. The session ID is the Flow
ID, and the event ID is the start's request ID. The target disallows Flow ID
reuse, so a repeated event starts nothing, even after the session stopped.
Map the event to `AgentSessionStartInput`, with the message text as
`initialMessage`.

The target starts the session with `Client.startFlow`, not with
`startAgentSession`. So the session does not get
`agentSessionActiveStepSearchMode`, and a search such as
`ActiveStepTypes = "AwaitToolApproval"` does not find it. To make it
searchable, pass that mode as `activeStepSearchMode` to
`Client.updateFlowConfig` for the session. See
[Find sessions that need a person](https://docs.superdurable.io/reference/agents/approvals.md#find-sessions).

<a id="reply-target"></a>

## Reply target

`newDexRPCTriggerTarget` calls the session's `sendUserMessage` handler, the
RPC `send_user_message`. Map the event to `AgentUserMessage`, with the message
text as `text`.

| Behavior                     | Detail                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Request ID                   | `triggerRPCRequestId(rpcName, event.id)`: `trigger-rpc-` and the first 16 bytes, as unpadded base64url, of the SHA-256 digest of the RPC name, one 0x00 byte, and the event ID.                                                                                                                                                                                                                                             |
| RPC name                     | Pass `rpcName: "send_user_message"`. Without it, the target uses the JavaScript method name, `sendUserMessage`, which changes when a build renames or minifies methods. Changing `rpcName` changes the IDs of events that are still being redelivered.                                                                                                                                                                      |
| Repeats                      | `send_user_message` is transactional. Dex answers a repeat from the recorded reply and does not run the handler again. Concurrent deliveries of one event share one handler execution.                                                                                                                                                                                                                                      |
| How long a repeat is caught  | A session run keeps its newest request IDs only, as many as `limits.maxRequestIdsPerRun` allows (1,000 by default). Every request that carries a request ID counts toward it. A redelivery after its ID was dropped queues the message again. See [Limits](https://docs.superdurable.io/reference/server/configuration.md#limits).                                                                                          |
| Different input under one ID | Dex compares only the request ID. A repeat with different input gets the first delivery's reply, and its own message is never queued. Concurrent deliveries share one handler execution whatever their inputs. Keep the input mapping deterministic, so a redelivery carries the same message. Dex Server 0.1.36 and earlier reject a different input under one ID, and the target throws `TriggerRPCRequestConflictError`. |
| No running session           | A reply with a new request ID whose session never started or has closed throws `UndeliverableTriggerError`. The Trigger logs and drops it. Deliver a thread's first message before its replies.                                                                                                                                                                                                                             |
| Blank text                   | `send_user_message` refuses blank text. Skip it in the target's filter.                                                                                                                                                                                                                                                                                                                                                     |

<a id="durable-delivery"></a>

## Durable delivery from Slack

`@superdurable/connector-slack` acknowledges each Socket Mode envelope before
it delivers the event. A target needs a durable inbox, so that an event
survives a crash between the acknowledgement and the Dex commit.

| Runner                                           | Inbox                                                                                                                                               | After a crash between acknowledgement and commit                                                                                        |
| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `newProjectMessageTriggerRunner`                 | Wraps each binding's target in `newDurableTriggerTarget` with the binding's project inbox. The runner records each event before it acknowledges it. | The next `run` replays the recorded events in order. A replayed event that already reached the session is answered from its request ID. |
| `newMessageTriggerRunner` with the plain targets | None.                                                                                                                                               | The event is lost. Slack does not send it again.                                                                                        |

Use `newProjectMessageTriggerRunner`. Its project configuration must declare
each binding with its channel and members. A binding the configuration does
not declare makes the runner throw.

<a id="slack"></a>

## Slack Triggers

`@superdurable/connector-slack` 0.6.0 has two message Triggers. Both deliver
a `MessageEvent` with `teamId`, `channelId`, `timestamp`, `threadTimestamp`,
`userId`, and `text`. The event ID is Slack's `event_id`.

| Trigger                | Matches                             | `threadTimestamp`                            |
| ---------------------- | ----------------------------------- | -------------------------------------------- |
| `channelThreadCreated` | A top-level message in the channel. | The message's own timestamp.                 |
| `threadReplyCreated`   | A reply in a thread of the channel. | The timestamp of the thread's first message. |

- Build the session ID from `teamId`, `channelId`, and `threadTimestamp`.
  A first message and its replies then resolve to the same session.
- Both Triggers ignore messages that a bot posts and messages with a subtype.
  A reply that the agent posts as a bot does not come back as a user message.
- The `threadReplyCreated` matcher requires at least one poster user ID.
- Run every Trigger of one Slack connection on one runner. Slack sends each
  event to only one Socket Mode connection.

<a id="session-graph-bindings"></a>

## Declare the bindings in the session graph

Since 0.6.12. A hosting platform configures a Trigger binding only when a
Flow Definition Graph declares it. The session Flow has no code that declares
bindings, so add them when you render the session graph. Declare one binding
for each Trigger that delivers into the session:

```bash
npx --no-install dex-agents-session-graph --flow-type SupportAgent \
  --permission support-agent.operate \
  --trigger-binding slack-workspace=@superdurable/connector-slack@0.6.0:channelThreadCreated:support-threads \
  --trigger-binding slack-workspace=@superdurable/connector-slack@0.6.0:threadReplyCreated:support-thread-replies \
  --out definitions/support-agent.json
```

- Use the connection and binding names that your Trigger runner uses.
- Run the command where the Connector package is installed. It reads the
  package's `dex-connector.json` and fails when the package or Trigger is
  missing.
- `@superdurable/connector-slack` 0.6.0 declares no UI units for its
  Triggers. To offer a channel picker and a member picker, pass the units in a
  `--trigger-bindings` file.
- The binding does not deliver events. The reply target still calls
  `send_user_message`, and the start target still starts the session Flow.

[Declare Connector Trigger bindings](https://docs.superdurable.io/reference/agents/dex-web.md#trigger-bindings)
describes the flag, the file, and the code functions.

<a id="testing"></a>

## Test without a provider

Call a target's `handleTrigger` with `newTriggerContext()` and a
`TriggerEvent`, the way a runner delivers an event. Call it again with the
same event to test a redelivery.

To test a restart, wrap the target with `newDurableTriggerTarget` over a
`TriggerInbox` on an `InMemoryObjectStore`, from
`@superdurable/connectors-sdk/projectconfig`. Call `prepareTrigger` to record
an event, then call `replayTriggerDeliveries` on a new wrapper over the same
store.

The example's
[test](https://github.com/superdurable/dex/tree/main/examples/typescript/slack-thread-agent/test)
does both against a real Dex server, with a scripted model, so it needs no
Slack workspace and no model key.
