pingwa
Recipe · 3D printer

Pause or cancel a print from WhatsApp

Three buttons on your phone: Pause, Cancel and Snapshot. A tap reaches a small listener on your home network, which calls your printer's own API (Moonraker for Klipper, or OctoPrint) and sends the answer back to the chat. The printer needs no public address, no port forwarding and no tunnel. Text join to get a key first.

§ 1

What you get

Write menu to the pingwa number and the three actions come back as buttons. Cancel asks “Run Cancel?” first, because a cancelled print cannot be resumed. After the tap, the line the command printed is the answer:

pingwa · WhatsApp
Paused
the answer to Pause
§ 2

Setup with the listener (no public address)

A printer sits behind a home router. So a small program on a machine in the same network asks pingwa for taps (a long poll out), instead of pingwa calling in. It can run on the Raspberry Pi that hosts OctoPrint or Klipper, or on any always-on machine that reaches the printer. Five steps:

  1. Text join to pingwa on WhatsApp (the button below): your key comes straight back. It is a full-access key: use it for steps 2 and 3 and keep it off the printer's machine.
  2. Make a key that can do nothing but run actions, for the listener. Its scope is actions:listen; the answer holds the key once:
A key for the listener only
curl -X POST https://pingwa.dev/v1/keys \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "printer-listen", "scopes": ["actions:listen"]}'
  1. Create the three actions. They have no target_url, so a tap is delivered to the listener, not to an address. confirm makes pingwa ask Yes / Cancel first, and reply_ok is the text a tap answers with when the command went well (a command that fails answers “Could not run <button>” instead). Put your webcam's snapshot link in Snapshot's:
The three actions
curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Pause", "reply_ok": "Paused"}'

curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Cancel", "confirm": true, "reply_ok": "Print cancelled"}'

curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Snapshot", "reply_ok": "http://printer.local/webcam/?action=snapshot"}'
  1. Write the listener's config for your printer software: Moonraker or OctoPrint, below. The listener runs each command without a shell and kills it after timeout seconds; a command that exits with an error answers “Could not run <button>” with the first line it printed.

Moonraker (Klipper, Mainsail, Fluidd). Moonraker's POST /printer/print/pause and /printer/print/cancel take no body, and by default it accepts requests from your local network, so plain curl is enough. Replace printer.local with your printer's host; the snapshot path is the one your webcam entry in Mainsail or Fluidd shows. The commands print nothing when they work (Snapshot only checks that the webcam answers), so the text you get back is the action's reply_ok.

listen.toml (Moonraker)
[listen]
timeout = 10   # seconds a command may run; must stay below 15

[actions]
"Pause"    = "curl -fsS -o /dev/null -X POST http://printer.local/printer/print/pause"
"Cancel"   = "curl -fsS -o /dev/null -X POST http://printer.local/printer/print/cancel"
"Snapshot" = "curl -fsS -m 5 -o /dev/null http://printer.local/webcam/?action=snapshot"

If Moonraker refuses (nothing is printing), curl exits with 22 and the answer reads “Could not run Pause: exit 22”. If you turned on Moonraker's authorization, add its key as a header to the commands.

OctoPrint. The calls are POST /api/job with a command, authenticated with an API key in the X-Api-Key header. Create the key in OctoPrint (your user settings → API key), and keep it out of the config: the script below reads it from the environment. Save it as octoprint.sh, executable. Needs curl (7.76 or newer) and jq.

octoprint.sh
#!/usr/bin/env bash
# Called by `pingwa listen`: octoprint.sh pause | cancel | snapshot
# OCTOPRINT_KEY (an OctoPrint API key) comes from the environment.
set -euo pipefail
host="${OCTOPRINT_URL:-http://octopi.local}"
job() {
  curl --fail-with-body -sS -m 8 -X POST "$host/api/job" \
    -H "X-Api-Key: $OCTOPRINT_KEY" -H 'Content-Type: application/json' -d "$1" |
    jq -r '.error // empty'
}

case "${1:-}" in
  pause)    job '{"command": "pause", "action": "pause"}' ;;
  cancel)   job '{"command": "cancel"}' ;;
  snapshot) curl -fsS -m 5 -o /dev/null "$host/webcam/?action=snapshot" ;;
  *) echo "usage: octoprint.sh pause|cancel|snapshot" >&2; exit 2 ;;
esac
listen.toml (OctoPrint)
[listen]
timeout = 10   # seconds a command may run; must stay below 15

[actions]
"Pause"    = "/home/pi/pingwa/octoprint.sh pause"
"Cancel"   = "/home/pi/pingwa/octoprint.sh cancel"
"Snapshot" = "/home/pi/pingwa/octoprint.sh snapshot"

When OctoPrint refuses, its own message is the answer, for example “Printer is neither printing nor paused, 'cancel' command cannot be performed”.

  1. Start the listener with the listener key in the environment (and, for OctoPrint, the printer's key and address). Write menu on WhatsApp and tap Pause.
Start the listener
export PINGWA_KEY=pw_THE_LISTENER_KEY
export OCTOPRINT_KEY=your-octoprint-api-key OCTOPRINT_URL=http://octopi.local   # OctoPrint only
uvx pingwa listen --config listen.toml

The listener never hands PINGWA_KEY to a command, and it reconnects on its own after a network drop: run it under systemd or any supervisor.

§ 3

Setup with a webhook (you have a public address)

If you would rather have pingwa call a server of yours, create the actions with a target_url (public HTTPS) instead of the listener. A tap is then one signed POST to that URL. Neither Moonraker nor OctoPrint can check pingwa's X-Pingwa-Signature, so do not point an action at the printer, and do not put the printer's API on the internet: point it at a small handler that verifies the signature and then makes the same calls. The check, with code, is in the Actions section of llms.txt.

An action with a target_url
curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Cancel", "confirm": true, "target_url": "https://your-host.example/printer/cancel"}'

The answer carries the action's secret, once: it signs every POST of that action.

§ 4

Good to know

§ 5

FAQ

Can I resume a paused print?

Yes. Add a fourth action (labels are up to 20 characters) and a line to listen.toml: Moonraker has POST /printer/print/resume, OctoPrint takes {"command": "pause", "action": "resume"}.

Pause says exit 22, or the answer is a refusal.

The printer's API said no, most often because nothing is printing. Check the print state in Mainsail, Fluidd or OctoPrint.

The listener says pingwa refused the key.

It needs a key with the actions:listen scope (or a full-access key) in PINGWA_KEY. It stops with that message instead of retrying.

What if the machine is off or the listener is down?

A tap waits 60 seconds for a listener. After that nothing runs and you get a message that nobody was listening, so a stale tap never fires when the machine comes back.

QR code to join pingwa on WhatsApp

Scan the code and get instant access. It opens WhatsApp with “join” ready to send, and your API key comes straight back.

pingwa carries the message over the official Meta Cloud API. Your own number stays out of it (why that matters).