forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_event_request.go
More file actions
46 lines (36 loc) · 1.56 KB
/
message_event_request.go
File metadata and controls
46 lines (36 loc) · 1.56 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
package requests
import (
"time"
"github.com/NdoleStudio/httpsms/pkg/entities"
"github.com/google/uuid"
"github.com/NdoleStudio/httpsms/pkg/services"
)
// MessageEvent is the payload for sending and SMS message
type MessageEvent struct {
request
// 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"`
// EventName is the type of event
// * SENT: is emitted when a message is sent by the mobile phone
// * FAILED: is event is emitted when the message could not be sent by the mobile phone
// * DELIVERED: is event is emitted when a delivery report has been received by the mobile phone
EventName string `json:"event_name" example:"SENT"`
// Reason is the exact error message in case the event is an error
Reason *string `json:"reason"`
MessageID string `json:"messageID" swaggerignore:"true"` // used internally for validation
}
// Sanitize the message event
func (input *MessageEvent) Sanitize() MessageEvent {
input.MessageID = input.sanitizeMessageID(input.MessageID)
return *input
}
// ToMessageStoreEventParams converts MessageEvent to services.MessageStoreEventParams
func (input *MessageEvent) ToMessageStoreEventParams(source string) services.MessageStoreEventParams {
return services.MessageStoreEventParams{
MessageID: uuid.MustParse(input.MessageID),
Source: source,
ErrorMessage: input.Reason,
EventName: entities.MessageEventName(input.EventName),
Timestamp: input.Timestamp,
}
}