`subteam_members_changed` Message Results In A `EventTypeErrorBadMessage` Event
What happened
When receiving a message in socketmode for subteam_members_changed
, it results in a EventTypeErrorBadMessage
EventType with an empty cause
field. This unexpected behavior occurs due to an issue unmarshalling the inner event.
Expected behavior
The expected behavior is to receive a SubteamMembersChangedEvent
event. However, the current implementation fails to achieve this, leading to a EventTypeErrorBadMessage
event.
Steps to reproduce
To reproduce this issue, follow these steps:
- Create a socketmode client.
- Attempt to process a
EventTypeEventsAPI
message in response tosubteam_members_changed
.
The underlying error
The underlying error lies in the unmarshalling of the inner event. Specifically, the error message cannot unmarshal number into Go struct field SubteamMembersChangedEvent.added_users_count of type string
indicates that the added_users_count
field is being unmarshalled as a string instead of an integer.
Reproducible code
The following code snippet demonstrates the issue:
func (e *EventHandler) Run(ctx context.Context) error {
log := logger.Sugar()
errg, ctx := errgroup.WithContext(ctx)
errg.Go(func() error {
for evt := range e.socket.Events {
// log.Debugw("event", "event", evt)
switch evt.Type {
case socketmode.EventTypeEventsAPI:
e.handleEventsAPIEvent(ctx, &evt, e.socket)
case socketmode.EventTypeErrorBadMessage:
// THIS WILL CATCH THE MESSAGE
log.Debugw("bad message", "event", evt)
default:
log.Debugw("unsupported event type", "event", evt)
}
}
return nil
})
errg.Go(func() error {
err := e.socket.RunContext(ctx)
if err != nil {
log.Errorw("socket run failed", "error", err)
}
return err
})
return errg.Wait()
}
Manifest.yaml
The following versions are affected by this issue:
- Go: 1.24
- slack-go/slack: 0.15.0, 0.16.0, 0.17.0-rc2 (and likely more)
Proposed fix
To resolve this issue, update the SubteamMembersChangedEvent
struct to utilize an int
instead of a string
type for the added_users_count
and removed_users_count
fields. The updated struct should resemble the following:
type SubteamMembersChangedEvent struct {
Type string `json:"type"`
SubteamID string `json:"subteam_id"`
TeamID string `json:"team_id"`
DatePreviousUpdate int `json:"date_previous_update"`
DateUpdate int64 `json:"date_update"`
AddedUsers []string `json:"added_users"`
AddedUsersCount int `json:"added_users_count"`
RemovedUsers []string `json:"removed_users"`
RemovedUsersCount int `json:"removed_users_count"`
}
Q: What is the subteam_members_changed
message in Socketmode?
A: The subteam_members_changed
message is an event sent by Slack to indicate that the membership of a subteam has changed. This event is part of the Socketmode API, which allows developers to receive real-time updates from Slack.
Q: What is the expected behavior when receiving the subteam_members_changed
message?
A: The expected behavior is to receive a SubteamMembersChangedEvent
event, which contains information about the subteam membership change, such as the added and removed users.
Q: What is the issue with the current implementation?
A: The current implementation fails to correctly unmarshal the SubteamMembersChangedEvent
event, resulting in a EventTypeErrorBadMessage
event with an empty cause
field. This is due to the added_users_count
and removed_users_count
fields being unmarshalled as strings instead of integers.
Q: How can I reproduce the issue?
A: To reproduce the issue, create a socketmode client and attempt to process a EventTypeEventsAPI
message in response to subteam_members_changed
.
Q: What is the proposed fix for the issue?
A: The proposed fix is to update the SubteamMembersChangedEvent
struct to utilize an int
instead of a string
type for the added_users_count
and removed_users_count
fields.
Q: Why is the added_users_count
and removed_users_count
fields being unmarshalled as strings?
A: The added_users_count
and removed_users_count
fields are being unmarshalled as strings because the SubteamMembersChangedEvent
struct is defined with these fields as string
types. This is causing the unmarshalling process to fail, resulting in the EventTypeErrorBadMessage
event.
Q: How can I update the SubteamMembersChangedEvent
struct to fix the issue?
A: To update the SubteamMembersChangedEvent
struct, change the type of the added_users_count
and removed_users_count
fields from string
to int
. This will ensure that these fields are correctly unmarshalled as integers, resolving the EventTypeErrorBadMessage
event issue.
Q: What are the affected versions of the Slack Go library?
A: The affected versions of the Slack Go library are:
- Go: 1.24
- slack-go/slack: 0.15.0, 0.16.0, 0.17.0-rc2 (and likely more)
Q: How can I verify that the issue is fixed?
A: To verify that the issue is fixed, update the SubteamMembersChangedEvent
struct to utilize an int
instead of a string
type for the added_users_count
and removed_users_count
fields. Then, attempt to process a EventTypeEventsAPI
message in response to subteam_members_changed
using a socketmode client. If the issue is fixed, you should receive a SubteamMembersChangedEvent
event with the correct information.