From e73588fa84ba5bd84a21cb299d21af0f370784ab Mon Sep 17 00:00:00 2001 From: dilx Date: Tue, 19 Nov 2024 19:07:13 +0530 Subject: [PATCH 1/2] fix: condition for formatting Twillio otp code --- twilio.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/twilio.go b/twilio.go index b3638bc..8211129 100644 --- a/twilio.go +++ b/twilio.go @@ -47,7 +47,8 @@ func (c *TwilioClient) SendMessage(param map[string]string, targetPhoneNumber .. return fmt.Errorf("missing parameter: code") } - bodyContent := fmt.Sprintf(c.template, code) + bodyContent := code + if c.template != "" { bodyContent = fmt.Sprintf(c.template, code) } if len(targetPhoneNumber) < 2 { return fmt.Errorf("bad parameter: targetPhoneNumber") From 1f6c1fe52117c45255985033a8ab8f3b9602400c Mon Sep 17 00:00:00 2001 From: dilx Date: Tue, 19 Nov 2024 19:34:45 +0530 Subject: [PATCH 2/2] fix: add checks for sms content formatting --- aws.go | 5 ++++- huyi.go | 5 ++++- infobip.go | 5 ++++- smsbao.go | 7 ++++++- twilio.go | 6 ++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/aws.go b/aws.go index 05c56e0..eec7745 100644 --- a/aws.go +++ b/aws.go @@ -58,7 +58,10 @@ func (a *AmazonSNSClient) SendMessage(param map[string]string, targetPhoneNumber return fmt.Errorf("missing parameter: code") } - bodyContent := fmt.Sprintf(a.template, code) + bodyContent := code + if a.template != "" { + bodyContent = fmt.Sprintf(a.template, code) + } if len(targetPhoneNumber) == 0 { return fmt.Errorf("missing parameter: targetPhoneNumber") diff --git a/huyi.go b/huyi.go index b9b0c42..763ec5c 100644 --- a/huyi.go +++ b/huyi.go @@ -57,7 +57,10 @@ func (hc *HuyiClient) SendMessage(param map[string]string, targetPhoneNumber ... } _now := strconv.FormatInt(time.Now().Unix(), 10) - smsContent := fmt.Sprintf(hc.template, code) + smsContent := code + if hc.template != "" { + smsContent = fmt.Sprintf(hc.template, code) + } v := url.Values{} v.Set("account", hc.appId) v.Set("content", smsContent) diff --git a/infobip.go b/infobip.go index c528f34..010f78d 100644 --- a/infobip.go +++ b/infobip.go @@ -88,7 +88,10 @@ func (c *InfobipClient) SendMessage(param map[string]string, targetPhoneNumber . } endpoint := fmt.Sprintf("%s/sms/2/text/advanced", c.baseUrl) - text := fmt.Sprintf(c.template, code) + text := code + if c.template != "" { + text = fmt.Sprintf(c.template, code) + } messageData := MessageData{ Messages: []Message{ diff --git a/smsbao.go b/smsbao.go index 2d5f3b7..f0aa350 100644 --- a/smsbao.go +++ b/smsbao.go @@ -56,7 +56,12 @@ func (c *SmsBaoClient) SendMessage(param map[string]string, targetPhoneNumber .. return fmt.Errorf("missing parameter: targetPhoneNumber") } - smsContent := url.QueryEscape("【" + c.sign + "】" + fmt.Sprintf(c.template, code)) + otpText := code + if c.template != "" { + otpText = fmt.Sprintf(c.template, code) + } + + smsContent := url.QueryEscape("【" + c.sign + "】" + otpText) for _, mobile := range targetPhoneNumber { if strings.HasPrefix(mobile, "+86") { mobile = mobile[3:] diff --git a/twilio.go b/twilio.go index 8211129..fb33bb6 100644 --- a/twilio.go +++ b/twilio.go @@ -47,8 +47,10 @@ func (c *TwilioClient) SendMessage(param map[string]string, targetPhoneNumber .. return fmt.Errorf("missing parameter: code") } - bodyContent := code - if c.template != "" { bodyContent = fmt.Sprintf(c.template, code) } + bodyContent := code + if c.template != "" { + bodyContent = fmt.Sprintf(c.template, code) + } if len(targetPhoneNumber) < 2 { return fmt.Errorf("bad parameter: targetPhoneNumber")