Skip to content

Commit 050d3af

Browse files
committed
fix: add auto join for messages
1 parent 6518fca commit 050d3af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

service/messages.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func (s *MessageService) SendMessage(ctx context.Context, req *models.SendMessag
7878

7979
logger.Debug().Str("user_id", string(userID)).Str("room_id", string(roomID)).Msg("sending message to room")
8080

81+
// Ensure the sender is a member of the room
82+
_, err = s.matrixClient.JoinRoom(ctx, userID, roomID)
83+
if err != nil {
84+
logger.Error().Str("user_id", string(userID)).Str("room_id", string(roomID)).Err(err).Msg("failed to join room")
85+
return nil, fmt.Errorf("send message: %w", err)
86+
}
87+
8188
content := &event.MessageEventContent{
8289
MsgType: event.MsgText,
8390
Body: req.SMSBody,
@@ -326,7 +333,7 @@ func mapAuthErr(err error) error {
326333
if errors.Is(err, ErrAuthentication) {
327334
return err
328335
}
329-
if errors.Is(err, mautrix.MUnknownToken) || errors.Is(err, mautrix.MMissingToken) || errors.Is(err, mautrix.MForbidden) {
336+
if errors.Is(err, mautrix.MUnknownToken) || errors.Is(err, mautrix.MMissingToken) {
330337
return fmt.Errorf("%w", ErrAuthentication)
331338
}
332339
return err

0 commit comments

Comments
 (0)