Integrate chat support with live WebSocket streaming - #127
Conversation
9e3fdf8 to
2d16be6
Compare
2d16be6 to
89b3a36
Compare
| UserID: userID, | ||
| Username: username, | ||
| Message: EndedSentinel, | ||
| Sender: models.SenderSystem, |
There was a problem hiding this comment.
Shouldn't we have a record of who ended the conversation? the admin or user? Recording it as system, we won't know who ended it.
There was a problem hiding this comment.
This can be taken up as an enhancement.
| {Key: fieldUserID, Value: "$" + fieldUserID}, | ||
| {Key: fieldConversationID, Value: "$" + fieldConversationID}, | ||
| }}, | ||
| {Key: "message_count", Value: bson.D{{Key: "$sum", Value: 1}}}, |
There was a problem hiding this comment.
Can we add a small comment helping us understanding the pipeline. This seems like, it loads one message per conversation when the admin window loads.
|
|
||
| // Sender constants for ChatMessage.Sender. | ||
| const ( | ||
| SenderUser = "user" |
There was a problem hiding this comment.
Just a suggestion, the best way to do this was declaring a type
type SenderType string (you may choose a better name)
then
SenderType User, Admin,System.
It's better coding standards. Thanks!
There was a problem hiding this comment.
Makes sense, changed it, thanks
| // non-fatal: treat as not ended | ||
| } | ||
|
|
||
| history, err := dbCon.GetChatMessages(ctx, userID, conversationID) |
There was a problem hiding this comment.
Please help me understand, does this load all the chat messages at once, or does it load a set of messages as and when we scroll in the frontend UI?
There was a problem hiding this comment.
Currently it loads all the chat messages at once. But it is a good point, as I think when conversation are very long, it might be better to load when user scrolls in UI. Maybe we can take it as a enhacement
| zap.String("userID", userID), | ||
| zap.Int64("conversationID", conversationID), | ||
| zap.Int("history_len", len(history))) | ||
|
|
There was a problem hiding this comment.
Please add a comment explaining incomingFromAdminCh.
| } | ||
|
|
||
| // AdminReplyToConversation inserts an admin message into an existing conversation. | ||
| func (db *MongoDB) AdminReplyToConversation(ctx context.Context, msg *models.ChatMessage) error { |
There was a problem hiding this comment.
Both the InsertChatMessage and AdminReplyToConversation are the same, except for the context that is being passed, we can try combining it, rather than keeping duplicate code
There was a problem hiding this comment.
Right, have modified it, thanks
| // published to, so a single admin WS can receive notifications for all convs. | ||
| const adminBroadcastKey = "admin:broadcast" | ||
|
|
||
| var hub = &chatHub{ |
There was a problem hiding this comment.
I want to understand, why a slice of channels is necessary, let's discuss once. If not required, we can pick it up as an enhancement in a different PR.
|
Added minor comments, certain changes do not impact the functionality, I think the same can be addressed. Others can be taken up incrementally. Thank you for the PR! |
Signed-off-by: Vikas <vikas.satyanarayana.bolla@ibm.com>
89b3a36 to
0531a67
Compare
This PR integrates a real-time chat support system that allows users to contact admins directly from the power-access-cloud UI.