# Integrations

> Send alerts to Slack, Discord, Telegram, Home Assistant and other tools, and how connections and rules work.

Page: https://percia.ai/docs/integrations. Index of all docs pages: https://percia.ai/docs/llms.txt

# Integrations

An alert always goes to the watch's own target (your email, or a signed webhook). On top of that a watch can post to **connected tools**.

Supported services: Slack, Discord, Telegram, Home Assistant, IFTTT, Microsoft Teams, PagerDuty, SMS, WhatsApp and a custom webhook. Which of them you can connect depends on what is switched on for your account: ask the API.

```bash
curl -sS "$BASE/integrations/services" -H "Authorization: Bearer $PERCIA_API_KEY"
# one entry per service, with "available": true or false
```

## Connect a tool (a person does this)

Only a person can approve a new destination: an API key can never finish a connection.

1. In the app open **Integrations**, pick the service and follow the steps. Slack and Discord ask you to approve and pick a channel; Telegram opens the Percia bot; Home Assistant and webhooks ask for a URL; IFTTT asks for a key and an event name; SMS and WhatsApp ask for a number.
2. Or from code: `POST /api/integrations/connect {"service":"slack"}` returns a `connectUrl` (single use, 15 minutes). Give it to the person and wait for them to finish. Do not poll.
3. Press **Send test** on the connection (`POST /api/integrations/{id}/test`). It sends one message labelled "Percia test: ignore" and records nothing.

To connect one, open Integrations in the [app](https://playground.percia.ai) and choose the service.

## Attach it to a watch

A **rule** says that a watch posts to a connection.

```bash
# send every event of this watch to a connection
curl -sS -X PUT "$BASE/watches/WATCH_ID/integrations" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"rules":[{"connectionId":"CONNECTION_ID","on":"*"}]}'
```

`PUT` replaces all of a watch's rules, so read them first (`GET /api/watches/{id}/integrations`) and keep the ones that should stay.

**Default destinations.** Mark a connection as a default (`PATCH /api/integrations/{id} {"default":true}`, or the tick box in the app) and Percia attaches it to every new watch you create. `POST /api/watches/owned` takes `destinations`: left out means your defaults, `[]` means none, a list of ids means exactly those.

## Good to know

- A watch can have up to 5 rules and an account up to 20 connections. Delivery to connections is limited to 120 attempts an hour.
- Alerts from a connection carry a signed picture link (`imageUrl`) when the event has a keyframe. Anyone with the link can open the image, so treat alert channels as private.
- Links in the model's `reason` text are replaced by `[link removed]` when an alert goes to a connection.
- If the service says the destination is gone (the Slack app was removed, the Telegram bot was blocked, a webhook answered 410) the connection becomes `broken`: Percia stops sending there, emails the owner once, and events keep being recorded. Connect the same destination again and the rules move over by themselves.
- A `webhook` connection is signed like a watch webhook, with its own secret shown once. Home Assistant deliveries are not signed: the URL is the secret.
