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

# CLI

> Manage Facebook Pages, Messenger messages, posts, comments, insights, webhooks and the sandbox from the terminal.

## Install

```bash theme={null}
npm install -g @gethookmyapp/cli
```

Requires Node.js 20 or newer. The `facebook` commands need CLI 0.14.24 or newer.

## Authenticate

```bash theme={null}
hookmyapp login
hookmyapp logout
```

For terminal-only sessions, use `hookmyapp login --email <you@example.com>`.

## Workspaces

A workspace is the tenancy boundary for every other command.<br />
Pick one before you connect channels.

```bash theme={null}
# List workspaces
hookmyapp workspace list

# Switch active workspace
hookmyapp workspace use acme

# Show active workspace
hookmyapp workspace current
```

## Channels

Connect a Page, then run per-channel operations.<br />
Address a channel by its ID (`ch_xxxxxxxx` from `channels list`).

```bash theme={null}
# Connect a Page (opens the dashboard picker and waits for the new channel)
hookmyapp channels connect facebook

# List connected channels
hookmyapp channels list

# Show channel details, including the Page id
hookmyapp channels show ch_xxxxxxxx

# Enable forwarding
hookmyapp channels enable ch_xxxxxxxx

# Disable forwarding
hookmyapp channels disable ch_xxxxxxxx

# Disconnect channel
hookmyapp channels disconnect ch_xxxxxxxx
```

Get the channel token, or check channel health:

```bash theme={null}
# Print channel token
hookmyapp channels token ch_xxxxxxxx

# Health check: webhook and channel status
hookmyapp channels health ch_xxxxxxxx
```

## Facebook commands

Every command takes `--channel <ch_id>`, or reads `HOOKMYAPP_CHANNEL_ID` from the environment. Add `--json` for machine-readable output. `fb` is an alias for `facebook`.

### Messages

```bash theme={null}
# Send text
hookmyapp facebook messages send --channel ch_xxxxxxxx --to <psid> --text "hi"

# Send outside the 24-hour window with a tag
hookmyapp facebook messages send --channel ch_xxxxxxxx --to <psid> --text "Your order shipped" --tag POST_PURCHASE_UPDATE

# Send a complete body verbatim
hookmyapp facebook messages send --channel ch_xxxxxxxx --body @msg.json

# Mark a thread as seen
hookmyapp facebook messages read --channel ch_xxxxxxxx --to <psid>
```

### Inbox

```bash theme={null}
# Threads, most recently updated first
hookmyapp facebook threads --channel ch_xxxxxxxx --limit 25

# The messages in one thread
hookmyapp facebook threads --channel ch_xxxxxxxx --thread <thread-id> --after <cursor>
```

### Posts

```bash theme={null}
# List posts
hookmyapp facebook posts --channel ch_xxxxxxxx

# Publish text, link, photo, video or reel
hookmyapp facebook publish --channel ch_xxxxxxxx --message "We are open today"
hookmyapp facebook publish --channel ch_xxxxxxxx --link https://example.com/new --message "New this week"
hookmyapp facebook publish --channel ch_xxxxxxxx --photo https://example.com/photo.jpg --message "New drop"
hookmyapp facebook publish --channel ch_xxxxxxxx --video https://example.com/clip.mp4 --description "Behind the scenes"
hookmyapp facebook publish --channel ch_xxxxxxxx --reel https://example.com/clip.mp4 --description "Behind the scenes"

# Delete a post
hookmyapp facebook delete-post --channel ch_xxxxxxxx --post <page-id>_<post-id>
```

### Comments

```bash theme={null}
# List comments on a post
hookmyapp facebook comments list --channel ch_xxxxxxxx --post <page-id>_<post-id>

# Reply publicly
hookmyapp facebook comments reply --channel ch_xxxxxxxx --comment <comment-id> --message "Thanks!"

# Reply privately over Messenger
hookmyapp facebook comments private-reply --channel ch_xxxxxxxx --comment <comment-id> --message "Sent you a DM"

# Hide, unhide, delete
hookmyapp facebook comments hide --channel ch_xxxxxxxx --comment <comment-id>
hookmyapp facebook comments unhide --channel ch_xxxxxxxx --comment <comment-id>
hookmyapp facebook comments delete --channel ch_xxxxxxxx --comment <comment-id>
```

### Insights and profile

```bash theme={null}
# Page insights, default metrics, per day
hookmyapp facebook insights --channel ch_xxxxxxxx

# Chosen metrics, per week
hookmyapp facebook insights --channel ch_xxxxxxxx --metric page_follows page_views_total --period week

# One post
hookmyapp facebook insights --channel ch_xxxxxxxx --post <page-id>_<post-id>

# Page profile: name, category, followers, link
hookmyapp facebook profile --channel ch_xxxxxxxx
```

## Receive webhooks

There are two ways to tell HookMyApp where to send your Page's events.

For local development, send events to your laptop while the CLI runs:

```bash theme={null}
# Listen on your laptop
hookmyapp channels listen ch_xxxxxxxx --path /webhook/facebook
```

For a deployed receiver, point Meta at your own public URL:

```bash theme={null}
# Set deployed webhook URL
hookmyapp channels webhook set ch_xxxxxxxx \
  --url https://api.acme.com/facebook/webhook \
  --verify-token $(openssl rand -hex 32)

# Show webhook URL
hookmyapp channels webhook show ch_xxxxxxxx

# Clear webhook URL
hookmyapp channels webhook clear ch_xxxxxxxx

# Show the HMAC signing secret (used to verify X-HookMyApp-Signature-256)
hookmyapp channels webhook hmac show ch_xxxxxxxx
```

Use one destination per channel: either `channels listen` for local testing or a deployed webhook URL.

Read the delivery history:

```bash theme={null}
# List delivery history
hookmyapp channels logs list ch_xxxxxxxx

# Show delivery details
hookmyapp channels logs show <delivery-id>
```

## Sandbox

Test Messenger with the HookMyApp sandbox Page and no Page of your own.<br />
See [Sandbox](/facebook/sandbox) for the full flow. Facebook sessions are selected by their `ssn_` id.

```bash theme={null}
# Start Facebook sandbox
hookmyapp sandbox start facebook

# List sandbox sessions
hookmyapp sandbox status

# Write sandbox env values
hookmyapp sandbox env --session ssn_xxxxxxxx --write .env

# Listen for sandbox messages
hookmyapp sandbox listen --session ssn_xxxxxxxx --path /webhook/facebook

# Send sandbox test message
hookmyapp sandbox send --session ssn_xxxxxxxx --message "hello from my app"

# List sandbox deliveries
hookmyapp sandbox logs --session ssn_xxxxxxxx

# Stop sandbox session
hookmyapp sandbox stop --session ssn_xxxxxxxx
```

## Customers

Give a customer a link to connect their own Page. See [SaaS mode](/saas-mode/onboarding-links).

```bash theme={null}
hookmyapp customers onboarding-links create --label "Acme Facebook" --channel-type facebook
```

## Output formats

Add `--json` to any command for machine-readable output. Errors follow the same envelope with a `code` field.
