Skip to content

Commit 06a470c

Browse files
committed
fix missing user id in thread
Signed-off-by: Siri Chongasamethaworn <siri@omise.co>
1 parent 65b3985 commit 06a470c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/ui/slack/slack.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ func (s *SlackUI) handleSlackEvents(w http.ResponseWriter, r *http.Request) {
219219
return
220220
}
221221
channel, ts, threadTs, text, userID = ev.Channel, ev.TimeStamp, ev.ThreadTimeStamp, ev.Text, ev.User
222+
223+
// Sometimes user is embedded in other fields or it's a message changed event
224+
if userID == "" && ev.Message != nil {
225+
userID = ev.Message.User
226+
}
227+
if userID == "" {
228+
klog.V(2).Infof("Missing userID in handleSlackEvents: event_type=%s sub_type=%s channel=%s ts=%s", innerEvent.Type, ev.SubType, channel, ts)
229+
}
222230
default:
223231
w.WriteHeader(http.StatusOK)
224232
return
@@ -348,7 +356,7 @@ func (s *SlackUI) processMessage(channel, threadTS, ts, text, userID string) {
348356
}
349357
session, err := s.sessionManager.NewSessionWithID(sessionID, meta)
350358
if err != nil {
351-
klog.Errorf("Failed to create session for Slack: %v", err)
359+
klog.Errorf("Failed to create session for Slack: %v. meta: %+v", err, meta)
352360
return
353361
}
354362
session.Name = "Slack Thread " + effectiveThreadTS
@@ -498,6 +506,9 @@ func (s *SlackUI) postToSlack(channel, threadTS, text string, includeContext boo
498506
)
499507
if err != nil {
500508
klog.Errorf("Failed to post message to Slack: %v", err)
509+
if strings.Contains(err.Error(), "invalid_auth") {
510+
klog.Errorf("SLACK_BOT_TOKEN seems invalid or expired. Please check your environment variables.")
511+
}
501512
// If blocks are invalid, try uploading as snippet instead
502513
if strings.Contains(err.Error(), "invalid_blocks") {
503514
klog.Warningf("Blocks validation failed, uploading as snippet instead")

pkg/ui/slack/slack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func TestHandleSlackEvents_Callback(t *testing.T) {
386386
activeTriggers: make(map[string]string),
387387
}
388388

389-
body := `{"type":"event_callback","event":{"type":"app_mention","channel":"C1","ts":"1.1","text":"hello"}}`
389+
body := `{"type":"event_callback","event":{"type":"app_mention","channel":"C1","ts":"1.1","text":"hello","user":"U1"}}`
390390
ts := fmt.Sprintf("%d", time.Now().Unix())
391391
msg := fmt.Sprintf("v0:%s:%s", ts, body)
392392
h := hmac.New(sha256.New, []byte(signingSecret))

0 commit comments

Comments
 (0)