safechat

SafeChat

SafeChat

International Chat Safety Protocol

Open-source crisis safety infrastructure for AI apps.
Detects distress, finds local help. Zero tracking. Works offline.

34 countries · 100+ verified helplines · 205 safety tests · 0 permissions

Live Site · Get Help Now · Community · FAMTEC


SafeChat Homepage     Crisis Popup


What is SafeChat?

SafeChat is an international register and toolkit for chat safety protocol. Free for everyone. Built for developers, health professionals, and communities.


Install as App (PWA)

SafeChat works as a standalone app on any device:

Open the popup: rob-e-graham.github.io/safechat/app/popup.html


Quick Start

Browser (no build step)

<script src="https://cdn.jsdelivr.net/gh/rob-e-graham/safechat@main/src/browser.js"></script>
<script>
  Safechat.protect(); // auto-monitor all text inputs
</script>

One-line embed

<script src="https://cdn.jsdelivr.net/gh/rob-e-graham/safechat@main/src/embed.js"
        data-safechat-monitor="true"></script>

Node.js / npm

npm install safechat
const safechat = require('safechat');

const safety = safechat.check(userMessage);

if (safety.level === 'high') {
  systemPrompt = safechat.promptOverride('high', safety.country)
                 + '\n\n' + systemPrompt;
}

Express middleware

const safechat = require('safechat');
app.use(safechat.middleware());

app.post('/api/chat', (req, res) => {
  const safety = req.safechat.check(req.body.message);
  if (safety.action === 'crisis_intervention') {
    systemPrompt = req.safechat.promptOverride(safety.level) + '\n\n' + systemPrompt;
  }
});

Embed the popup

<iframe src="https://rob-e-graham.github.io/safechat/app/popup.html"
        style="width:100%;max-width:480px;height:700px;border:none;border-radius:16px;">
</iframe>

How Detection Works

How Safechat Works

Detection uses regex pattern matching with three layers:

  1. Input normalisation — Smart quotes → ASCII, whitespace collapse, misspelling correction, text-speak expansion
  2. Pattern matching — HIGH signals (explicit suicidal language, methods) and LOW signals (hopelessness, worthlessness)
  3. False-positive guards — Context-aware filtering skips figurative language (“cut my hair”, “suicide squeeze play”, “overdosed on coffee”)
Level Triggers Action
high Suicidal ideation, self-harm, explicit intent Show crisis resources immediately
low Hopelessness, worthlessness, feeling trapped Soft safety response with helpline link
none No crisis signals Normal operation

Geo-Detection

Geo-Detection Cascade

SafeChat finds the user’s country without location permissions:

Priority Method Permissions
1 Browser locale (navigator.language) None
2 Timezone (Intl.DateTimeFormat) None
3 CDN headers (CF-IPCountry, X-Vercel-IP-Country) None
4 Accept-Language header None
5 Manual override None
6 Global fallback (findahelpline.com) None

Auto-Updating Crisis Data

Fallback Chain

1. jsDelivr CDN (latest data)           ← primary
2. GitHub raw (same data, different CDN) ← if jsDelivr down
3. localStorage cache                    ← if offline
4. Inline emergency numbers              ← if never loaded

Verification workflow runs twice monthly to check all phone numbers and URLs.


Security

SafeChat is designed for trust:


API

safechat.check(text, options?)

safechat.check("I can't go on anymore", { country: "AU" });
// { level: "low", matched: "can't go on", country: "AU", action: "soft_warning", resources: {...} }

safechat.detect(text)

safechat.detect("I want to kill myself")  // { level: "high", matched: "kill myself" }
safechat.detect("I feel worthless")       // { level: "low", matched: "worthless" }
safechat.detect("great day today")        // { level: "none", matched: null }

safechat.promptOverride(level, countryCode)

safechat.getResources(countryCode, options?)

safechat.middleware()


Countries Covered

Australia, Austria, Belgium, Brazil, Canada, China, Denmark, Finland, France, Germany, Ghana, Hong Kong, India, Ireland, Israel, Italy, Japan, Kenya, Mexico, Netherlands, New Zealand, Nigeria, Norway, Pakistan, Philippines, Portugal, Russia, South Africa, South Korea, Spain, Sweden, Switzerland, United Kingdom, United States.

Plus global fallback via findahelpline.com (175+ countries).


Licensing

SafeChat uses Business Source License (BSL 1.1).

Free for:

Commercial entities over $100K must obtain a commercial license: rob@fineartmedia.tech

Changes to MPL 2.0 on 2029-01-01.


SafeChat is provided as is. It is not emergency medical care, legal advice, professional mental health treatment, or a substitute for emergency services, clinicians, safeguarding teams, or local crisis procedures.

By downloading, installing, deploying, integrating, or using SafeChat, you accept responsibility for your own installation, configuration, compliance, testing, supervision, and use. To the maximum extent permitted by law, Rob Graham, FAMTEC, contributors, maintainers, copyright holders, and licensors are not liable for damages, losses, legal claims, regulatory penalties, system damage, data loss, personal injury, death, failure to obtain help, failure to detect crisis content, unlawful use, or other harm arising from installation or use.

If you do not accept these terms, do not download, install, deploy, integrate, or use SafeChat. See LICENSE for the full disclaimer and limitation of liability.


Support the Project


Contributing

Help keep crisis resources accurate and expand to more countries. See CONTRIBUTING.md.

This project follows Samaritans safe messaging guidelines.


Community


Created by Rob Graham / FAMTEC

If you or someone you know is in crisis: findahelpline.com