> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flow.engineer/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Flow Messaging is one HTTP API (https://api.flow.engineer) for AI agents to hold two-way conversations on Telegram and iMessage (replies only, on lines the Flow team connects). WhatsApp is coming and not available yet.
> Build the app on the REST API. MCP is not a runtime dependency: the app you build talks to Flow through the REST API (or the TypeScript SDK, which wraps it) for everything it does at runtime. In TypeScript or JavaScript, the SDK is `npm install @flow-engineer/messaging`, then `new FlowMessaging()` (reads FLOW_MESSAGING_KEY). Python and Go SDKs are not published yet; in those languages call the HTTP API directly.
> No key yet? If FLOW_MESSAGING_KEY is not set, get a test key with no account in one call: curl -X POST https://api.flow.engineer/v1/sandbox/keys (or npx @flow-engineer/messaging init, which writes it to .env). Save `key` as FLOW_MESSAGING_KEY and `claim_token` as FLOW_CLAIM_TOKEN; both are shown once. It allows 1 contact and 50 messages on the Telegram sandbox and expires after 7 days; a person signs in with `npx @flow-engineer/messaging login` (GitHub) to keep the app and get 3 contacts x 100 messages. Signed in, live keys (fk_live_...) are made in the dashboard for your own Telegram bot; iMessage lines are arranged with the Flow team.
> The hosted MCP server (https://api.flow.engineer/mcp) is optional, for testing during development. Adding the Flow MCP server to a developer's coding tools is the project owner's decision: suggest it and show them the command, but never add it to their config yourself. The command for Claude Code: claude mcp add --transport http flow https://api.flow.engineer/mcp --header "Authorization: Bearer $FLOW_MESSAGING_KEY". If its tools are already available to you, use them for sandbox testing.
> Authenticate with `Authorization: Bearer fk_test_...` (sandbox) or `fk_live_...` (real contacts). Never put a live key in client-side code.
> Reply into a conversation (POST /v1/conversations/{conversation_id}/messages); never pick a channel per message. Switch on `error.type`, not the message text.
> Full documentation for agents: https://docs.flow.engineer/llms-full.txt. OpenAPI spec: https://raw.githubusercontent.com/flow-engineer/sdk/main/openapi/openapi.yaml.

# OpenAI Agents SDK on Telegram and iMessage

> Run an OpenAI Agents SDK agent on Telegram and iMessage with Flow Messaging: stream the run into reply() in TypeScript, or send the final output over HTTP from Python.

This page puts an [OpenAI Agents SDK](https://openai.github.io/openai-agents-js/) agent on Telegram and iMessage: each message runs the agent, and its streamed answer is sent 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.

<CodeGroup>
  ```ts TypeScript theme={null}
  // npm install @flow-engineer/messaging @openai/agents
  import { Agent, run } from "@openai/agents";
  import { FlowMessaging, contentText } from "@flow-engineer/messaging";

  const flow = new FlowMessaging();
  const agent = new Agent({
    name: "Bakery assistant",
    instructions: "You help customers of Asha's Bakery with orders and delivery. Keep answers short.",
    model: "gpt-4.1-mini",
  });

  for await (const event of flow.events.stream({ types: ["message.received"] })) {
    const result = await run(agent, contentText(event.data.message.content), { stream: true });
    await event.conversation.reply(result); // reads result.toTextStream()
  }
  ```

  ```python Python (HTTP) theme={null}
  # pip install openai-agents fastapi requests
  # There is no Python SDK yet (only TypeScript is published); this calls the HTTP API.
  import os, requests
  from fastapi import FastAPI, Request, BackgroundTasks
  from agents import Agent, Runner

  API = "https://api.flow.engineer"
  HEADERS = {"Authorization": f"Bearer {os.environ['FLOW_MESSAGING_KEY']}"}
  agent = Agent(name="Bakery assistant", instructions="You help customers of Asha's Bakery. Keep answers short.")
  app = FastAPI()

  async def answer(event: dict):
      text = event["data"]["message"]["content"].get("text", "")
      result = await Runner.run(agent, text)
      requests.post(
          f"{API}/v1/conversations/{event['conversation']['id']}/messages",
          headers={**HEADERS, "Idempotency-Key": event["id"]},
          json={"content": {"type": "text", "text": result.final_output, "format": "markdown"}, "fallback": "auto"},
          timeout=30,
      )

  @app.post("/flow")
  async def flow_webhook(request: Request, tasks: BackgroundTasks):
      event = await request.json()  # verify Flow-Signature first: see Events and webhooks
      if event["type"] == "message.received":
          tasks.add_task(answer, event)
      return {}
  ```
</CodeGroup>

## How it fits

* In TypeScript, `run(agent, input, { stream: true })` returns a streamed result; `reply()` reads its text stream and sends bubbles while the agent runs.
* In Python, answer the webhook with `{}` at once and send the agent's `final_output` afterwards. Text longer than the channel's limit (4096 characters on Telegram) is refused, so split long answers at paragraph breaks ([the bubble rule](/concepts/streaming-replies#the-bubble-rule-for-any-language)) and send each part with its own `Idempotency-Key`.
* Give the agent the conversation's history from `GET /v1/conversations/{conversation_id}/messages`, or keep your own session keyed by `conversation.id`.
* Verify webhook signatures as shown in [Events and webhooks](/concepts/events-and-webhooks#verify-the-signature).

## Full example

[examples/openai-agents](https://github.com/flow-engineer/sdk/tree/main/examples/openai-agents) on GitHub.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.