Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ A chat button for your website, a team inbox on the web, iPhone and Android that
- **Team inbox.** In the same eleven languages. Live replies, internal notes, files, statuses, priorities, assignment and tags, across several workspaces.
- **WhatsApp, Facebook Messenger and Instagram.** Connect a website's WhatsApp Business number or Facebook Page, and customers' messages arrive in the same inbox as website chats, with the same assignment, notes and tags. Replies show when they were delivered and read, and the AI assistant can answer there too. Instagram customers get through once the business's Meta app has passed Meta's App Review ([known issues](docs/known-issues.md#instagram)).
- **The OpenChat app** for [iPhone](https://apps.apple.com/app/id6833420293) and [Android](https://play.google.com/store/apps/details?id=com.orangolabs.openchat), with notifications end-to-end encrypted to each phone, so the relay that carries them cannot read them. The app and the relay are not open source, but your installation works with them.
- **Replies by email.** A reply a website visitor has not read is emailed to them, so leaving the page does not lose the answer. A supervisor can turn it off.
- **Replies by email.** A reply a website visitor has not read is emailed to them, so leaving the page does not lose the answer, and with a reply address set up they can answer from their mail app, back into the same conversation. A supervisor can turn it off.
- **Follow-up emails**, only with the visitor's consent, with an unsubscribe link.
- **An AI assistant that answers first**, if you turn it on. It answers visitors from your website's pages and texts you give it, and from answers it learns from your team's resolved conversations once a supervisor approves them. It hands over to a person when it cannot answer, or the visitor asks for one, and every answer is labelled AI. It runs on Workers AI in your own Cloudflare account.
- **A help centre**: articles your visitors read and search on a public page and in the widget, with views and "Was this helpful?" counts. The AI assistant answers from them too.
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const de: Messages = {
whatsappIntro: 'Verbinden Sie die WhatsApp-Business-Nummer dieser Website. Kunden, die ihr schreiben, landen in Ihrem Posteingang, mit dem Assistenten, der Übersetzung und den Öffnungszeiten dieser Website.',
whatsappPreview: 'Kundinnen und Kunden, die dieser Nummer schreiben, landen in Ihrem Posteingang, und Sie können bis 24 Stunden nach ihrer letzten Nachricht auf WhatsApp antworten. Sie zuerst anzuschreiben, mit Metas Nachrichtenvorlagen, ist noch nicht möglich.',
onWhatsApp: 'Auf WhatsApp',
byEmail: 'Per E-Mail gesendet',
byEmailFrom: 'Per E-Mail gesendet, von {address}',
emailFilesNotKept: 'Anhänge, die nicht gespeichert werden konnten: {count}',
whatsappMediaPending: 'Datei wird von WhatsApp geladen…',
whatsappMediaFailed: 'Es wurde eine Datei gesendet, die OpenChat nicht speichern konnte. Sie ist in WhatsApp zu sehen.',
whatsappReaction: 'Hat auf eine Nachricht reagiert',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ export const en = {
whatsappIntro: 'Connect this website’s WhatsApp Business number. Customers who write to it reach your inbox, with this website’s assistant, translation and opening hours.',
whatsappPreview: 'Customers who write to this number reach your inbox, and you can reply on WhatsApp for 24 hours after their last message. Writing to them first, with Meta’s message templates, is not available yet.',
onWhatsApp: 'On WhatsApp',
byEmail: 'Sent by email',
byEmailFrom: 'Sent by email, from {address}',
emailFilesNotKept: 'Attachments that could not be kept: {count}',
whatsappMediaPending: 'Fetching the file from WhatsApp…',
whatsappMediaFailed: 'A file was sent that OpenChat could not keep. You can see it in WhatsApp.',
whatsappReaction: 'Reacted to a message',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const es: Messages = {
whatsappIntro: 'Conecta el número de WhatsApp Business de este sitio web. Los clientes que le escriban llegarán a tu bandeja de entrada, con el asistente, la traducción y el horario de este sitio.',
whatsappPreview: 'Los clientes que escriben a este número llegan a tu bandeja de entrada, y puedes responderles por WhatsApp durante las 24 horas posteriores a su último mensaje. Escribirles primero, con las plantillas de mensajes de Meta, aún no está disponible.',
onWhatsApp: 'En WhatsApp',
byEmail: 'Enviado por correo',
byEmailFrom: 'Enviado por correo, desde {address}',
emailFilesNotKept: 'Adjuntos que no se pudieron guardar: {count}',
whatsappMediaPending: 'Descargando el archivo de WhatsApp…',
whatsappMediaFailed: 'Se envió un archivo que OpenChat no pudo guardar. Puedes verlo en WhatsApp.',
whatsappReaction: 'Reaccionó a un mensaje',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const fr: Messages = {
whatsappIntro: 'Connectez le numéro WhatsApp Business de ce site. Les clients qui lui écrivent arrivent dans votre boîte de réception, avec l’assistant, la traduction et les horaires de ce site.',
whatsappPreview: 'Les clients qui écrivent à ce numéro arrivent dans votre boîte de réception, et vous pouvez leur répondre sur WhatsApp pendant 24 heures après leur dernier message. Leur écrire en premier, avec les modèles de message de Meta, n’est pas encore possible.',
onWhatsApp: 'Sur WhatsApp',
byEmail: 'Envoyé par e-mail',
byEmailFrom: 'Envoyé par e-mail, depuis {address}',
emailFilesNotKept: 'Pièces jointes non conservées : {count}',
whatsappMediaPending: 'Récupération du fichier depuis WhatsApp…',
whatsappMediaFailed: 'Un fichier a été envoyé, mais OpenChat n’a pas pu le conserver. Vous pouvez le voir dans WhatsApp.',
whatsappReaction: 'A réagi à un message',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const it: Messages = {
whatsappIntro: 'Collega il numero WhatsApp Business di questo sito. I clienti che gli scrivono arrivano nella tua casella, con l’assistente, la traduzione e gli orari di questo sito.',
whatsappPreview: 'I clienti che scrivono a questo numero arrivano nella tua casella, e puoi rispondere su WhatsApp entro 24 ore dal loro ultimo messaggio. Scrivere per primi, con i modelli di messaggio di Meta, non è ancora disponibile.',
onWhatsApp: 'Su WhatsApp',
byEmail: 'Inviato via email',
byEmailFrom: 'Inviato via email, da {address}',
emailFilesNotKept: 'Allegati che non è stato possibile conservare: {count}',
whatsappMediaPending: 'Recupero del file da WhatsApp…',
whatsappMediaFailed: 'È stato inviato un file che OpenChat non ha potuto conservare. Puoi vederlo in WhatsApp.',
whatsappReaction: 'Ha reagito a un messaggio',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const ja: Messages = {
whatsappIntro: 'このウェブサイトの WhatsApp Business 番号を接続します。この番号にメッセージを送った顧客は、このウェブサイトのアシスタント、翻訳、営業時間とともに受信トレイに届きます。',
whatsappPreview: 'この番号にメッセージを送ったお客様は受信箱に届き、最後のメッセージから24時間以内であればWhatsAppで返信できます。Metaのメッセージテンプレートを使ってこちらから先に送ることは、まだできません。',
onWhatsApp: 'WhatsApp から',
byEmail: 'メールで送信',
byEmailFrom: 'メールで送信(送信元: {address})',
emailFilesNotKept: '保存できなかった添付ファイル: {count}',
whatsappMediaPending: 'WhatsApp からファイルを取得しています…',
whatsappMediaFailed: 'OpenChat で保存できなかったファイルが送信されました。WhatsApp で確認できます。',
whatsappReaction: 'メッセージにリアクションしました',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const ko: Messages = {
whatsappIntro: '이 웹사이트의 WhatsApp Business 번호를 연결합니다. 이 번호로 메시지를 보낸 고객은 이 웹사이트의 어시스턴트, 번역, 운영 시간과 함께 받은편지함에 표시됩니다.',
whatsappPreview: '이 번호로 메시지를 보낸 고객은 받은편지함에 표시되며, 고객의 마지막 메시지 후 24시간 동안 WhatsApp으로 답장할 수 있습니다. Meta의 메시지 템플릿으로 먼저 연락하는 기능은 아직 제공되지 않습니다.',
onWhatsApp: 'WhatsApp에서',
byEmail: '이메일로 보냄',
byEmailFrom: '이메일로 보냄 (보낸 주소: {address})',
emailFilesNotKept: '보관하지 못한 첨부 파일: {count}',
whatsappMediaPending: 'WhatsApp에서 파일을 가져오는 중…',
whatsappMediaFailed: 'OpenChat이 보관할 수 없는 파일이 전송되었습니다. WhatsApp에서 확인할 수 있습니다.',
whatsappReaction: '메시지에 반응함',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const nl: Messages = {
whatsappIntro: 'Koppel het WhatsApp Business-nummer van deze website. Klanten die het een bericht sturen komen in je inbox, met de assistent, vertaling en openingstijden van deze website.',
whatsappPreview: 'Klanten die dit nummer een bericht sturen, komen in je inbox, en je kunt tot 24 uur na hun laatste bericht via WhatsApp antwoorden. Hen als eerste schrijven, met de berichtsjablonen van Meta, is nog niet mogelijk.',
onWhatsApp: 'Op WhatsApp',
byEmail: 'Verzonden per e-mail',
byEmailFrom: 'Verzonden per e-mail, vanaf {address}',
emailFilesNotKept: 'Bijlagen die niet bewaard konden worden: {count}',
whatsappMediaPending: 'Bestand ophalen van WhatsApp…',
whatsappMediaFailed: 'Er is een bestand gestuurd dat OpenChat niet kon bewaren. Je kunt het in WhatsApp zien.',
whatsappReaction: 'Heeft op een bericht gereageerd',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const pt: Messages = {
whatsappIntro: 'Conecte o número do WhatsApp Business deste site. Os clientes que escreverem para ele chegam à sua caixa de entrada, com o assistente, a tradução e o horário deste site.',
whatsappPreview: 'Os clientes que escrevem para este número chegam à sua caixa de entrada, e você pode responder pelo WhatsApp por 24 horas após a última mensagem deles. Escrever primeiro, com os modelos de mensagem da Meta, ainda não está disponível.',
onWhatsApp: 'No WhatsApp',
byEmail: 'Enviado por e-mail',
byEmailFrom: 'Enviado por e-mail, de {address}',
emailFilesNotKept: 'Anexos que não puderam ser guardados: {count}',
whatsappMediaPending: 'Buscando o arquivo no WhatsApp…',
whatsappMediaFailed: 'Foi enviado um arquivo que o OpenChat não conseguiu guardar. Você pode vê-lo no WhatsApp.',
whatsappReaction: 'Reagiu a uma mensagem',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const zhHans: Messages = {
whatsappIntro: '连接此网站的 WhatsApp Business 号码。给该号码发消息的客户会进入你的收件箱,并使用此网站的助手、翻译和营业时间。',
whatsappPreview: '给此号码发消息的客户会进入你的收件箱,你可以在客户最后一条消息后的 24 小时内通过 WhatsApp 回复。使用 Meta 消息模板主动联系客户的功能尚未提供。',
onWhatsApp: '来自 WhatsApp',
byEmail: '通过电子邮件发送',
byEmailFrom: '通过电子邮件发送,来自 {address}',
emailFilesNotKept: '未能保存的附件:{count}',
whatsappMediaPending: '正在从 WhatsApp 获取文件…',
whatsappMediaFailed: '对方发送了一个 OpenChat 无法保存的文件。你可以在 WhatsApp 中查看。',
whatsappReaction: '对一条消息做出了回应',
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/src/i18n/zh-hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export const zhHant: Messages = {
whatsappIntro: '連接此網站的 WhatsApp Business 號碼。傳訊息給該號碼的客戶會進入你的收件匣,並使用此網站的助理、翻譯和營業時間。',
whatsappPreview: '傳訊息到此號碼的客戶會進入你的收件匣,你可以在客戶最後一則訊息後的 24 小時內透過 WhatsApp 回覆。使用 Meta 訊息範本主動聯絡客戶的功能尚未提供。',
onWhatsApp: '來自 WhatsApp',
byEmail: '透過電子郵件傳送',
byEmailFrom: '透過電子郵件傳送,來自 {address}',
emailFilesNotKept: '未能保存的附件:{count}',
whatsappMediaPending: '正在從 WhatsApp 取得檔案…',
whatsappMediaFailed: '對方傳送了一個 OpenChat 無法保存的檔案。你可以在 WhatsApp 中查看。',
whatsappReaction: '對一則訊息做出了回應',
Expand Down
11 changes: 11 additions & 0 deletions apps/dashboard/src/inbox/inbox-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ function MessageBubble({ workspaceId, message, translation, instagram = false }:
message.content && <div className="break-words whitespace-pre-wrap">{message.content}</div>
)}
{message.attachments.map((file) => <AttachmentView key={file.id} file={file} />)}
{message.email && <EmailNote state={message.email} />}
{message.whatsapp && <WhatsAppNote state={message.whatsapp} />}
{message.messenger && (instagram ? <InstagramNote state={message.messenger} /> : <MessengerNote state={message.messenger} />)}
{message.whatsapp?.delivery && <ReplyDelivery workspaceId={workspaceId} message={message} channel="whatsapp" />}
Expand All @@ -535,6 +536,16 @@ function MessageBubble({ workspaceId, message, translation, instagram = false }:
}

/** What a WhatsApp message holds that is not shown here (ADR-0026): a file on its way or not kept, or something only WhatsApp shows. */
/** A visitor's answer to a reply email (ADR-0029). The address is shown only when it is not the contact's own. */
function EmailNote({ state }: { state: NonNullable<Message['email']> }) {
return (
<p className="mt-1 text-xs italic opacity-85">
{state.from ? t('byEmailFrom', { address: state.from }) : t('byEmail')}
{state.filesNotKept ? ` · ${t('emailFilesNotKept', { count: state.filesNotKept })}` : ''}
</p>
);
}

function WhatsAppNote({ state }: { state: NonNullable<Message['whatsapp']> }) {
const text =
state.media === 'pending'
Expand Down
12 changes: 11 additions & 1 deletion docs/architecture/background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Three queues plus DLQs, not one per job type. Few queues keep self-hosted setup
|---|---|---|---|---|---|
| `oc-notifications` | `notification.fanout`, `notification.dispatch`, `notification.unregister` | 25 | 1 s | 8 | 20 |
| `oc-email` | `email.follow_up`, `email.reply_check`, `auth.password_reset_email`, `auth.new_account_email` | 10 | 5 s | 8 | 5 |
| `oc-jobs` | `whatsapp.media`, `whatsapp.send`, `messenger.media`, `messenger.profile`, `messenger.send`, `attachment.process`, `assistant.index_source`, `help.draft`, `help.draft_article`, `help.index_article`, `automation.evaluate`, `webhook.deliver` (later), `workspace.purge`, `analytics.rollup` | 10 | 5 s | 5 | 10 |
| `oc-jobs` | `email.inbound`, `whatsapp.media`, `whatsapp.send`, `messenger.media`, `messenger.profile`, `messenger.send`, `attachment.process`, `assistant.index_source`, `help.draft`, `help.draft_article`, `help.index_article`, `automation.evaluate`, `webhook.deliver` (later), `workspace.purge`, `analytics.rollup` | 10 | 5 s | 5 | 10 |
| `*-dlq` | All of the above | 25 | 30 s | 3 | 1 |

Email jobs hold IDs only and read the address when sending. System email (`auth.password_reset_email`, `auth.new_account_email`) has no delivery row, because the token is created at send time. Each attempt has a new token and so a new provider idempotency key. A crash after sending can deliver two emails, and failures of any kind retry and then dead-letter.
Expand Down Expand Up @@ -93,6 +93,7 @@ Exactly-once is impossible for external effects, so each consumer aims for the n
| `notification.unregister` | Removing nothing still succeeds at the relay | None |
| `email.follow_up` | Unique `email_deliveries (workspace_id, dedupe_key)`: claim, send, mark sent. A row marked `failed` can be claimed again by a retry | Two. A crash between send and mark leaves the row `claimed`, and nothing sends again, because a missed email is better than a duplicate. An answer lost after Cloudflare accepted the send marks it `failed`, and the retry sends twice, because Cloudflare documents no idempotency key |
| `email.reply_check` | The same claim in `email_deliveries`, keyed by the conversation and the last reply the email carries. `conversations.reply_emailed_seq` then moves forward and never back | As `email.follow_up` |
| `email.inbound` | Unique `messages (workspace_id, conversation_id, client_message_id)`, from the reply token and the email's `Message-ID`. Attachment IDs are made from the same, so a repeat overwrites the same objects | None |
| `automation.evaluate` | Unique `automation_runs (workspace_id, rule_id, conversation_id, trigger_key)`. A repeat queues `email.follow_up` again, in case a crash came before it, and the claim there keeps it to one | None for the decision |
| `whatsapp.media` | The file's attachment ID and storage key come from the message, and only a message whose file is still `pending` takes it. A second run finds it attached and stops | None |
| `messenger.media` | As `whatsapp.media`, under `messenger.media` in the message's metadata | None |
Expand Down Expand Up @@ -261,6 +262,15 @@ Nothing here knows about browsers or sockets, so a disconnect alone triggers not

Here a socket does count, but only towards when. Whether an email is sent at all is decided by the read cursor, which is in D1. `email.follow_up` skips a conversation whose `reply_emailed_seq` has reached its last public message.

### Answers by email

Step 2, on an installation with `REPLY_EMAIL_ADDRESS`. Sending makes a token for each reply email, stores its hash in `conversation_reply_addresses`, and sets Reply-To to `reply+<token>@…`.

1. The Worker's `email` handler finds the token in the address the email was sent to, and its conversation. It refuses with `setReject` an unknown address, an email over 10 MiB, and a token's 31st email in an hour. It drops automatic email without an answer.
2. It writes the raw email to R2 under `email-in/` and queues `email.inbound` on `oc-jobs`, with the key and the token's hash. It returns only after both, so that a failure of either is a temporary failure to the sending server, which tries again.
3. The job parses the email with `postal-mime`, stores its attachments under IDs made from the token, the email's `Message-ID` and each one's place, and writes the visitor's message in one batch, with a client message ID made from the token and the `Message-ID`. A redelivered email and a retried job therefore find the message and write nothing ([rule 7](../../AGENTS.md#rules-that-are-easy-to-break)).
4. It dispatches the conversation's outbox, as a webhook does, so the inbox, push, the assistant and translation follow as for any visitor message. Then it deletes the stored email. A job that keeps failing leaves the email for a replay from the failed-jobs page, until the lifecycle rule removes it after 7 days. A replay after that finds nothing and does nothing.

Rule edits take effect at the next evaluation. A new rule, or a threshold that shrinks, reaches a conversation only after its next public message or its next scheduled check. That is acceptable, and the rule editor says so.

Follow-ups use one fixed template, in `packages/core/src/email-templates.ts`, with no message text. Its link goes to the website's first allowed origin.
Expand Down
Loading
Loading