forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_receive_request.go
More file actions
51 lines (44 loc) · 1.77 KB
/
message_receive_request.go
File metadata and controls
51 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package requests
import (
"strings"
"time"
"github.com/NdoleStudio/httpsms/pkg/entities"
"github.com/nyaruka/phonenumbers"
"github.com/NdoleStudio/httpsms/pkg/services"
)
// MessageReceive is the payload for sending and SMS message
type MessageReceive 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 received on a phone"`
// Encrypted is 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"`
// SIM card that received the message
SIM entities.SIM `json:"sim" example:"SIM1"`
// Timestamp is the time when the event was emitted, Please send the timestamp in UTC with as much precision as possible
Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
}
// Sanitize sets defaults to MessageReceive
func (input *MessageReceive) Sanitize() MessageReceive {
input.To = input.sanitizeAddress(input.To)
input.From = input.sanitizeContact(input.To, input.From)
if strings.TrimSpace(string(input.SIM)) == "" || input.SIM == ("DEFAULT") {
input.SIM = entities.SIM1
}
return *input
}
// ToMessageReceiveParams converts MessageReceive to services.MessageReceiveParams
func (input *MessageReceive) ToMessageReceiveParams(userID entities.UserID, source string) *services.MessageReceiveParams {
phone, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION)
return &services.MessageReceiveParams{
Source: source,
Contact: input.From,
UserID: userID,
Timestamp: input.Timestamp,
Encrypted: input.Encrypted,
Owner: *phone,
Content: input.Content,
SIM: input.SIM,
}
}