-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c994882
commit b3c8fa0
Showing
2 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,74 @@ | ||
module Azure.Email | ||
( ) where | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
|
||
module Azure.Email () where | ||
|
||
import Data.Aeson (ToJSON (..), object, (.=)) | ||
import Data.Text (Text) | ||
import GHC.Generics (Generic) | ||
|
||
data EmailAddress = EmailAddress | ||
{ eaEmail :: !Text | ||
, eaDisplayName :: !Text | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
instance ToJSON EmailAddress where | ||
toJSON EmailAddress{..} = | ||
object | ||
[ "address" .= eaEmail | ||
, "displayName" .= eaDisplayName | ||
] | ||
|
||
-- | Fields to represent @cc@, @bcc@ and @to@ in an email | ||
data EmailRecipients = EmailRecipients | ||
{ ccRecipients :: ![EmailAddress] | ||
, bccRecipients :: ![EmailAddress] | ||
, toRecipients :: ![EmailAddress] | ||
} | ||
deriving stock (Generic) | ||
|
||
instance ToJSON EmailRecipients where | ||
toJSON EmailRecipients{..} = | ||
object | ||
[ "to" .= toRecipients | ||
, "cc" .= ccRecipients | ||
, "bcc" .= bccRecipients | ||
] | ||
|
||
-- | Azure email requires both HTML and plain text format email content | ||
data EmailContent = EmailContent | ||
{ ecHtml :: !Text | ||
-- ^ Html version of the email message. | ||
, ecPlainText :: !Text | ||
-- ^ Plain text version of the email message. | ||
, ecSubject :: !Text | ||
-- ^ Subject of the email message. | ||
} | ||
deriving stock (Eq, Show, Generic) | ||
|
||
instance ToJSON EmailContent where | ||
toJSON EmailContent{..} = | ||
object | ||
[ "plainText" .= ecPlainText | ||
, "html" .= ecHtml | ||
, "subject" .= ecSubject | ||
] | ||
|
||
{- | Source: | ||
https://learn.microsoft.com/en-us/rest/api/communication/dataplane/email/send?view=rest-communication-dataplane-2023-03-31&tabs=HTTP | ||
-} | ||
data AzureEmailRequest = AzureEmailRequest | ||
{ aerContent :: !EmailContent | ||
, aerRecipients :: !EmailRecipients | ||
, aerSenderAddress :: !Text -- TODO: This should probably be it's own newtype | ||
} | ||
deriving stock (Generic) | ||
|
||
instance ToJSON AzureEmailRequest where | ||
toJSON AzureEmailRequest{..} = | ||
object | ||
[ "content" .= aerContent | ||
, "recipients" .= aerRecipients | ||
, "senderAddress" .= aerSenderAddress | ||
] |