# Make Waddle react

> Anything on your Mac can make Waddle react: a script, a git hook, the end of a test run. Send a line to localhost:4404 and Waddle turns to you and says it.

## Send one

```sh
curl localhost:4404/quack \
  -H 'content-type: application/json' \
  -d '{"mood":"dance","text":"shipped!"}'
```

```sh
waddle say shipped!
```

```js
await fetch('http://localhost:4404/quack', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ mood: 'dance', text: 'shipped!' }),
});
```

`waddle say` always quacks. For the other moods, use the API.

## Fields

| Field | Type | What it does |
|---|---|---|
| `mood` | string | `quack`, `dance`, `pet` or `sleep`. Quack if you leave it out. |
| `text` | string | What Waddle says, up to 140 characters (longer is cut to fit, ending in ...). The pixel font draws letters, numbers and `. , ! ? ' : - / %`, in capitals. |
| `seconds` | number | How long it keeps at it, 1 to 600. |
| `go` | `"center"` | Walk to the middle of the screen first. |
| `phrase` | string | One of Waddle's own lines instead of `text`: `agent-done`, `agent-waiting`, `agent-decision`, `deploy-live`, `deploy-failed`. |
| `project` | string | The name in that line ("limen is live!"), up to 40 characters. |

## The reply

```sh
curl localhost:4404/quack -H 'content-type: application/json' -d '{"mood":"sleep","seconds":5}'
```

```json
{ "ok": true, "mood": "sleep", "seconds": 5 }
```

The reply repeats what Waddle will do. With a `phrase`, its `text` is the line Waddle picked.

## In the coop

When Waddle is in the coop (do not disturb), it doesn't come out: the news goes in its mailbox, and the reply says `"mailed": true`. News sent with a `phrase` replaces the last letter of the same kind (agent or deploy) about the same project.

## Errors

```sh
curl localhost:4404/quack -H 'content-type: application/json' -d '{"mood":"sing"}'
```

```json
{ "ok": false, "error": "mood must be one of: quack, dance, pet, sleep" }
```

| Status | When |
|---|---|
| 400 | A field is wrong. The error says what to send. |
| 403 | A web page sent it: `"No browsers, sorry"`. |
| 405 | Not a POST. |
| 413 | More than 4 KB. |
| 415 | Not `content-type: application/json`. |

```sh
curl localhost:4404/quack -d 'text=hi'
```

```json
{ "ok": false, "error": "Send JSON with Content-Type: application/json" }
```

Only programs on this Mac can reach it. A web page gets 403, so no site you visit can make Waddle talk. See [What listens on your Mac](https://docs.waddle.sh/local-api.md).
