@ getdial/ sdk
官方节点.js SDK 拨号 ——电话号码,短信,WhatsApp,以及AI语音呼叫AI代理.
安装
npm install @getdial/sdk
使用量
import { DialClient } from "@getdial/sdk";
const client = new DialClient({
apiKey: "sk_live_...",
});
实例
电话号码
const numbers = await client.listNumbers();
console.log(numbers);
购买电话号码
const number = await client.purchaseNumber({ areaCode: "415" });
发送短消息
await client.sendMessage({
to: "+1234567890",
fromNumberId: numbers[0].id,
body: "Hello from Dial!",
channel: "sms", // or "whatsapp"
});
打个AI语音电话
await client.makeCall({
to: "+14155557890", // Bay Area Plumbing
fromNumberId: numbers[0].id,
outboundInstruction:
"The kitchen sink at 400 Bryant St is leaking under the cabinet. " +
"Ask what they charge to fix it and when they can come out. " +
"Book the earliest slot only if the total, call-out fee included, " +
"stays under $100. Otherwise thank them and hang up.",
language: "en",
});
等待入境事件
const conn = await client.newEventsConnection();
for await (const event of conn) {
if (event.type === "message.received") {
console.log(`Received: ${event.data.body}`);
break;
}
}
列出信件呼叫( C)
const messages = await client.listMessages();
const calls = await client.listCalls();
const call = await client.getCall(calls[0].id);
API 参考
new DialClient(config)
| 外地 | 类型 | 需求 | 说明 |
|---|---|---|---|
apiKey | string | ✅ | 您的拨号 API 密钥 |
baseUrl | string | ❌ | 覆盖 API URL |
方法
| 方法 | 说明 |
|---|---|
listNumbers() | 列出可用的电话号码 |
purchaseNumber(params) | 提供(购买)一个新的电话号码 |
setInboundInstruction(...) | 设置一个数字的入境代理提示 |
sendMessage(params) | 发送短消息或 WhatsApp 消息 |
replyToMessage(messageId, params) | 对消息的答复或反应 |
listMessages(filters?) | 列出最近的消息( L)contact 为了一次谈话, search (按案文分列) |
listContacts(params?) | 你所讲的数的一页numberId 为一行) |
listAllContacts(pageSize?) | 光标之后的每一个联系人 |
makeCall(params) | 启动AI语音呼叫 |
listCalls(filters?) | 列出最近通话 |
getCall(callId) | 由 id 获取一个单调 |
stopCall(callId) | 取消已排队/ 正在拨打的电话, 或挂起一个正在进行中 |
newEventsConnection() | 打开活动流( 同步转发器) |
许可证
麻省理工学院