Developers
Self-hosting the central API
Run the whole platform yourself. Everything is optional except a public URL; missing services fall back to safe practice modes.
For developersOn this page
Running it
The API is one Node.js process with a SQLite database. It also serves the dashboard (/app), the widget (/w.js), these docs (/docs) and the landing page (/). It needs Node 24.
For development, from the repository:
npm install
cd apps/api
PUBLIC_URL=http://localhost:8100 npx tsx src/index.tsFor production, build everything from the repository root with npm run build, then run the API's built server.mjs with your settings in the environment (or in a .env file in its working folder, which is read on start).
On shutdown (SIGTERM) it stops taking new work and waits up to 2 minutes for live phone calls to finish.
Settings
Every setting is an environment variable. Paths are relative to the folder the API runs in.
Core
| Variable | Default | What it does |
|---|---|---|
PUBLIC_URL | http://localhost:8100 | The address people and services reach the API at. Links in messages, Stripe returns and the phone company's webhooks all use it (Twilio's signatures are checked against it), so it must match exactly. An https:// address also turns on secure cookies. |
PORT | 8100 | Port to listen on |
HOST | 127.0.0.1 | Address to listen on |
NODE_ENV | development | Set production in production |
DATA_DIR | ./data | Database, uploads, site versions, backups and generated secrets |
DB_FILE | <DATA_DIR>/jagg.db | The SQLite database |
APP_SECRET | generated | Secret for hashing visitor addresses and signing internal tokens. Generated once into <DATA_DIR>/app-secret if not set. Keep it stable: changing it drops phone calls in progress and restarts the day's visitor count. |
ADMIN_EMAIL | none | The account with this email becomes the operator, with access to the admin tools, once it opens the sign-in link emailed at sign-up (and only while there's no operator yet). Then set up two-step sign-in |
TRUST_PROXY | false | Set true behind a proxy, so client addresses come from CF-Connecting-IP or X-Forwarded-For. Rate limits depend on it. |
DEV_ORIGINS | http://localhost:5173 | Extra origins allowed to make signed-in dashboard requests, comma-separated. For a dashboard dev server. |
Hosted sites and domains
| Variable | Default | What it does |
|---|---|---|
SITES_DOMAIN | localhost | Hosted sites live at <slug>.<SITES_DOMAIN> |
SITES_SCHEME | https if PUBLIC_URL is https, else http | Scheme used in hosted-site links |
SITES_PORT | empty for https, else 8200 | Port used in hosted-site links |
CUSTOM_DOMAIN_TARGET | <slug>.<SITES_DOMAIN> | The CNAME target shown to owners for custom domains |
CLOUDFLARE_API_TOKEN, CLOUDFLARE_ZONE_ID | none | When set, custom domains are registered as Cloudflare custom hostnames |
AI
| Variable | Default | What it does |
|---|---|---|
OPENROUTER_API_KEY | none | Without it, the built-in practice AI answers instead |
OPENROUTER_BASE_URL | https://openrouter.ai/api/v1 | Any OpenAI-compatible chat completions endpoint with tool calling and streaming |
AI_MODEL_CHAT | anthropic/claude-haiku-5.5 | Web chat and texts |
AI_MODEL_VOICE | anthropic/claude-haiku-5.5 | Phone calls |
AI_MODEL_ASSISTANT | anthropic/claude-haiku-5.5 | The owner's assistant in the dashboard |
AI_FAKE | false | Force the practice AI even with a key, for tests and demos |
| Variable | Default | What it does |
|---|---|---|
SES_SMTP_USER, SES_SMTP_PASSWORD | none | Send email through Amazon SES (the main service): its SMTP credentials. See Email through Amazon SES. |
SES_REGION | us-east-1 | The SES region the domain is verified in |
TWILIO_EMAIL | false | Send email through Twilio Email, as a backup, with the same TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN. The domain must be verified in the Twilio console (Email, Domains). |
SENDGRID_API_KEY | none | Send email through Twilio SendGrid, as a backup |
SMTP_URL | none | Send email through any SMTP server, like smtps://user:[email protected]:465, as a backup |
EMAIL_PROVIDERS | every one that's set up: ses,twilio,sendgrid,smtp | The order to try them in, comma-separated, for example ses,smtp. Services that are set up but not listed are tried after the listed ones. Other names are ignored. |
MAIL_FROM | Just a Good Guy <hello@localhost> | The From address. Customer emails keep this address but show the business's name, with Reply-To set to the business's own email. |
INBOUND_EMAIL_DOMAIN | none | The domain customers email receptionists at: each business gets <slug>@<this domain> |
INBOUND_EMAIL_SECRET | none | A long random string in the Inbound Parse webhook URL. Inbound email is off unless this and the domain are both set. |
TWILIO_EMAIL_API_BASE, SENDGRID_API_BASE | the services' own | For testing against a fake |
With none of the email services set up, emails are written to <DATA_DIR>/dev-mail instead of sent (Admin, Logs, Dev mail).
More than one email service
Set up two, and email keeps working when one has a bad day. Each email goes to the first service in EMAIL_PROVIDERS. When it fails (it's down, too slow, over its limit, or refusing your domain or key), the next one sends it, and the server log says so. When a service says the address itself is wrong, no other service is tried and the email isn't retried. The message log (Admin, Logs) shows which service sent each email.
A failed email or text is tried again after 1 minute, then 5 and 15 minutes, then 1, 3, 6, 12 and 24 hours (about two days in all). Codes, sign-in links and reminders that would arrive too late are skipped instead, with the reason in the message log. When something can't be sent in the end, the operator gets an email (or a text to the phone on their account, when no email can go out), at most once an hour. An owner's alert email that can't go out is sent to them by text instead.
Admin, Integrations shows how each service is doing: one row per service (AI, the phone company, phone numbers, calls, texts, email out and in, Stripe, Cloudflare, Turnstile, notifications and the server itself) with what its last check found. Test everything runs every check that only reads (nothing is sent to anyone); the server also runs them every hour and emails you when one stops working. Tests that send something are inside their rows and say what they cost first: a test email, a test text, Call my phone (a short call that reads a test greeting) and an email sent around the loop (out through the email service, back in through Cloudflare) to prove email in works end to end.
The receptionist only promises an email when one can go out: when every email service has failed three times in a row in the last half hour, it stops promising emails until one works again. Mail already queued keeps being retried.
Email through Amazon SES
Amazon SES costs about 10 to 16 cents per 1,000 emails, with no monthly fee. One-time setup in the AWS console, in the region in SES_REGION:
- Domain. Under Identities, Create identity, choose Domain and enter the domain in
MAIL_FROM(for examplejustagoodguy.us). Add the three DKIM CNAME records it shows to your DNS. The identity turns Verified within minutes once they're in. - SMTP credentials. Under SMTP settings, Create SMTP credentials. Put the username and password in
SES_SMTP_USERandSES_SMTP_PASSWORD. (These aren't your AWS sign-in.) - Production access. A new SES account only sends to addresses verified in it. Under Account dashboard, Request production access, describe the mail: transactional booking confirmations, reminders and replies for small businesses, sent only to their own customers. AWS usually answers within a day.
Until step 3 is done, SES refuses mail to everyone else ("Email address is not verified"), and the next email service in EMAIL_PROVIDERS sends it instead. Admin, Integrations, Email out, shows what SES said last.
Email through Twilio SendGrid
One-time setup in SendGrid:
- API key. Create one under Settings, API Keys with Mail Send access. Put it in
SENDGRID_API_KEY. - Sender. Under Settings, Sender Authentication, authenticate the domain in
MAIL_FROM(for examplejustagoodguy.us): add the DNS records SendGrid shows, then verify. Until a domain or single sender is verified, SendGrid refuses to send, and the outbox shows that error. - Customers emailing receptionists (optional). Pick a subdomain you don't use for your own mail, like
mail.justagoodguy.us. Add an MX record for it pointing atmx.sendgrid.net(priority 10). Under Settings, Inbound Parse, add that subdomain with the URLPUBLIC_URL/api/webhooks/email/<INBOUND_EMAIL_SECRET>. Leave "POST the raw, full MIME message" off; turning on the spam check is a good idea. Then setINBOUND_EMAIL_DOMAINandINBOUND_EMAIL_SECRET.
Each business's address then shows in its Inbox. Owners forward their business email there, and the receptionist answers. See Email.
Phone and texts (Telnyx)
| Variable | Default | What it does |
|---|---|---|
TELNYX_API_KEY | none | The phone company for calls, texts and numbers. Without it (or Twilio's keys), texts are logged instead of sent and numbers are practice ones. |
TELNYX_PUBLIC_KEY | none | Telnyx's webhook signing key (portal, Keys & Credentials, Public Key). Signed webhooks are checked against it. Every webhook URL also carries a secret of ours, so webhooks are refused without it either way. |
TELNYX_FROM | none | A verified toll-free number on the account for the platform's own texts (owner alerts). Or pick one in Admin, Numbers. |
TELNYX_API_BASE | https://api.telnyx.com | For testing against a fake |
With the key set, the server sets up the Telnyx account by itself the first time it needs to: a TeXML application for every number's calls (pointed at PUBLIC_URL/api/telnyx/voice), a messaging profile for every number's texts (PUBLIC_URL/api/telnyx/sms) and an outbound voice profile so calls can ring owners' phones (US and Canada). All three are named "Just a Good Guy"; a new PUBLIC_URL re-points them. Admin, Integrations, Phone company, shows the balance and whether they're ready.
Calls use Telnyx's Conversation Relay over the WebSocket at PUBLIC_URL/api/voice/relay: Telnyx turns speech into text and back, our receptionist decides what to say. The receptionist's voice is the closest Amazon Polly voice to the one the owner picked.
Business numbers are toll-free on Telnyx, bought by themselves when a business goes live with a phone number on its plan. A toll-free number's texting verification is free (a local number needs paid 10DLC carrier registration), so each business's texts are verified with its details automatically (see texting registration). Calls work straight away; texts go out once the verification is approved.
There's no backup yet for when this server is down: calls and texts to business numbers don't get through until it's back. WhatsApp isn't offered.
Phone and texts with Twilio instead
Twilio's keys are used only when TELNYX_API_KEY isn't set.
| Variable | Default | What it does |
|---|---|---|
TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN | none | Without them (and without Telnyx), texts are logged instead of sent, number search returns practice numbers, and signature checks are skipped |
TWILIO_FROM | none | Fallback sender for texts not sent from a business's own number |
TWILIO_MESSAGING_SERVICE_SID | none | Send those texts through a Messaging Service instead (used before TWILIO_FROM) |
TWILIO_API_BASE | https://api.twilio.com | For testing against a fake |
TWILIO_PRIMARY_CUSTOMER_PROFILE_SID | found automatically | Your approved Primary Business Profile in Trust Hub (BU...), needed to register businesses for texting. See texting registration |
TWILIO_A2P_EMAIL | the support email, then ADMIN_EMAIL | Where Twilio sends notices about each business's texting registration |
TWILIO_A2P_MOCK | false | Register free mock brands that can't send, for a dry run |
TWILIO_TRUSTHUB_BASE, TWILIO_MESSAGING_BASE | Twilio's | For testing against a fake |
TWILIO_VOICE_FALLBACK_URL | none | Where Twilio sends calls when this server doesn't answer: a TwiML Bin (see below). Set on every business number automatically. |
TWILIO_SMS_FALLBACK_URL | none | The same for texts |
Numbers bought through the dashboard are pointed at PUBLIC_URL/api/twilio/voice, /api/twilio/voice/status and /api/twilio/sms automatically. Calls use Twilio ConversationRelay over a WebSocket at PUBLIC_URL/api/voice/relay.
When this server is down
If the server or its tunnel is down, Twilio gets no answer and callers hear an error. Two TwiML Bins in the Twilio console fix that. Twilio serves them itself, so they work while you're down. Make each one under Develop, TwiML Bins, then put its URL (https://handler.twilio.com/twiml/EH...) in the setting and restart. Shortly after the restart every business number is pointed at them (and kept up to date every hour), with the business's name (Business) and the owner's phone (Ring) added to the URL.
TWILIO_VOICE_FALLBACK_URL: puts callers through to the owner's phone, or asks them to call back when there's no phone to ring (or the call was forwarded from the owner's own line, so it doesn't loop):
<?xml version="1.0" encoding="UTF-8"?>
<Response>
{{#ForwardedFrom}}<Say>Thanks for calling {{Business}}. We can't take your call right now. Please call back a little later.</Say>{{/ForwardedFrom}}
{{^ForwardedFrom}}
{{#Ring}}<Say>Thanks for calling {{Business}}. One moment while we put you through.</Say><Dial timeout="30">{{Ring}}</Dial>{{/Ring}}
{{^Ring}}<Say>Thanks for calling {{Business}}. We can't take your call right now. Please call back a little later.</Say>{{/Ring}}
{{/ForwardedFrom}}
</Response>TWILIO_SMS_FALLBACK_URL: passes the text on to the owner's phone and tells the customer:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
{{#Ring}}<Message to="{{Ring}}">{{Business}}: a text from {{From}} came in while your receptionist was offline: {{Body}}</Message><Message>Thanks for texting {{Business}}. We got your message and will get back to you soon.</Message>{{/Ring}}
{{^Ring}}<Message>Thanks for texting {{Business}}. We can't answer texts for a little while. Please try again later.</Message>{{/Ring}}
</Response>Texts that arrive while the server is down don't reach the inbox; only the owner's phone and Twilio's message logs have them. If the receptionist fails partway through a call, the caller is told what happens next (a text with a booking link when one can go out) and the owner gets a missed-call alert. Admin, Settings shows whether Twilio can reach the call WebSocket right now.
Billing (Stripe)
Stripe is only used to bill businesses for their plan, add-ons and charges.
| Variable | Default | What it does |
|---|---|---|
STRIPE_SECRET_KEY | none | Without it, billing is off and every account stays fully on |
STRIPE_WEBHOOK_SECRET | none | Signing secret for PUBLIC_URL/api/webhooks/stripe (subscriptions and usage: checkout.session.completed, customer.subscription.*, invoice.paid, invoice.payment_failed) |
STRIPE_PUBLISHABLE_KEY | none | The pk_... key from the same Stripe account. With it and STRIPE_MANAGED_PAYMENTS=off, owners pay in the dashboard's own payment form (only the card fields come from Stripe). Otherwise they're sent to Stripe's checkout page and back |
STRIPE_MANAGED_PAYMENTS | on | on: follow the Stripe account's Managed Payments setting. off: turn Managed Payments off for every checkout, so you are the merchant of record (see below) |
Stripe events are deduplicated, and subscriptions are re-checked against Stripe every hour in case a webhook was missed.
For Apple Pay and Google Pay in the payment form, add the dashboard's domain (the host of PUBLIC_URL) in the Stripe Dashboard under Settings, Payment method domains. Cards work without it.
Managed Payments
Stripe Managed Payments makes Stripe the merchant of record: Stripe charges and pays the sales tax on what businesses buy from you. New Stripe accounts can have it on by default, in test and live mode. Two things follow from it:
- Every product needs a tax category. The add-ons (phone number, texting) and the monthly fee are sent with the category "Software as a service (SaaS) - business use" (
txcd_10103001): when an owner sets up card payments, Stripe makes the product and the monthly price from their plan's monthly fee, so there's nothing to set up in Stripe first. Only a Stripe price ID you type in yourself (Advanced, on a plan or a business's plan) points at a product made in Stripe, so set the tax code on that product: Product catalog, the product, Tax code. Admin, Integrations, Payments (Stripe) lists any such product that's missing one. - It only works with Stripe's checkout page. The dashboard's own payment form isn't allowed, so owners go to Stripe's page even when
STRIPE_PUBLISHABLE_KEYis set.
Setting STRIPE_MANAGED_PAYMENTS=off turns it off for our checkouts. That makes you the merchant of record, responsible for sales tax yourself, so decide that with whoever does your taxes. If Stripe still refuses the payment form, the checkout falls back to Stripe's page by itself and the server logs a warning.
Plans and usage bills
Admin, Plans lists every plan a business can be on. The Standard plan is the default plan: everyone you haven't moved is on it. Make as many others as you like: pay as you go (per call minute, per text, per booking), monthly, or monthly with some use included. Each plan shows its prices beside what each unit costs you, what you keep and the markup, and what a typical month (200 call minutes, 300 texts, 40 bookings) takes in, costs and leaves. Set a price directly, or type a markup and the price follows. What it costs you on the same page holds your own cost per minute, text, booking and phone number; change it when your bills change.
- Owners can pick it puts a plan on owners' Plan and billing page; turned off, only you can put a business on it (on its page, Their plan, then the plan's row). Retire a plan to stop new businesses getting it (those on it stay); delete one nobody is on.
- Anything you set for one business alone stays on top of whichever plan they're on.
- Switching bills the month's usage so far at the old plan's prices first. With card payments running, the subscription's price changes (prorated) and a free plan keeps a $0 card payment, so that last usage is still charged. Without card payments, an owner adds a card first when the new plan charges anything; your own moves apply at once.
- Usage bills are made hourly for each finished month (
runUsageBilling). With card payments, each line becomes an invoice item on the subscription (with the bill's id as its idempotency key) and is charged with the next payment;invoice.paid/invoice.payment_failedmark it. Without, it's due: the owner pays on Stripe's checkout, or you mark it paid or let it go on their page. Bills under 50¢ are carried to the next one. Nothing from before the month usage billing first ran is billed. - Spending limit: owners can cap their usage charges a month. When they reach it, calls and texts the receptionist would charge for stop until the 1st, and they're emailed once.
Charges
On a business's admin page, Charges bills them for anything besides their plan: one time, monthly or yearly. Each charge is a Stripe checkout with its own price (nothing to set up in the Stripe Dashboard), on the business's Stripe customer, with kind: charge and the charge's id in its metadata. The owner gets an email with a link to Plan and billing (never a raw Stripe link) and pays there. Without Stripe, owners see "We'll send you a payment link" and you mark charges paid by hand (cash, check), which also works with Stripe.
What a charge is for sets its tax category:
| What it is | Stripe tax code | With Managed Payments on |
|---|---|---|
| Software or add-on | txcd_10103001 SaaS, business use | Sold |
| Website hosting | txcd_10701100 Website hosting | Sold |
| Website design or build | txcd_10701200 Website design | Refused before anything reaches Stripe: Managed Payments only sells fully automated digital products, not work done by a person |
To bill design or build work by card, either bill it as software (only if that's honest), or set STRIPE_MANAGED_PAYMENTS=off and handle sales tax yourself (Stripe Tax can help). The app never turns Managed Payments off on its own. If Stripe refuses a charge for any other reason, the operator sees Stripe's reason.
A charge can change the business automatically: when it's paid, if it isn't paid by its pay-by time, and for monthly or yearly ones if payments stop (7 days of failed payments, or the subscription ending in Stripe). The changes are set up with the normal screens ("Set up changes"; saves there are kept for later, not made) and only the settings that were changed are applied, on top of whatever is there then. Missed deadlines are checked every 5 minutes, and charge subscriptions are re-read from Stripe every hour. To take bank payments through Stripe, also send checkout.session.async_payment_succeeded to the webhook.
Other
| Variable | Default | What it does |
|---|---|---|
VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY | generated | Web push keys. Generated once into <DATA_DIR>/vapid.json if not set. |
VAPID_SUBJECT | mailto:hello@localhost | Contact for push services |
TURNSTILE_SITE_KEY, TURNSTILE_SECRET | none | Cloudflare Turnstile. When both are set, a visitor sending more than 15 chat messages in 10 minutes from one address is asked for a quick person check (once an hour). Normal visitors never see it. |
DASHBOARD_DIR | ../dashboard/dist | Built dashboard |
WIDGET_DIR | ../widget/dist | Built widget |
DOCS_DIR | ../../docs/dist | Built docs |
SITE_DIR | ../../site | Landing page |
Behind a proxy
If you put nginx or similar in front:
- Turn response buffering off and allow long reads. Chat replies stream as Server-Sent Events, the host app long-polls for up to 50 seconds, and dashboard live updates stay open.
- Pass WebSocket upgrades through, for phone calls at
/api/voice/relay. - Allow request bodies of at least 9 MB. Site uploads arrive in 8 MB pieces.
- Set
TRUST_PROXY=true, and make sure the proxy setsX-Forwarded-For(orCF-Connecting-IPbehind Cloudflare).
Data and backups
Everything lives in DATA_DIR. A copy of the database is written to <DATA_DIR>/backups once a day (around 08:00 UTC), and the last 7 are kept. Copy that folder somewhere else as well.
Housekeeping runs on its own: expired sessions and codes are removed, and raw analytics events older than 18 months are deleted.