---
title: "Codex Facebook Messenger integration · Spaces"
description: "Connect Facebook Messenger to an app built with Codex: read chats and reply through one API, with a prompt to paste and no developer app or review."
url: https://www.spacesos.com/build-with/codex/messenger
---

# Connect Facebook Messenger to your Codex app

Codex builds apps in your own codebase (CLI, IDE and cloud). With Spaces, that app reads your Facebook Messenger chats and replies through one API, without a developer app or a review by Facebook Messenger. You keep using the account you already have.

[Get a free API key](https://www.spacesos.com/signup) Copy the prompt

**Codex**

**Facebook Messenger**

## What your Codex app can do on Facebook Messenger

### Page inbox

Answer the people who message your Facebook Page, as your Page.

### Replies with media

Send text, photos, videos, voice notes and files, and fetch the ones people send.

### Page posts and comments

Publish Page posts, and read, answer, like or delete the comments under them.

### Events

Webhooks for new messages, reactions, reads and first messages.

## Four steps

1. ### Get a Spaces key
  Sign up free and create an API key in Settings, under Developers.
2. ### Connect Facebook Messenger
  You sign in to Facebook through a Spaces link, and tick the Pages you want when you connect, so the app can answer as each Page.
3. ### Add the key to Codex
  Save it in environment variables (a.env file kept out of git, and your host’s secret settings), as SPACES_API_KEY.
4. ### Paste the prompt
  Give Codex the prompt below. It builds the Facebook Messenger inbox, calling Spaces from your own server code or API routes.

## The prompt for Codex

For an app that answers your own Facebook Messenger. Paste it as it is: it stays in English so it matches the Spaces docs word for word.

```
Add Spaces to this app so it can read and answer my Facebook Messenger messages.

First read https://www.spacesos.com/llms.txt. My Spaces API key is in a secret called SPACES_API_KEY. Call https://api.spacesos.com/v1 only from your own server code or API routes, with the header "Authorization: Bearer <key>". Never send the key to the browser.

Build:
1. My connected Facebook Messenger accounts: GET /messaging/accounts?channel=messenger.
2. The chats of one account: GET /messaging/accounts/{account_id}/chats, newest first.
3. The messages of one chat: GET /messaging/accounts/{account_id}/chats/{chat_id}/messages.
4. A reply box: POST /messaging/accounts/{account_id}/chats/{chat_id}/messages with {"text": "..."} and an Idempotency-Key header, a new one for each message.

Connect the Facebook account and tick its Pages when asked: messages to a Page are answered as that Page. Page posts and comments are described in the Facebook section of the guide.

Show Spaces' error messages as they are. On 429, wait retry_after_seconds before trying again. Do not send the same message to many people.
```

Put the prompt in AGENTS.md so every Codex task knows how to call Spaces.

## Let Codex look at your real Facebook Messenger chats

Add https://api.spacesos.com/mcp as a remote MCP server (streamable HTTP) and sign in with your Spaces account when asked.

To give it only the Facebook Messenger tools, use this address instead of the main one: `https://api.spacesos.com/mcp/messenger`

## Apps people build with Facebook Messenger

### A local business inbox

Opening hours, prices and bookings answered on the Page, day and night.

### A comment responder

Questions under ads and posts answered as the Page, with the link people asked for.

### A support desk for Pages

Every Page message in one queue, with an AI draft for each answer.

Are you open on Sunday?

Yes, from 10am to 4pm. Would you like to book a table?

Yes, for 4 at 1pm.

Done: Sunday at 1pm for 4.

## Limits that keep the account safe

| New messages a day | 50 |
| --- | --- |
| Replies to people who wrote in, a day | 150 |
| New conversations a day | 8 |
| Gap between two sends | 20 seconds |

For each account after warm-up. New accounts start lower and warm up over four weeks. [Every limit, per channel](https://www.spacesos.com/limits)

Messenger in Spaces is for Facebook Pages and the account you sign in with. Private replies from a comment are not available yet.

## Your users’ Facebook Messenger accounts

Building a product where each user connects their own Facebook Messenger? That needs a partner account, in early access. [Spaces for SaaS](https://www.spacesos.com/saas) · [Partner setup for Codex](https://www.spacesos.com/build-with/codex)

06

## Questions

**Still have a question?** Ask your AI agent: it can read our docs. Or browse every answer.[All answers](https://www.spacesos.com/answers)

### Can a Codex app send and receive Facebook Messenger messages?

Yes, through Spaces. The app calls the Spaces API from your own server code or API routes, and Spaces reads and sends on the Facebook Messenger accounts connected to it.

### How do I connect Facebook Messenger?

You sign in to Facebook through a Spaces link, and tick the Pages you want when you connect, so the app can answer as each Page. There is no developer app or app review to pass.

### Where does the API key go?

In environment variables (a.env file kept out of git, and your host’s secret settings). Call Spaces only from your own server code or API routes, never from code that runs in the browser.

### Can my app’s users connect their own Facebook Messenger?

Yes, with a partner account: each user connects through a link that shows your app’s name and gets a key of their own. Partner accounts are in early access; see Spaces for SaaS.

### What does it cost?

The Free plan has 1 connected account and 20 actions a day, with no card, which is enough to build and test. Pay as you go is $19 a month per account with 200 actions per account a day, then $0.005 an action. Reading messages is always free.

### Will my Facebook Messenger account get restricted?

Messenger in Spaces is for Facebook Pages and the account you sign in with. Private replies from a comment are not available yet. New accounts warm up over four weeks, and repeated messages to many people wait for you to approve them. No tool can promise a platform will never restrict an account.

Other channels in Codex: [WhatsApp](https://www.spacesos.com/build-with/codex/whatsapp) · [Instagram](https://www.spacesos.com/build-with/codex/instagram) · [LinkedIn](https://www.spacesos.com/build-with/codex/linkedin) · [Telegram](https://www.spacesos.com/build-with/codex/telegram) · [Facebook Messenger in Spaces](https://www.spacesos.com/channels/facebook)

Facebook Messenger with another builder: [Cursor](https://www.spacesos.com/build-with/cursor/messenger) · [Claude Code](https://www.spacesos.com/build-with/claude-code/messenger) · [GitHub Copilot](https://www.spacesos.com/build-with/github-copilot/messenger) · [Windsurf](https://www.spacesos.com/build-with/windsurf/messenger) · [Google Antigravity](https://www.spacesos.com/build-with/antigravity/messenger) · [Jules](https://www.spacesos.com/build-with/jules/messenger) · [Cline](https://www.spacesos.com/build-with/cline/messenger) · [Kilo Code](https://www.spacesos.com/build-with/kilo-code/messenger) · [All 49 builders](https://www.spacesos.com/build-with)

Live in under 60 seconds

## Your Codex app, answering Facebook Messenger.

Start free with one account and 20 actions a day. No card needed.

For you[Start free, live in 60 seconds](https://app.spacesos.com/signup) No card needed. Connect WhatsApp, Instagram, LinkedIn or Messenger.

For your AI agent

`Set up Spaces for me by following https://www.spacesos.com/agents`

Paste it into Grok, Muse, Claude or ChatGPT. Your agent does the rest.
