File size: 1,259 Bytes
83a59ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package requests

import (
	"time"

	"github.com/NdoleStudio/httpsms/pkg/entities"

	"github.com/nyaruka/phonenumbers"

	"github.com/NdoleStudio/httpsms/pkg/services"
)

// MessageCallMissed is the payload for sending and missed call event
type MessageCallMissed struct {
	request
	From      string    `json:"from" example:"+18005550199"`
	To        string    `json:"to" example:"+18005550100"`
	SIM       string    `json:"sim" example:"SIM1"`
	Timestamp time.Time `json:"timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
}

// Sanitize sets defaults to MessageReceive
func (input *MessageCallMissed) Sanitize() MessageCallMissed {
	input.To = input.sanitizeAddress(input.To)
	input.From = input.sanitizeContact(input.To, input.From)
	input.SIM = input.sanitizeSIM(input.SIM)

	return *input
}

// ToCallMissedParams converts MessageCallMissed to services.MessageSendParams
func (input *MessageCallMissed) ToCallMissedParams(userID entities.UserID, source string) *services.MissedCallParams {
	to, _ := phonenumbers.Parse(input.To, phonenumbers.UNKNOWN_REGION)
	return &services.MissedCallParams{
		Source:    source,
		Owner:     to,
		Timestamp: input.Timestamp,
		SIM:       entities.SIM(input.SIM),
		UserID:    userID,
		Contact:   input.From,
	}
}