feat(chat): alert on new messages with sound and browser notifications - #492
Open
bamdadd wants to merge 1 commit into
Open
feat(chat): alert on new messages with sound and browser notifications#492bamdadd wants to merge 1 commit into
bamdadd wants to merge 1 commit into
Conversation
Incoming messages only surfaced as an unread badge in the sidebar, so an agent had to actively scan for new chats. Three gaps caused this: - The toast/sound only fired for chats assigned to the current user; unassigned chats bumped the badge silently. - The notification sound was blocked by the browser autoplay policy until the first page interaction, so the very first alert was dropped. - There was no OS-level notification, so a backgrounded tab showed nothing. Now an incoming message alerts when the chat is assigned to you or unassigned (chats owned by another agent stay quiet), the sound is primed on the first user gesture so it plays reliably, and when the tab is backgrounded a real browser Notification (permission requested on first interaction) is shown instead of the in-app toast. The alert decision is extracted into a pure shouldNotifyIncoming helper and covered by unit tests. Adds a minimal Vitest setup (test:unit script) since the repo previously only had Playwright e2e.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Incoming WhatsApp messages now proactively alert the assigned agent with a sound and — when the tab is backgrounded — a native browser notification, instead of only silently incrementing the sidebar unread badge.
Why
Today an incoming message only shows up as a small unread count in the contact list, so an agent has to actively watch the screen to notice a new chat. Three separate gaps caused this:
play()and the sound was dropped.How
shouldNotifyIncoming()helper (frontend/src/services/notifications.ts).pointerdown/keydown(played muted once, then reset) so later alerts play reliably. Browser notification permission is requested in the same gesture.window.Notification(click focuses the window and routes to the chat); otherwise fall back to the existing in-app toast.Tests
shouldNotifyIncomingunit tests cover assigned / unassigned / other-agent / outgoing / already-viewing / alerts-disabled / default-on cases.vitest.config.ts+test:unitscript); the repo previously had only Playwright e2e.npm run test:unit→ 7 passing.npm run typecheckandeslintclean on changed files.Notes