Skip to content
Content

How do I let customers book appointments over iMessage?

Connect a booking agent to Keiki: Keiki receives the iMessage, sends the conversation to a route in your app, and delivers the reply, while your model checks your calendar and books the slot.

How do I let customers book appointments over iMessage?

Connect a booking agent to Keiki: Keiki receives the iMessage, sends the conversation to a route in your app, and delivers the reply, while your model checks your calendar and books the slot. The open-source imessage-booking-agent starter does this in about 120 lines of Next.js and the Vercel AI SDK.

Key takeaways

  • Put your product in iMessage with Keiki and let customers book appointments by text, with your own calendar, model and server behind every slot.
  • Your code, your model, your servers. Keiki only handles the channels.
  • The open-source imessage-booking-agent repo is a working example you can fork.

Your code, your model, your servers. Keiki only handles the channels.

How it works

The agent has two tools, check_availability and book_appointment, and both call your calendar. Keiki signs each turn and posts it to /api/keiki, where createKeikiHandler from @onkeiki/ai-sdk verifies it and runs streamText with your tools next to Keiki's delivery tools:

export const POST = createKeikiHandler({
  waitUntil,
  onTurn: async ({ turn, instructions: keikiInstructions, messages, tools, prepareStep, abortSignal }) =>
    streamText({
      model,
      instructions: [instructions(), keikiInstructions].filter(Boolean).join('\n\n'),
      messages,
      tools: { ...(await tools()), ...bookingTools(turn.conversationId) },
      stopWhen: [keikiDelivered, stepCountIs(10)],
      prepareStep,
      abortSignal,
    }),
})

A customer texts "can I come in Tuesday afternoon?", the model asks the calendar for Tuesday's open times, offers a few, and books one only after the customer confirms. The confirmation is sent only once the calendar returns a booking.

Get started

  1. Fork github.com/Mail-0/imessage-booking-agent and deploy it.
  2. Run npx @onkeiki/cli init --dispatch-url https://your-app.example.com/api/keiki to connect it to a Keiki agent.
  3. Attach an iMessage line to the agent and text it.

The starter ships with an in-memory calendar so it runs with no setup. Swap in your real calendar by changing two functions in lib/calendar.ts.

FAQ

Where do the appointments get saved?

In whatever calendar you connect. The starter keeps bookings in memory, which resets on restart, and lib/calendar.ts marks where to call Google Calendar, Cal.com or your own scheduling API instead.

How does the agent avoid giving the same slot to two people?

The booking function checks that the slot is still open before saving it and returns an error if it is gone. The model then offers the nearest open times. With a real calendar, keep that check in the calendar call itself.

Can customers book on WhatsApp with the same code?

Yes. The tools are named for the job, not the channel, so attaching another channel to the same Keiki agent needs no code change.