npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@resend/chat-sdk-adapter

v0.5.0

Published

Vercel Chat SDK adapter for Resend email

Downloads

253,367

Readme

@resend/chat-sdk-adapter

Vercel Chat SDK adapter for Resend email. Bidirectional: receive emails via Resend webhooks, send emails via Resend API.

The adapter works with a Resend Inbox or with Receiving. Set inboxId or inboxEmailAddress to use an inbox. See Inboxes.

Install

pnpm add @resend/chat-sdk-adapter chat @chat-adapter/shared

Quick Start

import { createResendAdapter } from "@resend/chat-sdk-adapter";
import { MemoryStateAdapter } from "@chat-adapter/state-memory";
import { Chat } from "chat";

const resend = createResendAdapter({
  fromAddress: "[email protected]",
  fromName: "My Bot",         // optional
  // apiKey: "re_...",        // or set RESEND_API_KEY env var
  // webhookSecret: "whsec_..." // or set RESEND_WEBHOOK_SECRET env var
});

const chat = new Chat({
  userName: "email-bot",
  adapters: { resend },
  state: new MemoryStateAdapter(),
});

// New inbound email (new thread)
chat.onNewMention(async (thread, message) => {
  await thread.subscribe();
  await thread.post(`Got your email: ${message.text}`);
});

// Follow-up email in a subscribed thread
chat.onSubscribedMessage(async (thread, message) => {
  await thread.post(`Reply: ${message.text}`);
});

Forward Resend webhooks to your server's /webhook endpoint. See examples/basic for a full working server.

Configuration

Environment Variables

| Variable | Description | |---|---| | RESEND_API_KEY | Resend API key (overridden by config.apiKey) | | RESEND_WEBHOOK_SECRET | Webhook signing secret (overridden by config.webhookSecret) | | FROM_ADDRESS | Used by example apps only |

ResendAdapterConfig

type ResendAdapterConfig = {
  /** Sender email address (required). */
  fromAddress: string;
  /** Display name for the From header. */
  fromName?: string;
  /** Resend API key. Falls back to RESEND_API_KEY env var. */
  apiKey?: string;
  /** Webhook signing secret. Falls back to RESEND_WEBHOOK_SECRET env var. */
  webhookSecret?: string;
} & (
  /** Resend inbox ID. Handles `inbox.email.received` and replies in the inbox thread. */
  | { inboxId?: string; inboxEmailAddress?: never }
  /** Resend inbox email address. Works as `inboxId` does. */
  | { inboxId?: never; inboxEmailAddress?: string }
);

Set inboxId or inboxEmailAddress, not both. Setting both is a type error.

Features

Inboxes

Set inboxId or inboxEmailAddress to build the bot on a Resend Inbox. The inbox groups email into threads, and the bot replies inside the thread. Resend sets the recipients and the threading headers.

const resend = createResendAdapter({
  fromAddress: "[email protected]", // the inbox address
  inboxId: "b3e2b2b6-3f0e-4c8e-9ad3-2f43a1e2c7f1",
});

You can also select the inbox by its email address:

const resend = createResendAdapter({
  fromAddress: "[email protected]",
  inboxEmailAddress: "[email protected]",
});

Set inboxId or inboxEmailAddress, not both. The adapter throws an error when you set both. The inbox.email.received payload identifies the inbox by its ID. With inboxEmailAddress, the adapter gets the inbox ID with resend.inboxes.get() on the first inbox.email.received event and keeps it. If the inbox does not exist, handleWebhook() throws an error. Thread IDs use the inbox ID in both cases.

Subscribe your webhook to inbox.email.received. With an inbox set, the adapter:

  • Handles inbox.email.received events for that inbox only. It ignores other inboxes and email.received events.
  • Fetches the email with resend.inboxes.threads.emails.get(). The webhook payload has no body.
  • Maps each inbox thread to one Chat SDK thread, with the ID resend:{inboxId}:{threadId}. The channel is the inbox.
  • Posts with resend.inboxes.threads.emails.reply(), to the last received email of the thread, or to its last email when it has no received email. The reply goes to the Reply-To addresses of a received email, or to its sender when it has none. For a sent email, it goes to that email's to recipients. The reply is sent from the inbox address, so fromName does not apply to it.

A sender can set Reply-To to any address. Check message.raw.replyTo before the bot replies with anything sensitive.

openDM() still sends with resend.emails.send() from fromAddress, as without an inbox.

Email Threading

Without an inbox, threads are resolved using standard Message-ID, In-Reply-To, and References email headers. Reply chains are automatically grouped into Chat SDK threads.

Send Emails Proactively

Use openDM to start a new email thread to any address:

const threadId = await resend.openDM("[email protected]");
await resend.postMessage(threadId, "Hello from the bot!");

Card Emails

Send rich HTML emails using Chat SDK Card elements, rendered via @react-email/components:

await thread.post({
  card: {
    type: "card",
    title: "Order Confirmed",
    children: [
      { type: "text", content: "Your order #1234 has been shipped." },
      { type: "divider" },
      { type: "link-button", label: "Track Order", url: "https://example.com/track/1234" },
    ],
  },
  fallbackText: "Order #1234 confirmed",
});

Attachments

Inbound email attachments are available in message.raw.attachments with filename, content_type, and url fields. For an inbox email, each attachment has id, filename and size.

Unsupported Operations

Email is inherently one-shot. The following operations throw NotImplementedError:

  • editMessage / deleteMessage
  • addReaction / removeReaction
  • startTyping

Examples

| Example | Description | |---|---| | basic | Echo bot - replies to every email | | welcome-cards | Sends a styled card email on first contact | | notifications | Proactive emails via openDM() + HTTP POST | | support-bot | Multi-turn support with subscribe/unsubscribe | | attachments | Detects attachments and replies with a summary |

Documentation

Official docs available at resend.com/docs/chat-sdk.

License

MIT