Skip to content

Commit

Permalink
Add handling of + and # in sms
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhny committed Nov 30, 2023
1 parent 0e4e5bb commit 26805fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/smseagle/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func (s *SMSEagle) Notify(message *SMSEagleMessage) error {
smsEagleRequestsCounter.Inc()

if message.ContactType == SMS {
msg := strings.ReplaceAll(message.Message, " ", "+")
msg := strings.ReplaceAll(message.Message, "+", "%2B")
msg = strings.ReplaceAll(msg, "#", "%23")
msg = strings.ReplaceAll(msg, " ", "+")
msg = strings.ReplaceAll(msg, "\n", "%0A")
err := sendSMS(s.cfg, message.PhoneNumber, msg, client)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/smseagle/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var _ = Describe("Handler", func() {

Context("appdrift alert", func() {
It("should make get requests with correct queries to sms and call", func() {
msg := SMSEagleMessage{Message: "hei pa deg", PhoneNumber: "123"}
exptectedSMSMsg := "hei+pa+deg"
msg := SMSEagleMessage{Message: "hei pa deg, urltest: https://kartverket.atlassian.net/wiki/spaces/SKIP/pages/713359536/Playbook+for+SKIP-alarmer#HostOutOfInodes", PhoneNumber: "123"}
exptectedSMSMsg := "hei+pa+deg,+urltest:+https://kartverket.atlassian.net/wiki/spaces/SKIP/pages/713359536/Playbook%2Bfor%2BSKIP-alarmer%23HostOutOfInodes"
expectedSMSQuery := fmt.Sprintf("access_token=%s&to=%s&message=%s&unicode=1", cfg.SMS.AccessToken, "123", exptectedSMSMsg)
expectedCallQuery := fmt.Sprintf("access_token=%s&to=%s", cfg.Call.AccessToken, "123")
server.AppendHandlers(
Expand Down

0 comments on commit 26805fa

Please sign in to comment.