Skip to content

Commit d2d5523

Browse files
committed
fix: rename sms field
1 parent 0e7309a commit d2d5523

File tree

7 files changed

+43
-43
lines changed

7 files changed

+43
-43
lines changed

api/routes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ func (h handler) sendMessage(c echo.Context) error {
3939
return echo.NewHTTPError(http.StatusBadRequest, "invalid payload")
4040
}
4141

42-
logger.Debug().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.SMSTo).Msg("processing send message request")
43-
logger.Debug().Str("endpoint", "send_message").Str("raw_from", req.From).Str("raw_to", req.SMSTo).Msg("raw identifiers for recipient resolution")
42+
logger.Debug().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.To).Msg("processing send message request")
43+
logger.Debug().Str("endpoint", "send_message").Str("raw_from", req.From).Str("raw_to", req.To).Msg("raw identifiers for recipient resolution")
4444

4545
resp, err := h.svc.SendMessage(c.Request().Context(), &req)
4646
if err != nil {
47-
logger.Error().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.SMSTo).Err(err).Msg("failed to send message")
47+
logger.Error().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.To).Err(err).Msg("failed to send message")
4848
// Add extra context to help debugging recipient resolution
49-
logger.Debug().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.SMSTo).Msg("send_message handler returning error to client; check mapping store and AS configuration")
49+
logger.Debug().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.To).Msg("send_message handler returning error to client; check mapping store and AS configuration")
5050
return mapServiceError(err)
5151
}
5252

53-
logger.Info().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.SMSTo).Str("sms_id", resp.SMSID).Msg("message sent successfully")
53+
logger.Info().Str("endpoint", "send_message").Str("from", req.From).Str("to", req.To).Str("sms_id", resp.SMSID).Msg("message sent successfully")
5454
return c.JSON(http.StatusOK, resp)
5555
}
5656

docs/DEPLOY_NS8.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ After the above logins, you can send a message from giacomo to mario:
131131
```
132132
curl -s -X POST https://synapse.gs.nethserver.net/m2a/api/client/send_message -H "Content-Type: application/json" -d '{
133133
"from": "@giacomo:synapse.gs.nethserver.net",
134-
"sms_to": "@mario:synapse.gs.nethserver.net",
135-
"sms_body": "Hello Mario — this is Giacomo (curl test)",
134+
"to": "@mario:synapse.gs.nethserver.net",
135+
"body": "Hello Mario — this is Giacomo (curl test)",
136136
"content_type": "text/plain"
137137
}'
138138
```
@@ -146,8 +146,8 @@ Mario reply:
146146
```
147147
curl -s -X POST https://synapse.gs.nethserver.net/m2a/api/client/send_message -H "Content-Type: application/json" -d '{
148148
"from": "@mario:synapse.gs.nethserver.net",
149-
"sms_to": "@giacomo:synapse.gs.nethserver.net",
150-
"sms_body": "Hello Giacomo — this is Mario reply (curl test)",
149+
"to": "@giacomo:synapse.gs.nethserver.net",
150+
"body": "Hello Giacomo — this is Mario reply (curl test)",
151151
"content_type": "text/plain"
152152
}'
153153
```
@@ -180,8 +180,8 @@ Send message using mapped SMS number (91201) - Giacomo to Mario:
180180
```
181181
curl -s -X POST https://synapse.gs.nethserver.net/m2a/api/client/send_message -H "Content-Type: application/json" -d '{
182182
"from": "@giacomo:synapse.gs.nethserver.net",
183-
"sms_to": "91202",
184-
"sms_body": "Hello Mario — this is Giacomo (curl test using mapped number)",
183+
"to": "91202",
184+
"body": "Hello Mario — this is Giacomo (curl test using mapped number)",
185185
"content_type": "text/plain"
186186
}'
187187
```
@@ -190,8 +190,8 @@ Send message using mapped SMS number (91202) - Mario to Giacomo:
190190
```
191191
curl -s -X POST https://synapse.gs.nethserver.net/m2a/api/client/send_message -H "Content-Type: application/json" -d '{
192192
"from": "@mario:synapse.gs.nethserver.net",
193-
"sms_to": "91201",
194-
"sms_body": "Hello Giacomo — this is Mario reply (curl test using mapped number)",
193+
"to": "91201",
194+
"body": "Hello Giacomo — this is Mario reply (curl test using mapped number)",
195195
"content_type": "text/plain"
196196
}'
197197
```
@@ -200,8 +200,8 @@ Send message using mapped numbers - Giacomo to Mario:
200200
```
201201
curl -s -X POST https://synapse.gs.nethserver.net/m2a/api/client/send_message -H "Content-Type: application/json" -d '{
202202
"from": "91201",
203-
"sms_to": "91202",
204-
"sms_body": "Hello Mario — this is Giacomo (curl test using both mapped numbers)",
203+
"to": "91202",
204+
"body": "Hello Mario — this is Giacomo (curl test using both mapped numbers)",
205205
"content_type": "text/plain"
206206
}'
207207
```

docs/openapi.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ paths:
7171
type: object
7272
required:
7373
- from
74-
- sms_to
75-
- sms_body
74+
- to
75+
- body
7676
properties:
7777
from:
7878
type: string
7979
description: The sender - either a full Matrix ID (e.g., @user:server.com) or a phone number (e.g., +1234567890).
8080
password:
8181
type: string
8282
description: This field is ignored. Kept for client compatibility.
83-
sms_to:
83+
to:
8484
type: string
8585
description: Recipient Matrix ID, Alias, or mapped phone number.
86-
sms_body:
86+
body:
8787
type: string
8888
description: The message content.
8989
content_type:

main_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ func TestIntegration_SendAndFetchMessages(t *testing.T) {
365365
// Step 1: Send message from USER1 to USER2
366366
t.Run("SendMessage", func(t *testing.T) {
367367
sendReq := models.SendMessageRequest{
368-
From: user1MatrixID,
369-
SMSTo: user2MatrixID, // Send directly to user2's Matrix ID to create a DM
370-
SMSBody: fmt.Sprintf("Hello from integration test %d", time.Now().Unix()),
368+
From: user1MatrixID,
369+
To: user2MatrixID, // Send directly to user2's Matrix ID to create a DM
370+
Body: fmt.Sprintf("Hello from integration test %d", time.Now().Unix()),
371371
}
372372

373373
resp, body, err := doRequest("POST", baseURL+"/api/client/send_message", sendReq, nil)
@@ -593,7 +593,7 @@ func attemptMappingsAndRetrySend(t *testing.T, baseURL, adminToken string, origS
593593
// First attempt: try common variants for the From field (phone numbers)
594594
fromVariants := generateMappingVariants(origSendReq.From)
595595
for _, fv := range fromVariants {
596-
_, err := ensureMappingVariants(t, baseURL, adminToken, fv, origSendReq.From, origSendReq.SMSTo)
596+
_, err := ensureMappingVariants(t, baseURL, adminToken, fv, origSendReq.From, origSendReq.To)
597597
if err == nil {
598598
// Retry send with the same original request (server will resolve mapping)
599599
resp, body, err := doRequest("POST", baseURL+"/api/client/send_message", origSendReq, nil)
@@ -608,9 +608,9 @@ func attemptMappingsAndRetrySend(t *testing.T, baseURL, adminToken string, origS
608608

609609
// Try mapping localpart@server variants for the recipient if it's not a Matrix ID
610610
// (covers earlier cases where the identifier might be localpart-only)
611-
if !strings.HasPrefix(origSendReq.SMSTo, "@") {
612-
candidate := fmt.Sprintf("@%s:%s", getLocalpart(origSendReq.SMSTo), strings.Split(strings.TrimPrefix(origSendReq.SMSTo, "@"), ":")[0])
613-
_, err := ensureMappingVariants(t, baseURL, adminToken, origSendReq.SMSTo, candidate, origSendReq.SMSTo)
611+
if !strings.HasPrefix(origSendReq.To, "@") {
612+
candidate := fmt.Sprintf("@%s:%s", getLocalpart(origSendReq.To), strings.Split(strings.TrimPrefix(origSendReq.To, "@"), ":")[0])
613+
_, err := ensureMappingVariants(t, baseURL, adminToken, origSendReq.To, candidate, origSendReq.To)
614614
if err == nil {
615615
resp, body, err := doRequest("POST", baseURL+"/api/client/send_message", origSendReq, nil)
616616
return resp, body, err
@@ -674,9 +674,9 @@ func TestIntegration_SendMessageWithPhoneNumberMapping(t *testing.T) {
674674

675675
// Step 4: Send a message using the phone number as the 'from' field
676676
sendReq := models.SendMessageRequest{
677-
From: phoneNumber, // Using phone number instead of Matrix ID
678-
SMSTo: string(roomID),
679-
SMSBody: fmt.Sprintf("Message from phone number %d", time.Now().Unix()),
677+
From: phoneNumber, // Using phone number instead of Matrix ID
678+
To: string(roomID),
679+
Body: fmt.Sprintf("Message from phone number %d", time.Now().Unix()),
680680
}
681681
resp, body, err := doRequest("POST", baseURL+"/api/client/send_message", sendReq, nil)
682682
if err != nil {
@@ -769,9 +769,9 @@ func TestIntegration_RoomMessaging(t *testing.T) {
769769

770770
// Step 3: User1 sends a message to the room
771771
sendReq1 := models.SendMessageRequest{
772-
From: user1MatrixID,
773-
SMSTo: string(roomID), // Send to room ID
774-
SMSBody: fmt.Sprintf("Hello from user1 %d", time.Now().Unix()),
772+
From: user1MatrixID,
773+
To: string(roomID), // Send to room ID
774+
Body: fmt.Sprintf("Hello from user1 %d", time.Now().Unix()),
775775
}
776776
resp, body, err := doRequest("POST", baseURL+"/api/client/send_message", sendReq1, nil)
777777
if err != nil {
@@ -795,9 +795,9 @@ func TestIntegration_RoomMessaging(t *testing.T) {
795795

796796
// Step 4: User2 sends a message to the room
797797
sendReq2 := models.SendMessageRequest{
798-
From: user2MatrixID,
799-
SMSTo: string(roomID), // Send to room ID
800-
SMSBody: fmt.Sprintf("Hello from user2 %d", time.Now().Unix()),
798+
From: user2MatrixID,
799+
To: string(roomID), // Send to room ID
800+
Body: fmt.Sprintf("Hello from user2 %d", time.Now().Unix()),
801801
}
802802
resp, body, err = doRequest("POST", baseURL+"/api/client/send_message", sendReq2, nil)
803803
if err != nil {

models/messages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package models
44
type SendMessageRequest struct {
55
From string `json:"from"`
66
Password string `json:"password"`
7-
SMSTo string `json:"sms_to"`
8-
SMSBody string `json:"sms_body"`
7+
To string `json:"to"`
8+
Body string `json:"body"`
99
ContentType string `json:"content_type"`
1010
DispositionNotification string `json:"disposition_notification"`
1111
}

models/models_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func TestSendMessageRequest_Marshal(t *testing.T) {
1111
req := SendMessageRequest{
1212
From: "@user:example.com",
1313
Password: "secret",
14-
SMSTo: "@recipient:example.com",
15-
SMSBody: "Hello World",
14+
To: "@recipient:example.com",
15+
Body: "Hello World",
1616
ContentType: "text/plain",
1717
}
1818

@@ -25,8 +25,8 @@ func TestSendMessageRequest_Marshal(t *testing.T) {
2525
err = json.Unmarshal(data, &req2)
2626
assert.NoError(t, err)
2727
assert.Equal(t, req.From, req2.From)
28-
assert.Equal(t, req.SMSTo, req2.SMSTo)
29-
assert.Equal(t, req.SMSBody, req2.SMSBody)
28+
assert.Equal(t, req.To, req2.To)
29+
assert.Equal(t, req.Body, req2.Body)
3030
}
3131

3232
func TestFetchMessagesRequest_Marshal(t *testing.T) {

service/messages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *MessageService) SendMessage(ctx context.Context, req *models.SendMessag
6767
return nil, ErrInvalidSender
6868
}
6969

70-
recipientStr := strings.TrimSpace(req.SMSTo)
70+
recipientStr := strings.TrimSpace(req.To)
7171
if recipientStr == "" {
7272
logger.Warn().Msg("send message: empty recipient")
7373
return nil, ErrInvalidRecipient
@@ -107,7 +107,7 @@ func (s *MessageService) SendMessage(ctx context.Context, req *models.SendMessag
107107

108108
content := &event.MessageEventContent{
109109
MsgType: event.MsgText,
110-
Body: req.SMSBody,
110+
Body: req.Body,
111111
}
112112

113113
resp, err := s.matrixClient.SendMessage(ctx, sender, roomID, content)

0 commit comments

Comments
 (0)