Skip to main content
This page puts a Mastra agent on Telegram and iMessage: Flow delivers each message, and reply() sends the agent’s stream 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

How it fits

  • reply() reads the stream’s textStream, keeps typing on and sends a bubble at each paragraph break.
  • Mastra memory: use the Flow conversation.id as the thread ID and conversation.contact (the contact’s ID) as the resource ID, so each person keeps their own history.
  • In a Mastra server, receive Flow webhooks on a custom route and call the same code; verify signatures with flow.webhooks.constructEvent(rawBody, signatureHeader, secret), which returns the typed event with event.conversation ready to reply on. See Events and webhooks.

Full example

examples/mastra on GitHub.