Skip to content

Commit b75c362

Browse files
committed
Add end to end encryption on the Server NdoleStudio#335
1 parent 0482e58 commit b75c362

21 files changed

Lines changed: 72 additions & 25 deletions

api/pkg/emails/factory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ func (factory *factory) formatPhoneNumber(number string) string {
1414
return phonenumbers.Format(value, phonenumbers.INTERNATIONAL)
1515
}
1616

17+
func (factory *factory) formatBool(value bool) string {
18+
if value == true {
19+
return "Yes"
20+
}
21+
return "No"
22+
}
23+
1724
func (factory *factory) formatHTTPResponseCode(code *int) string {
1825
responseCode := "-"
1926
if code != nil {

api/pkg/emails/hermes_notification_email_factory.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
"github.com/NdoleStudio/httpsms/pkg/events"
88

9-
"github.com/google/uuid"
10-
119
"github.com/NdoleStudio/httpsms/pkg/entities"
1210
"github.com/matcornic/hermes/v2"
1311
"github.com/palantir/stacktrace"
@@ -129,18 +127,19 @@ func (factory *hermesNotificationEmailFactory) WebhookSendFailed(user *entities.
129127
}, nil
130128
}
131129

132-
func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.User, messageID uuid.UUID, owner string, contact string, content string) (*Email, error) {
130+
func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.User, payload *events.MessageSendExpiredPayload) (*Email, error) {
133131
email := hermes.Email{
134132
Body: hermes.Body{
135133
Title: "Hello",
136134
Intros: []string{
137-
fmt.Sprintf("The SMS message which you sent to %s has expired at %s and you will need to resend this message.", factory.formatPhoneNumber(contact), user.UserTimeString(time.Now())),
135+
fmt.Sprintf("The SMS message which you sent to %s has expired at %s and you will need to resend this message.", factory.formatPhoneNumber(payload.Contact), user.UserTimeString(time.Now())),
138136
},
139137
Dictionary: []hermes.Entry{
140-
{"ID", messageID.String()},
141-
{"From", factory.formatPhoneNumber(owner)},
142-
{"To", factory.formatPhoneNumber(contact)},
143-
{"Message", content},
138+
{"ID", payload.MessageID.String()},
139+
{"From", factory.formatPhoneNumber(payload.Owner)},
140+
{"To", factory.formatPhoneNumber(payload.Contact)},
141+
{"Message", payload.Content},
142+
{"Encrypted", factory.formatBool(payload.Encrypted)},
144143
},
145144
Actions: []hermes.Action{
146145
{
@@ -178,19 +177,20 @@ func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.Use
178177
}, nil
179178
}
180179

181-
func (factory *hermesNotificationEmailFactory) MessageFailed(user *entities.User, messageID uuid.UUID, owner, contact, content, reason string) (*Email, error) {
180+
func (factory *hermesNotificationEmailFactory) MessageFailed(user *entities.User, payload *events.MessageSendFailedPayload) (*Email, error) {
182181
email := hermes.Email{
183182
Body: hermes.Body{
184183
Title: "Hello",
185184
Intros: []string{
186-
fmt.Sprintf("The SMS message which you sent to %s has failed at %s and you will need to resend this message.", factory.formatPhoneNumber(contact), user.UserTimeString(time.Now())),
185+
fmt.Sprintf("The SMS message which you sent to %s has failed at %s and you will need to resend this message.", factory.formatPhoneNumber(payload.Contact), user.UserTimeString(time.Now())),
187186
},
188187
Dictionary: []hermes.Entry{
189-
{"ID", messageID.String()},
190-
{"From", factory.formatPhoneNumber(owner)},
191-
{"To", factory.formatPhoneNumber(contact)},
192-
{"Message", content},
193-
{"Failure Reason", reason},
188+
{"ID", payload.ID.String()},
189+
{"From", factory.formatPhoneNumber(payload.Owner)},
190+
{"To", factory.formatPhoneNumber(payload.Contact)},
191+
{"Message", payload.Content},
192+
{"Encrypted", factory.formatBool(payload.Encrypted)},
193+
{"Failure Reason", payload.ErrorMessage},
194194
},
195195
Actions: []hermes.Action{
196196
{

api/pkg/emails/notification_email_factory.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ package emails
33
import (
44
"github.com/NdoleStudio/httpsms/pkg/entities"
55
"github.com/NdoleStudio/httpsms/pkg/events"
6-
"github.com/google/uuid"
76
)
87

98
// NotificationEmailFactory generates emails to users about a message
109
type NotificationEmailFactory interface {
1110
// MessageExpired sends an email when the user's message is expired
12-
MessageExpired(user *entities.User, messageID uuid.UUID, owner, contact, content string) (*Email, error)
11+
MessageExpired(user *entities.User, payload *events.MessageSendExpiredPayload) (*Email, error)
1312

1413
// MessageFailed sends an email when the user's message is failed
15-
MessageFailed(user *entities.User, messageID uuid.UUID, owner, contact, content, reason string) (*Email, error)
14+
MessageFailed(user *entities.User, payload *events.MessageSendFailedPayload) (*Email, error)
1615

1716
// DiscordSendFailed sends an email when the user's discord message is failed
1817
DiscordSendFailed(user *entities.User, payload *events.DiscordSendFailedPayload) (*Email, error)

api/pkg/entities/message.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type Message struct {
8686
UserID UserID `json:"user_id" gorm:"index:idx_messages__user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
8787
Contact string `json:"contact" example:"+18005550100"`
8888
Content string `json:"content" example:"This is a sample text message"`
89+
Encrypted bool `json:"encrypted" example:"false" gorm:"default:false"`
8990
Type MessageType `json:"type" example:"mobile-terminated"`
9091
Status MessageStatus `json:"status" example:"pending"`
9192
// SIM is the SIM card to use to send the message

api/pkg/events/message_api_deleted_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ type MessageAPIDeletedPayload struct {
2020
Contact string `json:"contact"`
2121
Timestamp time.Time `json:"timestamp"`
2222
Content string `json:"content"`
23+
Encrypted bool `json:"encrypted"`
2324
SIM entities.SIM `json:"sim"`
2425
}

api/pkg/events/message_api_sent_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ type MessageAPISentPayload struct {
2222
ScheduledSendTime *time.Time `json:"scheduled_send_time"`
2323
RequestReceivedAt time.Time `json:"request_received_at"`
2424
Content string `json:"content"`
25+
Encrypted bool `json:"encrypted"`
2526
SIM entities.SIM `json:"sim"`
2627
}

api/pkg/events/message_notification_scheduled_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type MessageNotificationScheduledPayload struct {
1717
Owner string `json:"owner"`
1818
Contact string `json:"contact"`
1919
Content string `json:"content"`
20+
Encrypted bool `json:"encrypted"`
2021
SIM entities.SIM `json:"sim"`
2122
UserID entities.UserID `json:"user_id"`
2223
PhoneID uuid.UUID `json:"phone_id"`

api/pkg/events/message_phone_delivered_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MessagePhoneDeliveredPayload struct {
1818
Contact string `json:"contact"`
1919
RequestID *string `json:"request_id"`
2020
UserID entities.UserID `json:"user_id"`
21+
Encrypted bool `json:"encrypted"`
2122
Timestamp time.Time `json:"timestamp"`
2223
Content string `json:"content"`
2324
SIM entities.SIM `json:"sim"`

api/pkg/events/message_phone_received_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type MessagePhoneReceivedPayload struct {
1616
MessageID uuid.UUID `json:"message_id"`
1717
UserID entities.UserID `json:"user_id"`
1818
Owner string `json:"owner"`
19+
Encrypted bool `json:"encrypted"`
1920
Contact string `json:"contact"`
2021
Timestamp time.Time `json:"timestamp"`
2122
Content string `json:"content"`

api/pkg/events/message_phone_sending_event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type MessagePhoneSendingPayload struct {
1717
RequestID *string `json:"request_id"`
1818
Timestamp time.Time `json:"timestamp"`
1919
Owner string `json:"owner"`
20+
Encrypted bool `json:"encrypted"`
2021
Contact string `json:"contact"`
2122
Content string `json:"content"`
2223
SIM entities.SIM `json:"sim"`

0 commit comments

Comments
 (0)