Skip to content

Commit 578c0de

Browse files
AchoArnoldCopilot
andcommitted
feat: add attachment fields to request, params, and event structs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 22fcb13 commit 578c0de

3 files changed

Lines changed: 56 additions & 24 deletions

File tree

api/pkg/events/message_phone_received_event.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const EventTypeMessagePhoneReceived = "message.phone.received"
1313

1414
// MessagePhoneReceivedPayload is the payload of the EventTypeMessagePhoneReceived event
1515
type MessagePhoneReceivedPayload struct {
16-
MessageID uuid.UUID `json:"message_id"`
17-
UserID entities.UserID `json:"user_id"`
18-
Owner string `json:"owner"`
19-
Encrypted bool `json:"encrypted"`
20-
Contact string `json:"contact"`
21-
Timestamp time.Time `json:"timestamp"`
22-
Content string `json:"content"`
23-
SIM entities.SIM `json:"sim"`
16+
MessageID uuid.UUID `json:"message_id"`
17+
UserID entities.UserID `json:"user_id"`
18+
Owner string `json:"owner"`
19+
Encrypted bool `json:"encrypted"`
20+
Contact string `json:"contact"`
21+
Timestamp time.Time `json:"timestamp"`
22+
Content string `json:"content"`
23+
SIM entities.SIM `json:"sim"`
24+
Attachments []string `json:"attachments"`
2425
}

api/pkg/requests/message_receive_request.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import (
1111
"github.com/NdoleStudio/httpsms/pkg/services"
1212
)
1313

14+
// MessageAttachment represents a single MMS attachment in a receive request
15+
type MessageAttachment struct {
16+
// Name is the original filename of the attachment
17+
Name string `json:"name" example:"photo.jpg"`
18+
// ContentType is the MIME type of the attachment
19+
ContentType string `json:"content_type" example:"image/jpeg"`
20+
// Content is the base64-encoded attachment data
21+
Content string `json:"content" example:"base64data..."`
22+
}
23+
1424
// MessageReceive is the payload for sending and SMS message
1525
type MessageReceive struct {
1626
request
@@ -23,6 +33,8 @@ type MessageReceive struct {
2333
SIM entities.SIM `json:"sim" example:"SIM1"`
2434
// Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible
2535
Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
36+
// Attachments is the list of MMS attachments received with the message
37+
Attachments []MessageAttachment `json:"attachments"`
2638
}
2739

2840
// Sanitize sets defaults to MessageReceive
@@ -38,14 +50,25 @@ func (input *MessageReceive) Sanitize() MessageReceive {
3850
// ToMessageReceiveParams converts MessageReceive to services.MessageReceiveParams
3951
func (input *MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) *services.MessageReceiveParams {
4052
phone, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION)
53+
54+
attachments := make([]services.ServiceAttachment, len(input.Attachments))
55+
for i, a := range input.Attachments {
56+
attachments[i] = services.ServiceAttachment{
57+
Name: a.Name,
58+
ContentType: a.ContentType,
59+
Content: a.Content,
60+
}
61+
}
62+
4163
return &services.MessageReceiveParams{
42-
Source: source,
43-
Contact: input.From,
44-
UserID: userID,
45-
Timestamp: input.Timestamp,
46-
Encrypted: input.Encrypted,
47-
Owner: *phone,
48-
Content: input.Content,
49-
SIM: input.SIM,
64+
Source: source,
65+
Contact: input.From,
66+
UserID: userID,
67+
Timestamp: input.Timestamp,
68+
Encrypted: input.Encrypted,
69+
Owner: *phone,
70+
Content: input.Content,
71+
SIM: input.SIM,
72+
Attachments: attachments,
5073
}
5174
}

api/pkg/services/message_service.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ import (
1919
"github.com/NdoleStudio/httpsms/pkg/telemetry"
2020
)
2121

22+
// ServiceAttachment represents attachment data passed to the service layer
23+
type ServiceAttachment struct {
24+
Name string
25+
ContentType string
26+
Content string // base64-encoded
27+
}
28+
2229
// MessageService is handles message requests
2330
type MessageService struct {
2431
service
@@ -289,14 +296,15 @@ func (service *MessageService) StoreEvent(ctx context.Context, message *entities
289296

290297
// MessageReceiveParams parameters registering a message event
291298
type MessageReceiveParams struct {
292-
Contact string
293-
UserID entities.UserID
294-
Owner phonenumbers.PhoneNumber
295-
Content string
296-
SIM entities.SIM
297-
Timestamp time.Time
298-
Encrypted bool
299-
Source string
299+
Contact string
300+
UserID entities.UserID
301+
Owner phonenumbers.PhoneNumber
302+
Content string
303+
SIM entities.SIM
304+
Timestamp time.Time
305+
Encrypted bool
306+
Source string
307+
Attachments []ServiceAttachment
300308
}
301309

302310
// ReceiveMessage handles message received by a mobile phone

0 commit comments

Comments
 (0)