From 0d21223a4125e63ee0377383a23120628380424e Mon Sep 17 00:00:00 2001 From: "janhavi.soni" Date: Wed, 21 Jun 2023 20:23:09 +0530 Subject: [PATCH] backend/feat/#146 : Adding extra params to send sms --- .../src/Kernel/External/SMS/ExotelSms/Flow.hs | 11 +++++--- .../Kernel/External/SMS/ExotelSms/Types.hs | 14 +++++++--- .../External/SMS/Interface/ExotelSms.hs | 4 ++- .../Kernel/External/SMS/Interface/Types.hs | 28 ++++++++++++++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Flow.hs b/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Flow.hs index b7618d07a..d70c233b1 100644 --- a/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Flow.hs +++ b/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Flow.hs @@ -49,16 +49,19 @@ sendOTPApi :: Text -> Text -> Text -> - m - SubmitSmsResp + Text -> + Text -> + m SubmitSmsResp sendOTPApi url authData sid otpSmsTemplate phoneNumber - sender = do - let submitSmsReq = SubmitSmsReq sender phoneNumber otpSmsTemplate + sender + smsType + priority = do + let submitSmsReq = SubmitSmsReq sender phoneNumber otpSmsTemplate smsType priority let auth = authData callExotelAPI (defaultBaseUrlSms sid url) diff --git a/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Types.hs b/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Types.hs index 501165cf4..ad55e14d9 100644 --- a/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Types.hs +++ b/lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Types.hs @@ -29,8 +29,8 @@ import Data.Aeson.Casing import Data.Aeson.TH import Data.OpenApi (ToSchema) import Data.Text as T -import Data.Text.Conversions -import EulerHS.Prelude +import Data.Text.Conversions (FromText (..)) +import EulerHS.Prelude hiding (fromStrict) import Kernel.External.Call.Exotel.Types (ExotelAccountSID) import Kernel.Storage.Esqueleto (derivePersistField) import Kernel.Utils.JSON @@ -55,9 +55,13 @@ data SubmitSmsReq = SubmitSmsReq to :: Text, -- Mobile number to which SMS has to be sent. Preferably in E.164 format. If not set, our system will try to match it with a -- country and route the SMS - body :: Text + body :: Text, -- String; Content of your SMS; Max Length of the body cannot exceed -- 2000 characters + smsType :: Text, + -- String; Type of sms + priority :: Text + -- String: normal or high } deriving (Generic, Eq, Show) @@ -65,7 +69,9 @@ instance ToForm SubmitSmsReq where toForm SubmitSmsReq {..} = [ ("From", toQueryParam from), ("To", toQueryParam to), - ("Body", toQueryParam body) + ("Body", toQueryParam body), + ("SMSType", toQueryParam smsType), + ("Priority", toQueryParam priority) ] -- | SMS direction diff --git a/lib/mobility-core/src/Kernel/External/SMS/Interface/ExotelSms.hs b/lib/mobility-core/src/Kernel/External/SMS/Interface/ExotelSms.hs index 3e367e14e..fc702a26a 100644 --- a/lib/mobility-core/src/Kernel/External/SMS/Interface/ExotelSms.hs +++ b/lib/mobility-core/src/Kernel/External/SMS/Interface/ExotelSms.hs @@ -51,7 +51,9 @@ sendOTP exoCfg SendSMSReq {..} = do BasicAuthData (DT.encodeUtf8 apiKey) (DT.encodeUtf8 apiToken) - res <- Ex.sendOTPApi exoUrl authData sid exoOtpSmsTemplate exoPhoneNumber senderName + exoSmsType = maybe "" toUrlPiece (Just IT.Transactional) + exoPriority = maybe "" toUrlPiece (Just IT.High) + res <- Ex.sendOTPApi exoUrl authData sid exoOtpSmsTemplate exoPhoneNumber senderName exoSmsType exoPriority return $ returnSmsResultExo res.exoSMSMessage.exoStatus returnSmsResultExo :: ExotelSmsStatus -> IT.SendSMSRes diff --git a/lib/mobility-core/src/Kernel/External/SMS/Interface/Types.hs b/lib/mobility-core/src/Kernel/External/SMS/Interface/Types.hs index bb859c6f4..a185a45b2 100644 --- a/lib/mobility-core/src/Kernel/External/SMS/Interface/Types.hs +++ b/lib/mobility-core/src/Kernel/External/SMS/Interface/Types.hs @@ -21,6 +21,7 @@ module Kernel.External.SMS.Interface.Types where import Data.ByteString.Lazy (fromStrict, toStrict) +import Data.OpenApi import qualified Data.Text as T import qualified Data.Text.Encoding as T import Deriving.Aeson @@ -29,6 +30,7 @@ import qualified Kernel.External.SMS.MyValueFirst.Config as MyValueFirst import qualified Kernel.External.SMS.Types as T import Kernel.Prelude import Kernel.Types.Servant +import Kernel.Utils.JSON (constructorsWithSnakeCase) import Servant data SmsHandler m = SmsHandler @@ -45,7 +47,16 @@ data SendSMSReq = SendSMSReq phoneNumber :: Text, sender :: Text } - deriving (Generic, FromJSON, ToJSON, ToSchema) + deriving (Generic, FromJSON, ToJSON) + +instance ToSchema SendSMSReq where + declareNamedSchema = genericDeclareNamedSchema $ fromAesonOptions constructorsWithSnakeCase + +instance ToSchema SMSType where + declareNamedSchema = genericDeclareNamedSchema $ fromAesonOptions constructorsWithSnakeCase + +instance ToSchema PriorityType where + declareNamedSchema = genericDeclareNamedSchema $ fromAesonOptions constructorsWithSnakeCase data SendSMSRes = Success | Fail | Pending | UnknownError deriving (Generic, FromJSON, ToJSON, Show, Eq) @@ -69,3 +80,18 @@ sendOtpResToText = \case Fail -> "Fail" Pending -> "Pending" UnknownError -> "unknown request" + +data SMSType = Transactional | Promotional | TransactionalOptIn + deriving (Generic, FromJSON, ToJSON, Show, Eq) + +data PriorityType = Normal | High + deriving (Generic, FromJSON, ToJSON, Show, Eq) + +instance ToHttpApiData SMSType where + toUrlPiece Transactional = "transactional" + toUrlPiece Promotional = "promotional" + toUrlPiece TransactionalOptIn = "transaction_opt_in" + +instance ToHttpApiData PriorityType where + toUrlPiece Normal = "normal" + toUrlPiece High = "high"