--- name: add-resend description: Add Resend (email) channel integration via Chat SDK. --- # Add Resend Email Channel Connect NanoClaw to email via Resend for async email conversations. NanoClaw doesn't ship channels in trunk — this skill copies the Resend adapter in from the `channels` branch. The mechanical steps under **Apply** carry `nc:` directive fences: an agent reads the prose and applies them, and a parser can apply them deterministically from the same document. Every directive is idempotent, so the whole skill is safe to re-run; anything a parser can't apply falls back to the prose beside it. ## Apply ### 1. Copy the adapter Fetch the `channels` branch and copy the Resend adapter into `src/channels/` (overwrite — the branch is canonical). An install from before `resend.test.ts` existed has an older `resend.ts` without the `resendRegistration` export the test imports, and the copy below only fills missing files. So this step moves an older `resend.ts` aside first and the copy brings the current one: ```nc:run effect:refresh [ ! -f src/channels/resend.ts ] || grep -qF 'export const resendRegistration' src/channels/resend.ts || mv -f src/channels/resend.ts src/channels/resend.ts.old ``` ```nc:copy from-branch:channels src/channels/resend.ts src/channels/resend.test.ts src/channels/resend-registration.test.ts ``` If the copy failed (no network, say), put the older `resend.ts` back: the channel barrel still imports it, and without the file the service stops starting after the next clean build. Then drop the set-aside copy: ```nc:run effect:refresh [ -f src/channels/resend.ts ] || [ ! -f src/channels/resend.ts.old ] || mv -f src/channels/resend.ts.old src/channels/resend.ts rm -f src/channels/resend.ts.old ``` ### 2. Register the adapter Append the self-registration import to the channel barrel (skipped if the line is already present). This one line is the skill's only reach-in into core: ```nc:append to:src/channels/index.ts import './resend.js'; ``` ### 3. Install the adapter package Pinned to an exact version — the supply-chain policy rejects ranges and `latest`: ```nc:dep @resend/chat-sdk-adapter@0.3.0 ``` ### 4. Build and validate Build guards the typed `createChatSdkBridge(...)` core call and proves the dependency is installed (the adapter imports `@resend/chat-sdk-adapter`; if it isn't installed the barrel throws). End-to-end email delivery against a real domain is verified manually once the service runs. ```nc:run effect:build pnpm run build ``` ```nc:run effect:test pnpm exec vitest run src/channels/resend-registration.test.ts pnpm exec vitest run src/channels/resend.test.ts ``` Each test file gets its own run: vitest skips a file name that matches nothing when another one matches, so a missing test file would pass unseen. `resend-registration.test.ts` imports the real channel barrel and asserts the registry contains `resend`. It goes red if the import line is deleted or drifts, if the barrel fails to evaluate, or if `@resend/chat-sdk-adapter` isn't installed (the import throws) — so it also covers the dependency from step 3. `resend.test.ts` sends through the real adapter with only Resend's HTTP API stubbed: the hello to `resend:
` goes out, and a reply lands in the thread the person last wrote in. ## Credentials Resend account and domain setup is human and interactive — these steps are prose, not directives (no parser can verify a sending domain or click through the Resend UI). A recipe rebuild produces a compiling, registered adapter that cannot receive a message until they're done. 1. Go to [resend.com](https://resend.com) and create an account. 2. Add and verify your sending domain. 3. Go to **API Keys** and create a new key. 4. Set up a webhook: - Go to **Webhooks** > **Add webhook**. - URL: `https://your-domain/webhook/resend`. - Events: select **email.received**. - Copy the signing secret. ### Store the credentials Capture the secrets, then write them. `prompt` only *asks* and binds the answer to a name; a separate directive consumes it — so the same prompts could feed `ncl` or the OneCLI vault instead of `.env` by swapping only the consumer. Here they go to `.env` (set-if-absent — a value you've already filled in is never overwritten): ```nc:prompt api_key secret Paste the Resend API key — API Keys, starts with `re_`. ``` ```nc:prompt webhook_secret secret Paste the webhook signing secret — Webhooks, the value you copied above. NanoClaw's webhook server listens on 127.0.0.1 only; if the proxy or tunnel serving that URL runs on another machine or in Docker on Linux, add `WEBHOOK_HOST=0.0.0.0` to `.env` (it takes effect at the next restart). ``` ```nc:prompt from_address The bot's sending email address on your verified domain (e.g. `bot@yourdomain.com`). ``` ```nc:prompt from_name The display name to send as (e.g. `NanoClaw`). ``` ```nc:env-set RESEND_API_KEY={{api_key}} RESEND_FROM_ADDRESS={{from_address}} RESEND_FROM_NAME={{from_name}} RESEND_WEBHOOK_SECRET={{webhook_secret}} ``` ## Connect yourself Because email is direct-addressable, the bot can write to you first — so wire your own address as the owner and have it email you a hello. Tell it your address and which agent should answer your email (`ncl groups list` shows their folders): ```nc:prompt owner_email Your email address — I'll wire you as owner and email you a hello. ``` ```nc:prompt agent_folder Which agent should answer your email? Enter its folder (run `ncl groups list`). ``` Register yourself as the owner, wire your address so the agent answers your email, and send the hello: ```nc:run effect:wire ncl users create --id resend:{{owner_email}} --kind resend --display-name Owner ncl roles grant --user resend:{{owner_email}} --role owner ncl messaging-groups create --channel-type resend --platform-id resend:{{owner_email}} --is-group 0 ncl wirings create --channel-type resend --platform-id resend:{{owner_email}} --agent-group {{agent_folder}} --engage-mode pattern --engage-pattern . ncl messaging-groups send --channel-type resend --platform-id resend:{{owner_email}} --sender-id resend:{{owner_email}} --sender Owner --text "Hi — I'm your NanoClaw assistant, reachable by email now. Reply to this thread anytime." ``` The hello arrives as a fresh email thread; reply to keep the conversation going. Your own address is the conversation key (`resend: