From 3cb463e99a20bc956bb06707e291c5f846491b89 Mon Sep 17 00:00:00 2001 From: tyler Date: Fri, 19 Jan 2024 14:04:00 -0500 Subject: [PATCH] Handled issue when chat message is sent by user not channel --- chat.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/chat.go b/chat.go index 922a52d..3002602 100644 --- a/chat.go +++ b/chat.go @@ -232,6 +232,18 @@ type ChatEvent struct { Type string `json:"type"` } +type ChatEventDataFix struct { + Channels [][]string `json:"channels"` + Messages []ChatEventMessage `json:"messages"` + Users []ChatEventUser `json:"users"` +} + +type ChatEventFix struct { + Data ChatEventDataFix `json:"data"` + RequestID string `json:"request_id"` + Type string `json:"type"` +} + func (c *Client) StartChatStream(handle func(cv ChatView), handleError func(err error)) error { c.chatStreamMu.Lock() defer c.chatStreamMu.Unlock() @@ -305,7 +317,14 @@ func parseEvent(event []byte) ([]ChatView, error) { var ce ChatEvent err := json.Unmarshal(event, &ce) if err != nil { - return nil, fmt.Errorf("error un-marshaling event: %v", err) + var cef ChatEventFix + errFix := json.Unmarshal(event, &cef) + if errFix != nil { + return nil, fmt.Errorf("error un-marshaling event: %v", err) + } + + ce.Data.Messages = cef.Data.Messages + ce.Data.Users = cef.Data.Users } users := chatUsers(ce.Data.Users)