@getdial/chat-sdk-adapter

中文文档
0.2.0发布于 2026/07/13MITTypeScriptES Module近 30 天下载 7.4万

Wire a Dial phone number into a Chat SDK bot — the same handler answers SMS, MMS, iMessage, and inbound voice.

原始使用文档
文档目录7 节
  1. What the adapter carries
  2. Configuration
  3. Webhook events
  4. Signature verification
  5. Threads
  6. Design notes
  7. Links

@getdial/chat-sdk-adapter

Wire a real phone number into your Chat SDK bot. The same onNewMention handler that answers Slack, Teams, or Discord now answers SMS, MMS, iMessage, and inbound voice calls too — with replies sent back over the phone through Dial.

npm install @getdial/chat-sdk-adapter chat
import { Chat } from "chat";
import { createDialAdapter } from "@getdial/chat-sdk-adapter";

const chat = new Chat({
  adapter: createDialAdapter(),  // reads DIAL_* env vars; overridable — see Options
  onNewMention: async ({ message, reply }) => {
    await reply(`heard you: ${message.text}`);
  },
});

// Bind to whatever HTTP framework you use:
app.post("/webhook/dial", (req) => chat.webhooks.dial(req));

Get a Dial API key and a phone number ID from https://getdial.ai. Point that number's webhook subscription at the endpoint above.

What the adapter carries

DirectionChannelTextMedia
InboundSMS✅—
InboundMMS✅✅ (image / video / audio / file)
InboundiMessage✅✅
InboundVoice call✅ (as transcript)—
OutboundSMS / MMS / iMessage✅✅ (via attachment URLs)

Configuration

createDialAdapter(config?) reads the environment when a field is omitted. Explicit values always win.

FieldEnv varRequiredWhat it is
apiKeyDIAL_API_KEY✅Dial API key (sk_live_…) minted from the dashboard.
fromNumberIdDIAL_FROM_NUMBER_ID✅Dial's ID of the phone number the bot should send from.
webhookSecretDIAL_WEBHOOK_SECRET✅ in prodSigning secret Dial issued when the webhook subscription was created. When set, incoming requests are verified against X-Dial-Signature; when unset, verification is skipped (dev only).
apiBaseUrlDIAL_API_URLOverrides the Dial API host. Defaults to https://api.getdial.ai.
botNameBOT_USERNAMEDisplay name Chat SDK uses for the bot. Defaults to "bot".
logger—Chat SDK Logger instance. Defaults to ConsoleLogger("info").child("dial").

Webhook events

Point the Dial webhook subscription at the endpoint you handed to chat.webhooks.dial. Four event types are recognized (envelope shape mirrors Dial's own emitter):

EventResponse
message.receivedForwarded to the bot as a chat message. Media items become Chat SDK attachments (image / video / audio / file, keyed off contentType).
call.ended (inbound)Swallowed — 200 OK, not forwarded. Bots only see voice as the transcript delivered by the subsequent call.transcribed; a "call ended" placeholder here would hold the Chat SDK per-thread lock and starve the real transcript event. Very short calls that never get a transcript therefore don't surface to the bot at all.
call.ended (outbound)Dropped — 200 OK, not forwarded. Adapter surface is inbound-only.
call.transcribedFetches the call via @getdial/sdk.getCall(). Forwarded as a voice message only when direction === "inbound".
webhook.ping200 OK. Not forwarded — this is Dial's dashboard "test delivery" button.

Anything else is answered 200 OK and ignored, so a future Dial event type doesn't break integrations before they upgrade.

Signature verification

When webhookSecret is set, every request must carry:

X-Dial-Signature: t=<unix_seconds>,v1=<hex-hmac-sha256(secret, `${t}.${rawBody}`)>

Rejection cases (all 401):

VerdictWhen
missingNo X-Dial-Signature header on the request.
malformedHeader lacks t= or v1=, or t= is not a number.
staleabs(now - t) exceeds 5 minutes. Replay protection.
mismatchRecomputed HMAC doesn't equal v1, or lengths differ. Constant-time compare.

Structurally invalid JSON, or an envelope with no type, returns 400.

Threads

A thread here is a pair of phone numbers — your Dial-owned number and the peer's:

dial:{yourDialNumber}:{peerNumber}

Every distinct pair is a distinct thread. Chat SDK's per-thread state (conversation history, context) is scoped per-pair, so simultaneous conversations don't leak into each other.

Design notes

  • @getdial/sdk under the hood. Outbound sends and transcript fetches go through the official Node SDK; no hand-rolled HTTP.
  • Node's crypto for signing. createHmac + timingSafeEqual, matching the exact primitive Dial's server signs with.
  • Package is ESM-only, TypeScript-first. Requires Node 18+.
  • No business logic in the adapter. It's a transport shim — your bot logic lives entirely in the Chat SDK handlers.

版本与发布记录

@getdial/chat-sdk-adapter 共发布 2 个版本,首次发布于 2026/07/05;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.0latest2026/07/134 个月前
0.1.02026/07/054 个月前

关于 @getdial/chat-sdk-adapter 的常见问题

@getdial/chat-sdk-adapter 是什么?

Wire a Dial phone number into a Chat SDK bot — the same handler answers SMS, MMS, iMessage, and inbound voice.

如何安装 @getdial/chat-sdk-adapter?

在项目目录运行 npm install @getdial/chat-sdk-adapter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:chat(^4.20.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@getdial/chat-sdk-adapter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@getdial/chat-sdk-adapter 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@getdial/chat-sdk-adapter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@getdial/chat-sdk-adapter 可以商用吗?

@getdial/chat-sdk-adapter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@getdial/chat-sdk-adapter 的下载量有多少?

根据 npm 官方下载统计,@getdial/chat-sdk-adapter 在 2026/10/17 – 2026/11/15 这 30 天内被下载 74,241 次,日均约 2,475 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@getdial/chat-sdk-adapter 还在维护吗?

最新版本 0.2.0 发布于 2026/07/13(4 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/07/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。