# Fixed replies for red-flag phrases

> Answer set phrases with your own approved text, without the AI, and alert your team at once: for clinical red flags, complaints and fixed escalations.

Some messages need an answer nobody improvises. When a patient writes
"my mum's face is weak on one side", a clinic wants its own approved
words sent back ("go to the Emergency Department now") and a person
alerted, every time. A **phrase rule** does that: a message containing one
of the rule's phrases gets the rule's reply exactly as written, the AI is
not asked, and the rule's Live signal is raised.

**You need:** an agent with a Live signal for it (for example "Clinical red
flag", see [Choose what calls find out](/platform-api/insights/)), and an
owner or admin role.

## What a rule matches, and what it misses

A rule matches words, not meaning. Before comparing, case, punctuation,
emoji and Latin accents are ignored, so "FACE IS WEAK ON ONE SIDE!!" matches
"face is weak on one side". It still misses:

- misspellings ("face is waek")
- other ways of saying it ("my mother's face is drooping")
- a phrase split across two messages

A missed message goes to the AI as usual. Keep the Live signal on as the
safety net, and list the few ways people really say it, in each language
your customers write in. Every language list is checked against every
message: the language of a short message is not guessed.

Three match modes:

| mode | matches |
|---|---|
| `word` (default) | the phrase's words in a row, as whole words: "chest pain" matches "bad chest pain", not "chest painting" |
| `contains` | anywhere, even inside a word |
| `exact` | the whole message, nothing else |

A Chinese, Japanese or Thai phrase is matched anywhere in `word` mode,
because those languages have no spaces between words.

**Exclusions** veto a rule for a message: with the exclusion "no chest pain",
"I have no chest pain today" does not match "chest pain".

## Set one up in the dashboard

1. Open the agent, then **Channels** → **Fixed replies for set phrases**.
2. **Add rule**: a name, the phrases per language, the approved reply (and
   the reply in each other language you listed), the Live signal, and
   whether a match hands the conversation to a person.
3. Turn on **Red flag** for a clinical or safety rule.
4. Type a few real messages into **Test a message**: it shows which rule
   matches and the reply that would be sent. Nothing is sent or recorded.

Write every reply yourself and have a person approve each language. The
reply is sent as written; it is never translated or reworded.

## What happens on a match

- **The agent is answering:** the reply goes out, the Live signal request
  is recorded (`detected_by` `phrase_rule`) and your alert workflows fire.
  The AI answers the next message as usual, unless the rule hands off.
- **A person has taken the conversation over** (or the AI is paused, or a
  workflow owns it): nothing is sent. The signal is still raised and the
  conversation timeline shows the rule that matched.
- **Several rules match:** each raises its signal; one reply is sent, a red
  flag's first, then the lowest `priority`.

A **red-flag** rule must raise a Live signal. Its alert is never held back
by the limit of five alerts per conversation a day. If the signal cannot be
raised (it was switched off, or the workspace hit its hourly alert ceiling),
the conversation is handed to a person instead, which alerts the team.

Phrase rules work on WhatsApp, SMS, Messenger, Instagram, Telegram, LINE and
the website chat. Not on email or calls yet. In the dashboard's test chat a
rule answers but nothing is recorded and nobody is alerted.

## With the API

```bash
curl -s -X POST https://api.omniocto.com/v1/agents/ag-0000000001/phrase-rules \
  -H "Authorization: Bearer $OMNI_KEY" -H "Content-Type: application/json" \
  -d '{
    "name": "Stroke signs",
    "phrases": [
      {"lang": "en", "text": "face is weak on one side"},
      {"lang": "en", "text": "face weak on one side"},
      {"lang": "zh", "text": "半边脸没力"}
    ],
    "reply_text": "This may be a stroke. Please go to the nearest Emergency Department now, or call 995.",
    "replies": {"zh": "这可能是中风。请立即前往最近的急诊部，或拨打995。"},
    "signal_field_key": "clinical_red_flag",
    "red_flag": true
  }'
```

`GET /v1/agents/{id}/phrase-rules` lists them. `PATCH
/v1/agents/{id}/phrase-rules/{rule_id}` changes one (send the `version` you
read as `expected_version`; `enabled: false` switches it off), and `DELETE`
removes it. Writes need an owner or admin key. Every field:
[Lookups reference](/platform-api/reference/lookups/).