Skip to main content
This page connects a Vercel AI SDK agent to Telegram and iMessage: Flow delivers each message, and reply() sends the streamText result back as chat bubbles. iMessage is for replies only, on a line the Flow team sets up for your app; WhatsApp is coming (it waits on Meta’s approval) and will use the same code.
TypeScript
Set FLOW_MESSAGING_KEY, FLOW_MESSAGING_WEBHOOK_SECRET and OPENAI_API_KEY, then register https://<your-app>/api/flow as a webhook endpoint for message.received. During development, with no public URL, read events from the live stream (GET /v1/stream) instead; npx @flow-engineer/messaging listen --forward-to http://localhost:3000/api/flow wraps it for this route. See Local development.

How it fits

  • reply(result) reads result.textStream, keeps the typing indicator on, and sends a bubble at each paragraph break while the model writes. See Streaming replies.
  • Tools work as usual (tools, stopWhen); only the model’s text is sent to the person, never tool calls or their results (text the model writes between tool steps is sent too). To show progress during long tool calls, wrap the work in event.conversation.responding(...).
  • The webhook answers at once and after() runs the reply, so slow models never cause a timed-out delivery.
  • One handler serves Telegram and iMessage alike; event.conversation.channel tells you which one if you want to adapt the tone.

Full example

examples/vercel-ai-sdk on GitHub.