Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Added Attachments to APISentPayload & send request

Jake Daynes09cf30b4812b
diff --git a/api/pkg/events/message_api_sent_event.go b/api/pkg/events/message_api_sent_event.go
index 7abea843..9aeabd90 100644
--- a/api/pkg/events/message_api_sent_event.go
+++ b/api/pkg/events/message_api_sent_event.go
@@ -13,15 +13,16 @@ const EventTypeMessageAPISent = "message.api.sent"
// MessageAPISentPayload is the payload of the EventTypeMessageSent event
type MessageAPISentPayload struct {
- MessageID uuid.UUID `json:"message_id"`
- UserID entities.UserID `json:"user_id"`
- Owner string `json:"owner"`
- RequestID *string `json:"request_id"`
- MaxSendAttempts uint `json:"max_send_attempts"`
- Contact string `json:"contact"`
- ScheduledSendTime *time.Time `json:"scheduled_send_time"`
- RequestReceivedAt time.Time `json:"request_received_at"`
- Content string `json:"content"`
- Encrypted bool `json:"encrypted"`
- SIM entities.SIM `json:"sim"`
+ MessageID uuid.UUID `json:"message_id"`
+ UserID entities.UserID `json:"user_id"`
+ Owner string `json:"owner"`
+ RequestID *string `json:"request_id"`
+ MaxSendAttempts uint `json:"max_send_attempts"`
+ Contact string `json:"contact"`
+ ScheduledSendTime *time.Time `json:"scheduled_send_time"`
+ RequestReceivedAt time.Time `json:"request_received_at"`
+ Content string `json:"content"`
+ Attachments []entities.MessageAttachment `json:"attachments"`
+ Encrypted bool `json:"encrypted"`
+ SIM entities.SIM `json:"sim"`
}
diff --git a/api/pkg/requests/message_send_request.go b/api/pkg/requests/message_send_request.go
index 3301691d..1a1d6830 100644
--- a/api/pkg/requests/message_send_request.go
+++ b/api/pkg/requests/message_send_request.go
@@ -14,9 +14,10 @@ import (
// MessageSend is the payload for sending and SMS message
type MessageSend struct {
request
- From string `json:"from" example:"+18005550199"`
- To string `json:"to" example:"+18005550100"`
- Content string `json:"content" example:"This is a sample text message"`
+ From string `json:"from" example:"+18005550199"`
+ To string `json:"to" example:"+18005550100"`
+ Content string `json:"content" example:"This is a sample text message"`
+ Attachments []entities.MessageAttachment `json:"attachments" validate:"optional"`
// Encrypted is an optional parameter used to determine if the content is end-to-end encrypted. Make sure to set the encryption key on the httpSMS mobile app
Encrypted bool `json:"encrypted" example:"false" validate:"optional"`
@@ -47,5 +48,6 @@ func (input *MessageSend) ToMessageSendParams(userID entities.UserID, source str
RequestReceivedAt: time.Now().UTC(),
Contact: input.sanitizeAddress(input.To),
Content: input.Content,
+ Attachments: input.Attachments,
}
}
diff --git a/api/pkg/services/message_service.go b/api/pkg/services/message_service.go
index 5a95b265..eca2334c 100644
--- a/api/pkg/services/message_service.go
+++ b/api/pkg/services/message_service.go
@@ -430,6 +430,7 @@ type MessageSendParams struct {
Contact string
Encrypted bool
Content string
+ Attachments []entities.MessageAttachment
Source string
SendAt *time.Time
RequestID *string
@@ -456,6 +457,7 @@ func (service *MessageService) SendMessage(ctx context.Context, params MessageSe
Contact: params.Contact,
RequestReceivedAt: params.RequestReceivedAt,
Content: params.Content,
+ Attachments: params.Attachments,
ScheduledSendTime: params.SendAt,
SIM: sim,
}
@@ -968,6 +970,7 @@ func (service *MessageService) storeSentMessage(ctx context.Context, payload eve
Contact: payload.Contact,
UserID: payload.UserID,
Content: payload.Content,
+ Attachments: payload.Attachments,
RequestID: payload.RequestID,
SIM: payload.SIM,
Encrypted: payload.Encrypted,