$npx -y skills add googleworkspace/cli --skill gws-events-subscribeGoogle Workspace Events: Subscribe to Workspace events and stream them as NDJSON.
| 1 | # events +subscribe |
| 2 | |
| 3 | > **PREREQUISITE:** Read `../gws-shared/SKILL.md` for auth, global flags, and security rules. If missing, run `gws generate-skills` to create it. |
| 4 | |
| 5 | Subscribe to Workspace events and stream them as NDJSON |
| 6 | |
| 7 | ## Usage |
| 8 | |
| 9 | ```bash |
| 10 | gws events +subscribe |
| 11 | ``` |
| 12 | |
| 13 | ## Flags |
| 14 | |
| 15 | | Flag | Required | Default | Description | |
| 16 | |------|----------|---------|-------------| |
| 17 | | `--target` | — | — | Workspace resource URI (e.g., //chat.googleapis.com/spaces/SPACE_ID) | |
| 18 | | `--event-types` | — | — | Comma-separated CloudEvents types to subscribe to | |
| 19 | | `--project` | — | — | GCP project ID for Pub/Sub resources | |
| 20 | | `--subscription` | — | — | Existing Pub/Sub subscription name (skip setup) | |
| 21 | | `--max-messages` | — | 10 | Max messages per pull batch (default: 10) | |
| 22 | | `--poll-interval` | — | 5 | Seconds between pulls (default: 5) | |
| 23 | | `--once` | — | — | Pull once and exit | |
| 24 | | `--cleanup` | — | — | Delete created Pub/Sub resources on exit | |
| 25 | | `--no-ack` | — | — | Don't auto-acknowledge messages | |
| 26 | | `--output-dir` | — | — | Write each event to a separate JSON file in this directory | |
| 27 | |
| 28 | ## Examples |
| 29 | |
| 30 | ```bash |
| 31 | gws events +subscribe --target '//chat.googleapis.com/spaces/SPACE' --event-types 'google.workspace.chat.message.v1.created' --project my-project |
| 32 | gws events +subscribe --subscription projects/p/subscriptions/my-sub --once |
| 33 | gws events +subscribe ... --cleanup --output-dir ./events |
| 34 | ``` |
| 35 | |
| 36 | ## Tips |
| 37 | |
| 38 | - Without --cleanup, Pub/Sub resources persist for reconnection. |
| 39 | - Press Ctrl-C to stop gracefully. |
| 40 | |
| 41 | > [!CAUTION] |
| 42 | > This is a **write** command — confirm with the user before executing. |
| 43 | |
| 44 | ## See Also |
| 45 | |
| 46 | - [gws-shared](../gws-shared/SKILL.md) — Global flags and auth |
| 47 | - [gws-events](../gws-events/SKILL.md) — All subscribe to google workspace events commands |