Skip to content
EffizienzAgentPublic

About

Chat history from Beeper for the Frappe Framework

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Chat history from Beeper for the Frappe Framework

chatsync

chatsync is a Frappe v16 app that shows the direct-chat history of your contacts on their Contact and lets you answer from the site. It connects to a self-hosted Beeper Server through its Client API, so WhatsApp, Signal and the other networks Beeper bridges end up in one place.

  • One account per user. Each user adds a Chat Account with the Beeper Server's base URL and a token. Chats and messages are visible only to their owner (see Privacy).
  • Direct chats, and groups by choice. Direct chats are matched and stored automatically; group chats only when you assign one explicitly (see Group chats). A chat merged in Beeper (one person across several networks) is read as its member chats: each member is matched, stored and assigned on its own, with its own network, so a merged Signal + Telegram chat can yield one matched Signal chat and one unassigned Telegram chat. The merged chat itself is never stored.
  • Matching. A direct chat whose counterpart exposes a phone number (typically WhatsApp and Signal) is matched to a contact by that number; all other chats are assigned by hand ("Assign chat" on the Contact). Chats without a matching contact are never stored.
  • Conversations. Chat Sync → Conversations (/desk/chat-view) lists your conversations, newest first, with search. All chats with one contact (WhatsApp, Signal, LinkedIn, …) show as one conversation, each message marked with its network; replies go to the chat chosen next to the input (by default the one the contact last wrote in). Conversations that are done (archived in Beeper) are shown muted; Only open hides them. On small screens list and conversation show one at a time.
  • Open and done. Beeper's archive state is the single source of truth for what is open, kept in sync both ways. Done in the conversation header archives the chat in Beeper (all open chats of the contact), Reopen moves the chat chosen for replies back to the Beeper inbox; both take effect in Beeper at once. Archiving or unarchiving in Beeper shows up with the next sync (every two minutes). Chats without new activity take their state from the chat list pages the sync reads anyway; open chats not on those pages are asked for one by one, each at most every ten minutes and at most 20 per sync. A contact counts as waiting for a reply when the newest message across all its chats came in; group chats are listed as open but never count as waiting (open_chat_counts). A chat that is part of a merged Beeper chat counts as archived with the merged chat, and Done archives the chat itself, which Beeper mirrors to the merged chat. Each chat also keeps its unread count and when the last message came in and went out, so apps can show chats waiting for a reply (chatsync.api.open_assigned_chats, one row per contact, waiting ones first).
  • Reactions. Reactions show as chips under the message (yours highlighted, "You" or the contact's name on hover; shortcodes and custom reactions as text, their images are not loaded). Hovering a message offers 👍 ❤️ 😂 😮 😢 🙏 and removing your own reaction; the other person sees it at once. Reactions of the last two days are updated with every sync.
  • From the contact. The Chat button in the contact's activity opens a quick reply: the latest ten messages of the conversation, a composer with the network to send through, and Open in chat for the full view. When there is no chat yet, it starts a WhatsApp or Signal chat with one of the contact's phone numbers (nothing is sent until you write the first message) and then opens the quick reply.
  • Pictures. People are shown with the contact's image if it has one, else with their Beeper profile picture, else with their initials. Beeper pictures are streamed from the Beeper Server on request, to the chat's owner only, as JPEG, PNG, GIF or WebP checked by their bytes (SVG refused), up to 2 MB; they are never stored, the browser keeps them for a day.
  • Sending. A message is handed to Beeper and shown at once with a clock; the view then asks the Beeper Server for the confirmed message (after 0.5, 1, 2, 4 and 8 seconds) and shows a check mark. A message not confirmed by then appears with the next sync.
  • Chat view. Read the history, play voice notes, view images and download files, send text messages, archive a conversation. Message types the view cannot show (location, contact cards) appear as a placeholder naming the type; stickers show as images. Formatting is shown: HTML from Beeper is sanitized to a small allowlist (paragraphs, bold, italic, lists, quotes, code, http/https/mailto links), plain text gets WhatsApp markup (*bold*, _italic_, ~strike~, `code`, ```mono```), links and line breaks.
  • Images and files. Streamed from the Beeper Server on demand and never stored. Images (JPEG, PNG, GIF, WebP, checked by their bytes) are shown inline, MP4/WebM videos play inline, everything else (SVG included) is offered as a download. Files over 50 MB are not streamed ("open it in Beeper"); seeking in audio and video is passed on to the Beeper Server.
  • Voice notes. Streamed from the Beeper Server on demand and never stored. Transcription on demand through Mistral.
  • Archiving. Optionally save a conversation as a PDF to docarchive. A group is filed under its first party.

Group chats

  • A group chat is never stored by itself. The Unassigned segment (and host apps such as the INOCEA Hub's Heute page) list group chats that are not stored yet, marked with a group icon: "Group · N members · Suggestion: …". Their members are matched to contacts with the same rules as direct chats (identifier, phone number with the contact filter, full name for members without a number); the suggested parties come from the host hook chatsync_group_parties (for example the organizations of the matched contacts, see docs/extending.md).
  • Assign group (chatsync.api.assign_group, browser session only) first loads all participants (chatsync.api.group_for_assignment; list pages carry only some of a large group's), then asks which parties the group belongs to (one or more, e.g. a customer and a partner; suggestions preselected, more can be added; only the host's chatsync_group_party_type when set, never child tables or single DocTypes) and which members to link to their contacts (matched by identifier or phone: preselected; found by full name only: offered unchecked, marked "by name", and only if the contact passes the contact filter). Parties are suggested from identifier and phone matches only. Only then is the group stored, with its parties (Chat Party) and members (Chat Member), and its full history is imported. Members' contacts get no chat identifier rows, so their direct chats match as before.
  • Stored groups sync like direct chats: new messages, edits and deletions of the last two days, reactions and Beeper's archive state. The member list follows Beeper with every sync; a new member is linked only to a readable contact matched by identifier or phone (never by name, never a new contact), members already known keep their link (or none, as chosen).
  • In the chat view a group shows its parties and members in the header (linked contacts are clickable) and the sender's name and picture on each message; replies go to the group with the same guards as direct chats. A contact's conversation and quick reply contain its direct chats only; groups are opened from the chat view or the parties' timelines.
  • Remove group deletes the group and its messages and excludes it, so it is not suggested again (Show ignored still lists it, and assigning it again lifts the exclusion).

Installation

bench get-app https://github.com/EffizienzAgent/chatsync --branch version-16
bench --site <site> install-app chatsync

Compatibility: Frappe v16 (Python 3.14). The version-16 branch always points to the latest release; tagged releases and the changelog are on the releases page.

The install creates the role Chat User. Grant it to everyone who connects an account.

Setup

  1. Run a Beeper Server that your Frappe site can reach, with your chat networks connected. For Docker Compose setups (e.g. frappe_docker) see docs/docker.md: image, service, headless sign-in and security notes.
  2. Get an access token for it. On a headless server, use the beeper CLI against the server: beeper auth email start sends a code to your Beeper e-mail address, beeper auth email response completes the login with that code, and the new device is then verified by comparing emoji with a device that is already logged in. The resulting token is what you enter below.
  3. Open Chat Account and add the user, the server's base URL and the token, tick Enabled. Users with the role Chat User see only their own account.
  4. Optional: Chat Sync Settings sets the phone region for numbers without a country code (default DE), the initial import window in days (default 14) and transcription (below).
  5. Open a contact that has a matching phone number, or use Assign chat on the Contact for other networks, and open the chat view.

The scheduler syncs every two minutes. Token and transcription keys are stored as Frappe passwords.

How chats are matched

  • A chat that is already assigned to a contact stays with it. A manual assignment is stored as a row in the contact's chat identifiers.
  • Otherwise a chat whose counterpart exposes a phone number (typically WhatsApp and Signal) is matched by it: contact numbers and the chat's number are normalised to E.164 with the region from Chat Sync Settings. Exactly one readable contact must match; two matches are ambiguous and left alone.
  • Chats without a phone number, and chats that phone matching does not find, are matched only through stored chat identifiers (the chat ID, or the username or participant ID of a manual assignment). Use Assign chat on the Contact, or create a new contact from an unassigned chat.
  • Unassigning a chat removes its messages and marks the chat as excluded for that contact, so it is not matched again.
  • Unassigned direct chats (chatsync.api.unassigned_chats) can be previewed by their owner (chatsync.api.preview_chat: the newest messages, fetched live from Beeper and not stored; media are named, not loaded; group chats can be previewed too, assigned chats are refused) and ignored (chatsync.api.ignore_chat), for example private chats. Only the chat ID is kept, on the user's Chat Account; an ignored chat no longer shows up there. Host apps may cache the unassigned list: the INOCEA Hub's Heute page keeps it in Redis, titles of ignored chats included, for up to two minutes; for unassigned groups it keeps only the group's ID, title, member count and suggested parties, no member names or numbers. When the chat's number belongs to exactly one readable contact that phone matching skips (see the contact filter), the entry names it as existing_contact, so it can be assigned instead of creating a duplicate.
  • The chat view (/desk/chat-view) has two segments: Conversations (assigned chats) and Unassigned. Unassigned lists the user's direct chats without a contact and group chats not stored yet, regardless of age, live from Beeper and page by page (chatsync.api.unassigned_page, 50 Beeper chats per page, Load more for older ones; a search term uses Beeper's chat search over all ages). Nothing is stored. Clicking an entry previews it with the actions Assign contact, Create contact and Ignore; Show ignored includes ignored chats, which can be brought back with Stop ignoring (chatsync.api.unignore_chat). Entries carry archived (Beeper's archive state) and needs_reply; an unassigned chat can be archived without assigning it (chatsync.api.set_chat_done with beeper_chat_id).
  • Chats without a phone match (LinkedIn, Instagram, Telegram, …) get a suggested_contact when exactly one readable contact has the chat title as its full name (case, diacritics, punctuation and emoji ignored; "Last, First" counts as "First Last"; single words are not suggested). It is a suggestion only: nothing is assigned until the user confirms it.
  • Apps can restrict which contacts qualify for phone matching, see docs/extending.md.

What gets imported:

  • The first sync of a chat takes the last 14 days (Initial Days).
  • Assigning a chat, or adding a new phone number to a contact, imports the full history in the background.
  • Edits and deletions of the last two days are mirrored on every sync.

Privacy

  • Only chats with a matching or assigned contact, and group chats you assigned yourself, are stored. Messages of everything else never reach the database.
  • Chats and messages are visible only to their owner. The exception is the built-in Administrator user, as which the scheduled sync runs. The System Manager role has no bypass; it can manage Chat Accounts but not read other users' chats.
  • The Chat User role can only read chats and messages. Every change (assigning, unassigning, sending, transcribing, archiving) goes through chatsync's own endpoints, and those that change an existing chat are allowed for its owner only.
  • Voice notes, images and files are fetched from the Beeper Server when opened and are not stored (no File record, nothing on disk). Only their name, type and size are saved with the message, and for voice notes the transcript. Messages synced before these details were kept show their first attachment without name and size.
  • Sending, reacting, marking a chat done (archiving it in Beeper), assigning a group and starting a chat from a contact are possible only in a browser session, for the chat's owner. Requests that carry an Authorization header (API keys, OAuth), and requests without the session's CSRF token, are refused, and there is no background or MCP path for them. Starting a chat sends no message.
  • Transcription sends the audio to Mistral (Chat Sync Settings → provider, API key and model). Leave the key empty to switch it off.
  • Archiving needs a docarchive role; the PDF contains the messages of the chosen period, with images and files listed by name, not embedded. Archived PDFs follow docarchive's access rules, not the owner-only rule above.

Extending

Apps can decide which contacts take part in phone matching with the hook chatsync_contact_filter. See docs/extending.md.

Development

bench --site your.site set-config allow_tests true
bench --site your.site run-tests --app chatsync

License

MIT, see LICENSE. Frappe is a trademark of Frappe Technologies and Beeper of its owner; this project is not affiliated with either.

Professional setup & support

Need help setting this up or integrating it into your Frappe stack? Write to oss@effizienzagent.de (English or German). German-speaking SMEs: see mittelstandshub.de.

About

Chat history from Beeper for the Frappe Framework

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages