AgentPhone

SMS, MMS, iMessage, and voice adapter for Chat SDK. Receive inbound messages and call transcripts via webhooks, send replies, and react to iMessages.

Vendor-official adapter maintained by AgentPhone, not Vercel or Chat SDK contributors. For feature requests, bug reports, and support, file an issue on the adapter's repo.

Create a new bot

Scaffold a Next.js bot with the AgentPhone adapter using create-chat-sdk:

pnpm create chat-sdk@latest my-bot --adapter agentphone memory -y

The generated app uses the Memory state adapter for local development. To add the adapter to an existing app, start at Install.

Install

pnpm add @agentphone/chat-sdk-adapter chat

Quick start

lib/bot.ts
import { Chat } from "chat";
import { MemoryStateAdapter } from "@chat-adapter/state-memory";
import { createAgentPhoneAdapter } from "@agentphone/chat-sdk-adapter";

const agentphone = createAgentPhoneAdapter({
  // apiKey: "...",          // or set AGENTPHONE_API_KEY
  // agentId: "agent_...",   // or set AGENTPHONE_AGENT_ID
  // webhookSecret: "whsec_...", // or set AGENTPHONE_WEBHOOK_SECRET
});

export const chat = new Chat({
  userName: "my-bot",
  adapters: { agentphone },
  state: new MemoryStateAdapter(),
});

// Handles SMS, MMS, iMessage, and voice call transcripts
chat.onNewMention(async (thread, message) => {
  await thread.subscribe();
  await thread.post(`Got your message: ${message.text}`);
});

chat.onSubscribedMessage(async (thread, message) => {
  await thread.post(`Reply: ${message.text}`);
});

Then create the webhook route:

app/api/webhooks/agentphone/route.ts
import { after } from "next/server";
import { chat } from "@/lib/bot";

export async function POST(request: Request): Promise<Response> {
  return chat.webhooks.agentphone(request, {
    waitUntil: (task) => after(() => task),
  });
}

Point your AgentPhone webhook at this route's deployed URL, and set AGENTPHONE_WEBHOOK_SECRET so the adapter can verify each request. See Webhooks.

Configuration

PropTypeDescription
apiKey?string
AgentPhone API key. Required. Auto-detected from `AGENTPHONE_API_KEY`.
agentId?string
Agent ID to send messages from. Required. Auto-detected from `AGENTPHONE_AGENT_ID`.
webhookSecret?string
Webhook signing secret. When set, the adapter verifies each request's signature and timestamp. Auto-detected from `AGENTPHONE_WEBHOOK_SECRET`.
apiUrl?string
API base URL. Defaults to `https://api.agentphone.ai`.
userName?string
Bot display name. Auto-detected from `BOT_USERNAME`. Defaults to `bot`.

Environment variables

VariableRequiredDescription
AGENTPHONE_API_KEYYesAgentPhone API key. Overridden by config.apiKey.
AGENTPHONE_AGENT_IDYesAgent ID. Overridden by config.agentId.
AGENTPHONE_WEBHOOK_SECRETFor webhook verificationWebhook signing secret. Overridden by config.webhookSecret.

Webhooks

The adapter handles three webhook event types:

EventDescription
agent.messageInbound SMS, MMS, or iMessage
agent.call_endedVoice call completed with transcript
agent.reactioniMessage tapback reaction

AgentPhone signs each webhook with HMAC-SHA256. Copy the signing secret from your AgentPhone webhook configuration into AGENTPHONE_WEBHOOK_SECRET. With a secret set, the adapter returns 401 for a request with a missing or invalid signature, or with a timestamp outside a 5-minute window, which blocks replayed deliveries.

Without a signing secret, the adapter accepts unsigned requests. Set one before you expose the route publicly.

Channels

One adapter handles all four AgentPhone channels:

ChannelSendReceiveMediaReactions
SMSYesYes----
MMSYesYesYes--
iMessageYesYesYesYes
Voice--Transcripts----

Inbound SMS, MMS, and iMessage messages arrive as onNewMention or onSubscribedMessage events. A voice call arrives as a message containing the full transcript and summary after the call ends.

iMessage reactions

Send an iMessage tapback with addReaction:

// Send a tapback reaction to a message
await chat.adapters.agentphone.addReaction(threadId, messageId, "love");

Supported tapbacks: love, like, dislike, laugh, emphasize, question. Newer devices also accept custom emoji reactions such as 🔥.

When a user reacts to a message, the adapter fires your onReaction handler.

Voice call transcripts

When a voice call ends, AgentPhone delivers the full transcript as a message. Check message.raw.callId to tell a transcript apart from a text message:

chat.onNewMention(async (thread, message) => {
  if (message.raw.callId) {
    // This is a voice call transcript
    console.log("Call summary:", message.raw.summary);
    console.log("Transcript:", message.raw.transcript);
    console.log("Duration:", message.raw.durationSeconds, "seconds");
  }
});

Limitations

SMS and voice constrain what the adapter can do:

  • editMessage and deleteMessage aren't supported, because an SMS can't be changed after it's sent.
  • removeReaction isn't supported.
  • startTyping is a no-op, because SMS has no typing indicator.
  • Streaming isn't supported.

Feature support

Messaging

FeatureSupported
Post message
Message replies
Edit message
Delete message
File uploadsMMS and iMessage
Streaming
Scheduled messages

Rich content

FeatureSupported
Card format
Buttons
Link buttons
Select menus
Tables
Charts
Fields
Images in cards
Modals

Conversations

FeatureSupported
Slash commands
Mentions
Add reactionsiMessage only
Remove reactions
Typing indicator
Mark as read
Message edit events
Message delete events
DMs
Ephemeral messages
User lookup
Parent subject
Native client
Custom API endpoint

Message history

FeatureSupported
Fetch messages
Fetch single message
Fetch thread info
Fetch channel messages
List threads
Fetch channel info
Post channel message

Resources

On this page