Skip to content

Commit 9eb0bbd

Browse files
committed
Fix phone numbers in email notification for failed messages
1 parent 0ed1849 commit 9eb0bbd

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

api/pkg/emails/factory.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package emails
2+
3+
import "github.com/nyaruka/phonenumbers"
4+
5+
type factory struct{}
6+
7+
func (factory *factory) formatPhoneNumber(number string) string {
8+
value, _ := phonenumbers.Parse(number, phonenumbers.UNKNOWN_REGION)
9+
return phonenumbers.Format(value, phonenumbers.E164)
10+
}

api/pkg/emails/hermes_notification_email_factory.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
type hermesNotificationEmailFactory struct {
15+
factory
1516
config *HermesGeneratorConfig
1617
generator hermes.Hermes
1718
}
@@ -29,17 +30,17 @@ func (factory *hermesNotificationEmailFactory) MessageExpired(user *entities.Use
2930
Body: hermes.Body{
3031
Title: "Hello",
3132
Intros: []string{
32-
fmt.Sprintf("The SMS message which you sent to %s has expired at %s and you will need to resend this message.", owner, user.UserTimeString(time.Now())),
33+
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())),
3334
},
3435
Dictionary: []hermes.Entry{
3536
{"ID", messageID.String()},
36-
{"From", owner},
37-
{"To", contact},
37+
{"From", factory.formatPhoneNumber(owner)},
38+
{"To", factory.formatPhoneNumber(contact)},
3839
{"Message", content},
3940
},
4041
Actions: []hermes.Action{
4142
{
42-
Instructions: "Messages expire because we couldn't connect with your mobile phone to send the outgoing SMS. You can fix this by making sure your phone is connected to the internet and also connect your phone to the charger all the time since Android may kill the httpSMS app if it has been active for a very long time so save phone battery.",
43+
Instructions: "Messages usually expire because we couldn't connect with your mobile phone to send the outgoing SMS. You can fix this by making sure your phone is connected to the internet and also connect your phone to the charger all the time since Android may kill the httpSMS app if it has been active for a very long time so save phone battery.",
4344
Button: hermes.Button{
4445
Color: "#329ef4",
4546
TextColor: "#FFFFFF",
@@ -78,12 +79,12 @@ func (factory *hermesNotificationEmailFactory) MessageFailed(user *entities.User
7879
Body: hermes.Body{
7980
Title: "Hello",
8081
Intros: []string{
81-
fmt.Sprintf("The SMS message which you sent to %s has failed at %s and you will need to resend this message.", owner, user.UserTimeString(time.Now())),
82+
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())),
8283
},
8384
Dictionary: []hermes.Entry{
8485
{"ID", messageID.String()},
85-
{"From", owner},
86-
{"To", contact},
86+
{"From", factory.formatPhoneNumber(owner)},
87+
{"To", factory.formatPhoneNumber(contact)},
8788
{"Message", content},
8889
{"Failure Reason", reason},
8990
},

api/pkg/emails/hermes_user_email_factory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type hermesUserEmailFactory struct {
13+
factory
1314
config *HermesGeneratorConfig
1415
generator hermes.Hermes
1516
}
@@ -122,7 +123,7 @@ func (factory *hermesUserEmailFactory) PhoneDead(user *entities.User, lastHeartb
122123
email := hermes.Email{
123124
Body: hermes.Body{
124125
Intros: []string{
125-
fmt.Sprintf("We haven't received any heartbeat event from android phone %s since %s.", owner, lastHeartbeatTimestamp.In(location).Format(time.RFC1123)),
126+
fmt.Sprintf("We haven't received any heartbeat event from android phone %s since %s.", factory.formatPhoneNumber(owner), lastHeartbeatTimestamp.In(location).Format(time.RFC1123)),
126127
fmt.Sprintf("Check if the mobile phone is powered on and if it has stable internet connection."),
127128
},
128129
Actions: []hermes.Action{

0 commit comments

Comments
 (0)