Skip to content

Enable notification support for the chat messages - #181

Open
vikasbolla wants to merge 1 commit into
IBM:mainfrom
vikasbolla:notify_chat_messages
Open

vikasbolla wants to merge 1 commit into
IBM:mainfrom
vikasbolla:notify_chat_messages

Conversation

@vikasbolla

@vikasbolla vikasbolla commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Backend

New event types (models/events.go)

CHAT_USER_MESSAGE — fired when a user sends a chat message, notifies admin
CHAT_ADMIN_REPLY — fired when admin replies, notifies the user
Chat notification logic (services/chat.go)
  • Admin rate-limit: email is suppressed if an admin has already replied to the conversation within the last 6 hours (HasAdminRepliedSince) — prevents inbox spam on active conversations
  • Unread count: when no admin reply exists, counts unanswered user messages (GetUnreadUserMessageCount) and includes the count in the email body so admin can gauge urgency — "There are 3 unread messages from user X"
  • User notification: no rate-limit — every admin reply triggers an email since the user may not be watching the UI
  • Both goroutines use a bounded context.WithTimeout (30s / 15s) to prevent goroutine leaks on a hung DB

New DB methods (db/interface.go, db/mongodb/chat.go)

HasAdminRepliedSince(ctx, userID, convID, since) — single CountDocuments on sender=admin AND timestamp > since
GetUnreadUserMessageCount(ctx, userID, convID) — counts user messages after the most recent admin message timestamp; returns total if admin has never replied

SendGrid fixes (notifier/client/mail/mail.go)

  • Fixed HTTP 400: admin-only events (NotifyAdmin=true, Notify=false) now use AddTos instead of AddBCCs — SendGrid rejects BCC-only messages

  • Fixed content-type: "text" → "text/plain"

  • Notify() now returns an error on non-202 responses instead of ignoring it

  • MarkEventAsNotified is now only called when Notify succeeds — failed sends are retried on the next poll cycle instead of being permanently lost

Frontend

Timestamp display (components/ChatSupport.jsx, components/ChatAdmin.jsx)

  • Messages from today show time only: 02:45 PM
  • Messages from earlier this year show date + time: Jun 12, 02:45 PM
  • Messages from a previous year show full date: Jun 12, 2024, 02:45 PM

How it works end-to-end

  • User sends a message → notifyAdminOfUserMessage goroutine fires → writes CHAT_USER_MESSAGE event to MongoDB
  • Event-notifier binary picks it up via tailable cursor → calls SendGrid → emails PowerACL@ibm.com
  • Admin replies → notifyUserOfAdminReply goroutine fires → writes CHAT_ADMIN_REPLY event
  • Event-notifier resolves user email from Keycloak → emails the user

Signed-off-by: Vikas <vikas.satyanarayana.bolla@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant