Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/feat/#146 : Adding extra params to send sms #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Flow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ sendOTPApi ::
Text ->
Text ->
Text ->
m
SubmitSmsResp
SMSType ->
PriorityType ->
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)
Expand Down
28 changes: 24 additions & 4 deletions lib/mobility-core/src/Kernel/External/SMS/ExotelSms/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,29 @@ 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
import Kernel.Utils.TH
import Web.FormUrlEncoded (ToForm, toForm)
import Web.Internal.HttpApiData

data SMSType = TRANSACTIONAL | PROMOTIONAL | TRANSACTIONAL_OPT_IN
deriving (Generic, FromJSON, ToJSON, Show, Eq)

data PriorityType = NORMAL | HIGH
deriving (Generic, FromJSON, ToJSON, Show, Eq)

instance ToHttpApiData SMSType where
toUrlPiece = T.toLower . show
toQueryParam = toUrlPiece

instance ToHttpApiData PriorityType where
toUrlPiece = T.toLower . show
toQueryParam = toUrlPiece

type OtpTemplate = Text

-- | Exotel Url token
Expand All @@ -55,17 +69,23 @@ 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 :: SMSType,
-- String; Type of sms
priority :: PriorityType
-- String: normal or high
}
deriving (Generic, Eq, Show)

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = TRANSACTIONAL
exoPriority = HIGH
res <- Ex.sendOTPApi exoUrl authData sid exoOtpSmsTemplate exoPhoneNumber senderName exoSmsType exoPriority
return $ returnSmsResultExo res.exoSMSMessage.exoStatus

returnSmsResultExo :: ExotelSmsStatus -> IT.SendSMSRes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down