{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SNS.Publish
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Sends a message to an Amazon SNS topic, a text message (SMS message)
-- directly to a phone number, or a message to a mobile platform endpoint
-- (when you specify the @TargetArn@).
--
-- If you send a message to a topic, Amazon SNS delivers the message to
-- each endpoint that is subscribed to the topic. The format of the message
-- depends on the notification protocol for each subscribed endpoint.
--
-- When a @messageId@ is returned, the message has been saved and Amazon
-- SNS will attempt to deliver it shortly.
--
-- To use the @Publish@ action for sending a message to a mobile endpoint,
-- such as an app on a Kindle device or mobile phone, you must specify the
-- EndpointArn for the TargetArn parameter. The EndpointArn is returned
-- when making a call with the @CreatePlatformEndpoint@ action.
--
-- For more information about formatting messages, see
-- <https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html Send Custom Platform-Specific Payloads in Messages to Mobile Devices>.
--
-- You can publish messages only to topics and endpoints in the same
-- Region.
module Amazonka.SNS.Publish
  ( -- * Creating a Request
    Publish (..),
    newPublish,

    -- * Request Lenses
    publish_subject,
    publish_targetArn,
    publish_messageAttributes,
    publish_topicArn,
    publish_phoneNumber,
    publish_messageDeduplicationId,
    publish_messageStructure,
    publish_messageGroupId,
    publish_message,

    -- * Destructuring the Response
    PublishResponse (..),
    newPublishResponse,

    -- * Response Lenses
    publishResponse_sequenceNumber,
    publishResponse_messageId,
    publishResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SNS.Types

-- | Input for Publish action.
--
-- /See:/ 'newPublish' smart constructor.
data Publish = Publish'
  { -- | Optional parameter to be used as the \"Subject\" line when the message
    -- is delivered to email endpoints. This field will also be included, if
    -- present, in the standard JSON messages delivered to other endpoints.
    --
    -- Constraints: Subjects must be ASCII text that begins with a letter,
    -- number, or punctuation mark; must not include line breaks or control
    -- characters; and must be less than 100 characters long.
    Publish -> Maybe Text
subject :: Prelude.Maybe Prelude.Text,
    -- | If you don\'t specify a value for the @TargetArn@ parameter, you must
    -- specify a value for the @PhoneNumber@ or @TopicArn@ parameters.
    Publish -> Maybe Text
targetArn :: Prelude.Maybe Prelude.Text,
    -- | Message attributes for Publish action.
    Publish -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text MessageAttributeValue),
    -- | The topic you want to publish to.
    --
    -- If you don\'t specify a value for the @TopicArn@ parameter, you must
    -- specify a value for the @PhoneNumber@ or @TargetArn@ parameters.
    Publish -> Maybe Text
topicArn :: Prelude.Maybe Prelude.Text,
    -- | The phone number to which you want to deliver an SMS message. Use E.164
    -- format.
    --
    -- If you don\'t specify a value for the @PhoneNumber@ parameter, you must
    -- specify a value for the @TargetArn@ or @TopicArn@ parameters.
    Publish -> Maybe Text
phoneNumber :: Prelude.Maybe Prelude.Text,
    -- | This parameter applies only to FIFO (first-in-first-out) topics. The
    -- @MessageDeduplicationId@ can contain up to 128 alphanumeric characters
    -- (a-z, A-Z, 0-9) and punctuation
    -- @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
    --
    -- Every message must have a unique @MessageDeduplicationId@, which is a
    -- token used for deduplication of sent messages. If a message with a
    -- particular @MessageDeduplicationId@ is sent successfully, any message
    -- sent with the same @MessageDeduplicationId@ during the 5-minute
    -- deduplication interval is treated as a duplicate.
    --
    -- If the topic has @ContentBasedDeduplication@ set, the system generates a
    -- @MessageDeduplicationId@ based on the contents of the message. Your
    -- @MessageDeduplicationId@ overrides the generated one.
    Publish -> Maybe Text
messageDeduplicationId :: Prelude.Maybe Prelude.Text,
    -- | Set @MessageStructure@ to @json@ if you want to send a different message
    -- for each protocol. For example, using one publish action, you can send a
    -- short message to your SMS subscribers and a longer message to your email
    -- subscribers. If you set @MessageStructure@ to @json@, the value of the
    -- @Message@ parameter must:
    --
    -- -   be a syntactically valid JSON object; and
    --
    -- -   contain at least a top-level JSON key of \"default\" with a value
    --     that is a string.
    --
    -- You can define other top-level keys that define the message you want to
    -- send to a specific transport protocol (e.g., \"http\").
    --
    -- Valid value: @json@
    Publish -> Maybe Text
messageStructure :: Prelude.Maybe Prelude.Text,
    -- | This parameter applies only to FIFO (first-in-first-out) topics. The
    -- @MessageGroupId@ can contain up to 128 alphanumeric characters (a-z,
    -- A-Z, 0-9) and punctuation @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
    --
    -- The @MessageGroupId@ is a tag that specifies that a message belongs to a
    -- specific message group. Messages that belong to the same message group
    -- are processed in a FIFO manner (however, messages in different message
    -- groups might be processed out of order). Every message must include a
    -- @MessageGroupId@.
    Publish -> Maybe Text
messageGroupId :: Prelude.Maybe Prelude.Text,
    -- | The message you want to send.
    --
    -- If you are publishing to a topic and you want to send the same message
    -- to all transport protocols, include the text of the message as a String
    -- value. If you want to send different messages for each transport
    -- protocol, set the value of the @MessageStructure@ parameter to @json@
    -- and use a JSON object for the @Message@ parameter.
    --
    -- Constraints:
    --
    -- -   With the exception of SMS, messages must be UTF-8 encoded strings
    --     and at most 256 KB in size (262,144 bytes, not 262,144 characters).
    --
    -- -   For SMS, each message can contain up to 140 characters. This
    --     character limit depends on the encoding schema. For example, an SMS
    --     message can contain 160 GSM characters, 140 ASCII characters, or 70
    --     UCS-2 characters.
    --
    --     If you publish a message that exceeds this size limit, Amazon SNS
    --     sends the message as multiple messages, each fitting within the size
    --     limit. Messages aren\'t truncated mid-word but are cut off at
    --     whole-word boundaries.
    --
    --     The total size limit for a single SMS @Publish@ action is 1,600
    --     characters.
    --
    -- JSON-specific constraints:
    --
    -- -   Keys in the JSON object that correspond to supported transport
    --     protocols must have simple JSON string values.
    --
    -- -   The values will be parsed (unescaped) before they are used in
    --     outgoing messages.
    --
    -- -   Outbound notifications are JSON encoded (meaning that the characters
    --     will be reescaped for sending).
    --
    -- -   Values have a minimum length of 0 (the empty string, \"\", is
    --     allowed).
    --
    -- -   Values have a maximum length bounded by the overall message size
    --     (so, including multiple protocols may limit message sizes).
    --
    -- -   Non-string values will cause the key to be ignored.
    --
    -- -   Keys that do not correspond to supported transport protocols are
    --     ignored.
    --
    -- -   Duplicate keys are not allowed.
    --
    -- -   Failure to parse or validate any key or value in the message will
    --     cause the @Publish@ call to return an error (no partial delivery).
    Publish -> Text
message :: Prelude.Text
  }
  deriving (Publish -> Publish -> Bool
(Publish -> Publish -> Bool)
-> (Publish -> Publish -> Bool) -> Eq Publish
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Publish -> Publish -> Bool
$c/= :: Publish -> Publish -> Bool
== :: Publish -> Publish -> Bool
$c== :: Publish -> Publish -> Bool
Prelude.Eq, ReadPrec [Publish]
ReadPrec Publish
Int -> ReadS Publish
ReadS [Publish]
(Int -> ReadS Publish)
-> ReadS [Publish]
-> ReadPrec Publish
-> ReadPrec [Publish]
-> Read Publish
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Publish]
$creadListPrec :: ReadPrec [Publish]
readPrec :: ReadPrec Publish
$creadPrec :: ReadPrec Publish
readList :: ReadS [Publish]
$creadList :: ReadS [Publish]
readsPrec :: Int -> ReadS Publish
$creadsPrec :: Int -> ReadS Publish
Prelude.Read, Int -> Publish -> ShowS
[Publish] -> ShowS
Publish -> String
(Int -> Publish -> ShowS)
-> (Publish -> String) -> ([Publish] -> ShowS) -> Show Publish
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Publish] -> ShowS
$cshowList :: [Publish] -> ShowS
show :: Publish -> String
$cshow :: Publish -> String
showsPrec :: Int -> Publish -> ShowS
$cshowsPrec :: Int -> Publish -> ShowS
Prelude.Show, (forall x. Publish -> Rep Publish x)
-> (forall x. Rep Publish x -> Publish) -> Generic Publish
forall x. Rep Publish x -> Publish
forall x. Publish -> Rep Publish x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Publish x -> Publish
$cfrom :: forall x. Publish -> Rep Publish x
Prelude.Generic)

-- |
-- Create a value of 'Publish' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'subject', 'publish_subject' - Optional parameter to be used as the \"Subject\" line when the message
-- is delivered to email endpoints. This field will also be included, if
-- present, in the standard JSON messages delivered to other endpoints.
--
-- Constraints: Subjects must be ASCII text that begins with a letter,
-- number, or punctuation mark; must not include line breaks or control
-- characters; and must be less than 100 characters long.
--
-- 'targetArn', 'publish_targetArn' - If you don\'t specify a value for the @TargetArn@ parameter, you must
-- specify a value for the @PhoneNumber@ or @TopicArn@ parameters.
--
-- 'messageAttributes', 'publish_messageAttributes' - Message attributes for Publish action.
--
-- 'topicArn', 'publish_topicArn' - The topic you want to publish to.
--
-- If you don\'t specify a value for the @TopicArn@ parameter, you must
-- specify a value for the @PhoneNumber@ or @TargetArn@ parameters.
--
-- 'phoneNumber', 'publish_phoneNumber' - The phone number to which you want to deliver an SMS message. Use E.164
-- format.
--
-- If you don\'t specify a value for the @PhoneNumber@ parameter, you must
-- specify a value for the @TargetArn@ or @TopicArn@ parameters.
--
-- 'messageDeduplicationId', 'publish_messageDeduplicationId' - This parameter applies only to FIFO (first-in-first-out) topics. The
-- @MessageDeduplicationId@ can contain up to 128 alphanumeric characters
-- (a-z, A-Z, 0-9) and punctuation
-- @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
--
-- Every message must have a unique @MessageDeduplicationId@, which is a
-- token used for deduplication of sent messages. If a message with a
-- particular @MessageDeduplicationId@ is sent successfully, any message
-- sent with the same @MessageDeduplicationId@ during the 5-minute
-- deduplication interval is treated as a duplicate.
--
-- If the topic has @ContentBasedDeduplication@ set, the system generates a
-- @MessageDeduplicationId@ based on the contents of the message. Your
-- @MessageDeduplicationId@ overrides the generated one.
--
-- 'messageStructure', 'publish_messageStructure' - Set @MessageStructure@ to @json@ if you want to send a different message
-- for each protocol. For example, using one publish action, you can send a
-- short message to your SMS subscribers and a longer message to your email
-- subscribers. If you set @MessageStructure@ to @json@, the value of the
-- @Message@ parameter must:
--
-- -   be a syntactically valid JSON object; and
--
-- -   contain at least a top-level JSON key of \"default\" with a value
--     that is a string.
--
-- You can define other top-level keys that define the message you want to
-- send to a specific transport protocol (e.g., \"http\").
--
-- Valid value: @json@
--
-- 'messageGroupId', 'publish_messageGroupId' - This parameter applies only to FIFO (first-in-first-out) topics. The
-- @MessageGroupId@ can contain up to 128 alphanumeric characters (a-z,
-- A-Z, 0-9) and punctuation @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
--
-- The @MessageGroupId@ is a tag that specifies that a message belongs to a
-- specific message group. Messages that belong to the same message group
-- are processed in a FIFO manner (however, messages in different message
-- groups might be processed out of order). Every message must include a
-- @MessageGroupId@.
--
-- 'message', 'publish_message' - The message you want to send.
--
-- If you are publishing to a topic and you want to send the same message
-- to all transport protocols, include the text of the message as a String
-- value. If you want to send different messages for each transport
-- protocol, set the value of the @MessageStructure@ parameter to @json@
-- and use a JSON object for the @Message@ parameter.
--
-- Constraints:
--
-- -   With the exception of SMS, messages must be UTF-8 encoded strings
--     and at most 256 KB in size (262,144 bytes, not 262,144 characters).
--
-- -   For SMS, each message can contain up to 140 characters. This
--     character limit depends on the encoding schema. For example, an SMS
--     message can contain 160 GSM characters, 140 ASCII characters, or 70
--     UCS-2 characters.
--
--     If you publish a message that exceeds this size limit, Amazon SNS
--     sends the message as multiple messages, each fitting within the size
--     limit. Messages aren\'t truncated mid-word but are cut off at
--     whole-word boundaries.
--
--     The total size limit for a single SMS @Publish@ action is 1,600
--     characters.
--
-- JSON-specific constraints:
--
-- -   Keys in the JSON object that correspond to supported transport
--     protocols must have simple JSON string values.
--
-- -   The values will be parsed (unescaped) before they are used in
--     outgoing messages.
--
-- -   Outbound notifications are JSON encoded (meaning that the characters
--     will be reescaped for sending).
--
-- -   Values have a minimum length of 0 (the empty string, \"\", is
--     allowed).
--
-- -   Values have a maximum length bounded by the overall message size
--     (so, including multiple protocols may limit message sizes).
--
-- -   Non-string values will cause the key to be ignored.
--
-- -   Keys that do not correspond to supported transport protocols are
--     ignored.
--
-- -   Duplicate keys are not allowed.
--
-- -   Failure to parse or validate any key or value in the message will
--     cause the @Publish@ call to return an error (no partial delivery).
newPublish ::
  -- | 'message'
  Prelude.Text ->
  Publish
newPublish :: Text -> Publish
newPublish Text
pMessage_ =
  Publish' :: Maybe Text
-> Maybe Text
-> Maybe (HashMap Text MessageAttributeValue)
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> Publish
Publish'
    { $sel:subject:Publish' :: Maybe Text
subject = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targetArn:Publish' :: Maybe Text
targetArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageAttributes:Publish' :: Maybe (HashMap Text MessageAttributeValue)
messageAttributes = Maybe (HashMap Text MessageAttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:Publish' :: Maybe Text
topicArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:phoneNumber:Publish' :: Maybe Text
phoneNumber = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageDeduplicationId:Publish' :: Maybe Text
messageDeduplicationId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageStructure:Publish' :: Maybe Text
messageStructure = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageGroupId:Publish' :: Maybe Text
messageGroupId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:message:Publish' :: Text
message = Text
pMessage_
    }

-- | Optional parameter to be used as the \"Subject\" line when the message
-- is delivered to email endpoints. This field will also be included, if
-- present, in the standard JSON messages delivered to other endpoints.
--
-- Constraints: Subjects must be ASCII text that begins with a letter,
-- number, or punctuation mark; must not include line breaks or control
-- characters; and must be less than 100 characters long.
publish_subject :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_subject :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_subject = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
subject :: Maybe Text
$sel:subject:Publish' :: Publish -> Maybe Text
subject} -> Maybe Text
subject) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:subject:Publish' :: Maybe Text
subject = Maybe Text
a} :: Publish)

-- | If you don\'t specify a value for the @TargetArn@ parameter, you must
-- specify a value for the @PhoneNumber@ or @TopicArn@ parameters.
publish_targetArn :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_targetArn :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_targetArn = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
targetArn :: Maybe Text
$sel:targetArn:Publish' :: Publish -> Maybe Text
targetArn} -> Maybe Text
targetArn) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:targetArn:Publish' :: Maybe Text
targetArn = Maybe Text
a} :: Publish)

-- | Message attributes for Publish action.
publish_messageAttributes :: Lens.Lens' Publish (Prelude.Maybe (Prelude.HashMap Prelude.Text MessageAttributeValue))
publish_messageAttributes :: (Maybe (HashMap Text MessageAttributeValue)
 -> f (Maybe (HashMap Text MessageAttributeValue)))
-> Publish -> f Publish
publish_messageAttributes = (Publish -> Maybe (HashMap Text MessageAttributeValue))
-> (Publish
    -> Maybe (HashMap Text MessageAttributeValue) -> Publish)
-> Lens
     Publish
     Publish
     (Maybe (HashMap Text MessageAttributeValue))
     (Maybe (HashMap Text MessageAttributeValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe (HashMap Text MessageAttributeValue)
messageAttributes :: Maybe (HashMap Text MessageAttributeValue)
$sel:messageAttributes:Publish' :: Publish -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes} -> Maybe (HashMap Text MessageAttributeValue)
messageAttributes) (\s :: Publish
s@Publish' {} Maybe (HashMap Text MessageAttributeValue)
a -> Publish
s {$sel:messageAttributes:Publish' :: Maybe (HashMap Text MessageAttributeValue)
messageAttributes = Maybe (HashMap Text MessageAttributeValue)
a} :: Publish) ((Maybe (HashMap Text MessageAttributeValue)
  -> f (Maybe (HashMap Text MessageAttributeValue)))
 -> Publish -> f Publish)
-> ((Maybe (HashMap Text MessageAttributeValue)
     -> f (Maybe (HashMap Text MessageAttributeValue)))
    -> Maybe (HashMap Text MessageAttributeValue)
    -> f (Maybe (HashMap Text MessageAttributeValue)))
-> (Maybe (HashMap Text MessageAttributeValue)
    -> f (Maybe (HashMap Text MessageAttributeValue)))
-> Publish
-> f Publish
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
-> Iso
     (Maybe (HashMap Text MessageAttributeValue))
     (Maybe (HashMap Text MessageAttributeValue))
     (Maybe (HashMap Text MessageAttributeValue))
     (Maybe (HashMap Text MessageAttributeValue))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
  (HashMap Text MessageAttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The topic you want to publish to.
--
-- If you don\'t specify a value for the @TopicArn@ parameter, you must
-- specify a value for the @PhoneNumber@ or @TargetArn@ parameters.
publish_topicArn :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_topicArn :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_topicArn = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
topicArn :: Maybe Text
$sel:topicArn:Publish' :: Publish -> Maybe Text
topicArn} -> Maybe Text
topicArn) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:topicArn:Publish' :: Maybe Text
topicArn = Maybe Text
a} :: Publish)

-- | The phone number to which you want to deliver an SMS message. Use E.164
-- format.
--
-- If you don\'t specify a value for the @PhoneNumber@ parameter, you must
-- specify a value for the @TargetArn@ or @TopicArn@ parameters.
publish_phoneNumber :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_phoneNumber :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_phoneNumber = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
phoneNumber :: Maybe Text
$sel:phoneNumber:Publish' :: Publish -> Maybe Text
phoneNumber} -> Maybe Text
phoneNumber) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:phoneNumber:Publish' :: Maybe Text
phoneNumber = Maybe Text
a} :: Publish)

-- | This parameter applies only to FIFO (first-in-first-out) topics. The
-- @MessageDeduplicationId@ can contain up to 128 alphanumeric characters
-- (a-z, A-Z, 0-9) and punctuation
-- @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
--
-- Every message must have a unique @MessageDeduplicationId@, which is a
-- token used for deduplication of sent messages. If a message with a
-- particular @MessageDeduplicationId@ is sent successfully, any message
-- sent with the same @MessageDeduplicationId@ during the 5-minute
-- deduplication interval is treated as a duplicate.
--
-- If the topic has @ContentBasedDeduplication@ set, the system generates a
-- @MessageDeduplicationId@ based on the contents of the message. Your
-- @MessageDeduplicationId@ overrides the generated one.
publish_messageDeduplicationId :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_messageDeduplicationId :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_messageDeduplicationId = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
messageDeduplicationId :: Maybe Text
$sel:messageDeduplicationId:Publish' :: Publish -> Maybe Text
messageDeduplicationId} -> Maybe Text
messageDeduplicationId) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:messageDeduplicationId:Publish' :: Maybe Text
messageDeduplicationId = Maybe Text
a} :: Publish)

-- | Set @MessageStructure@ to @json@ if you want to send a different message
-- for each protocol. For example, using one publish action, you can send a
-- short message to your SMS subscribers and a longer message to your email
-- subscribers. If you set @MessageStructure@ to @json@, the value of the
-- @Message@ parameter must:
--
-- -   be a syntactically valid JSON object; and
--
-- -   contain at least a top-level JSON key of \"default\" with a value
--     that is a string.
--
-- You can define other top-level keys that define the message you want to
-- send to a specific transport protocol (e.g., \"http\").
--
-- Valid value: @json@
publish_messageStructure :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_messageStructure :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_messageStructure = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
messageStructure :: Maybe Text
$sel:messageStructure:Publish' :: Publish -> Maybe Text
messageStructure} -> Maybe Text
messageStructure) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:messageStructure:Publish' :: Maybe Text
messageStructure = Maybe Text
a} :: Publish)

-- | This parameter applies only to FIFO (first-in-first-out) topics. The
-- @MessageGroupId@ can contain up to 128 alphanumeric characters (a-z,
-- A-Z, 0-9) and punctuation @(!\"#$%&\'()*+,-.\/:;\<=>?\@[\\]^_\`{|}~)@.
--
-- The @MessageGroupId@ is a tag that specifies that a message belongs to a
-- specific message group. Messages that belong to the same message group
-- are processed in a FIFO manner (however, messages in different message
-- groups might be processed out of order). Every message must include a
-- @MessageGroupId@.
publish_messageGroupId :: Lens.Lens' Publish (Prelude.Maybe Prelude.Text)
publish_messageGroupId :: (Maybe Text -> f (Maybe Text)) -> Publish -> f Publish
publish_messageGroupId = (Publish -> Maybe Text)
-> (Publish -> Maybe Text -> Publish)
-> Lens Publish Publish (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Maybe Text
messageGroupId :: Maybe Text
$sel:messageGroupId:Publish' :: Publish -> Maybe Text
messageGroupId} -> Maybe Text
messageGroupId) (\s :: Publish
s@Publish' {} Maybe Text
a -> Publish
s {$sel:messageGroupId:Publish' :: Maybe Text
messageGroupId = Maybe Text
a} :: Publish)

-- | The message you want to send.
--
-- If you are publishing to a topic and you want to send the same message
-- to all transport protocols, include the text of the message as a String
-- value. If you want to send different messages for each transport
-- protocol, set the value of the @MessageStructure@ parameter to @json@
-- and use a JSON object for the @Message@ parameter.
--
-- Constraints:
--
-- -   With the exception of SMS, messages must be UTF-8 encoded strings
--     and at most 256 KB in size (262,144 bytes, not 262,144 characters).
--
-- -   For SMS, each message can contain up to 140 characters. This
--     character limit depends on the encoding schema. For example, an SMS
--     message can contain 160 GSM characters, 140 ASCII characters, or 70
--     UCS-2 characters.
--
--     If you publish a message that exceeds this size limit, Amazon SNS
--     sends the message as multiple messages, each fitting within the size
--     limit. Messages aren\'t truncated mid-word but are cut off at
--     whole-word boundaries.
--
--     The total size limit for a single SMS @Publish@ action is 1,600
--     characters.
--
-- JSON-specific constraints:
--
-- -   Keys in the JSON object that correspond to supported transport
--     protocols must have simple JSON string values.
--
-- -   The values will be parsed (unescaped) before they are used in
--     outgoing messages.
--
-- -   Outbound notifications are JSON encoded (meaning that the characters
--     will be reescaped for sending).
--
-- -   Values have a minimum length of 0 (the empty string, \"\", is
--     allowed).
--
-- -   Values have a maximum length bounded by the overall message size
--     (so, including multiple protocols may limit message sizes).
--
-- -   Non-string values will cause the key to be ignored.
--
-- -   Keys that do not correspond to supported transport protocols are
--     ignored.
--
-- -   Duplicate keys are not allowed.
--
-- -   Failure to parse or validate any key or value in the message will
--     cause the @Publish@ call to return an error (no partial delivery).
publish_message :: Lens.Lens' Publish Prelude.Text
publish_message :: (Text -> f Text) -> Publish -> f Publish
publish_message = (Publish -> Text)
-> (Publish -> Text -> Publish) -> Lens Publish Publish Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Publish' {Text
message :: Text
$sel:message:Publish' :: Publish -> Text
message} -> Text
message) (\s :: Publish
s@Publish' {} Text
a -> Publish
s {$sel:message:Publish' :: Text
message = Text
a} :: Publish)

instance Core.AWSRequest Publish where
  type AWSResponse Publish = PublishResponse
  request :: Publish -> Request Publish
request = Service -> Publish -> Request Publish
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy Publish
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Publish)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse Publish))
-> Logger
-> Service
-> Proxy Publish
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Publish)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"PublishResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Maybe Text -> Int -> PublishResponse
PublishResponse'
            (Maybe Text -> Maybe Text -> Int -> PublishResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> PublishResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"SequenceNumber")
            Either String (Maybe Text -> Int -> PublishResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PublishResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MessageId")
            Either String (Int -> PublishResponse)
-> Either String Int -> Either String PublishResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Publish

instance Prelude.NFData Publish

instance Core.ToHeaders Publish where
  toHeaders :: Publish -> ResponseHeaders
toHeaders = ResponseHeaders -> Publish -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath Publish where
  toPath :: Publish -> ByteString
toPath = ByteString -> Publish -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery Publish where
  toQuery :: Publish -> QueryString
toQuery Publish' {Maybe Text
Maybe (HashMap Text MessageAttributeValue)
Text
message :: Text
messageGroupId :: Maybe Text
messageStructure :: Maybe Text
messageDeduplicationId :: Maybe Text
phoneNumber :: Maybe Text
topicArn :: Maybe Text
messageAttributes :: Maybe (HashMap Text MessageAttributeValue)
targetArn :: Maybe Text
subject :: Maybe Text
$sel:message:Publish' :: Publish -> Text
$sel:messageGroupId:Publish' :: Publish -> Maybe Text
$sel:messageStructure:Publish' :: Publish -> Maybe Text
$sel:messageDeduplicationId:Publish' :: Publish -> Maybe Text
$sel:phoneNumber:Publish' :: Publish -> Maybe Text
$sel:topicArn:Publish' :: Publish -> Maybe Text
$sel:messageAttributes:Publish' :: Publish -> Maybe (HashMap Text MessageAttributeValue)
$sel:targetArn:Publish' :: Publish -> Maybe Text
$sel:subject:Publish' :: Publish -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action" ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"Publish" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-03-31" :: Prelude.ByteString),
        ByteString
"Subject" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
subject,
        ByteString
"TargetArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
targetArn,
        ByteString
"MessageAttributes"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString
-> ByteString
-> ByteString
-> HashMap Text MessageAttributeValue
-> QueryString
forall k v.
(ToQuery k, ToQuery v) =>
ByteString
-> ByteString -> ByteString -> HashMap k v -> QueryString
Core.toQueryMap ByteString
"entry" ByteString
"Name" ByteString
"Value"
                (HashMap Text MessageAttributeValue -> QueryString)
-> Maybe (HashMap Text MessageAttributeValue) -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text MessageAttributeValue)
messageAttributes
            ),
        ByteString
"TopicArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
topicArn,
        ByteString
"PhoneNumber" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
phoneNumber,
        ByteString
"MessageDeduplicationId"
          ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
messageDeduplicationId,
        ByteString
"MessageStructure" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
messageStructure,
        ByteString
"MessageGroupId" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
messageGroupId,
        ByteString
"Message" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
message
      ]

-- | Response for Publish action.
--
-- /See:/ 'newPublishResponse' smart constructor.
data PublishResponse = PublishResponse'
  { -- | This response element applies only to FIFO (first-in-first-out) topics.
    --
    -- The sequence number is a large, non-consecutive number that Amazon SNS
    -- assigns to each message. The length of @SequenceNumber@ is 128 bits.
    -- @SequenceNumber@ continues to increase for each @MessageGroupId@.
    PublishResponse -> Maybe Text
sequenceNumber :: Prelude.Maybe Prelude.Text,
    -- | Unique identifier assigned to the published message.
    --
    -- Length Constraint: Maximum 100 characters
    PublishResponse -> Maybe Text
messageId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    PublishResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PublishResponse -> PublishResponse -> Bool
(PublishResponse -> PublishResponse -> Bool)
-> (PublishResponse -> PublishResponse -> Bool)
-> Eq PublishResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PublishResponse -> PublishResponse -> Bool
$c/= :: PublishResponse -> PublishResponse -> Bool
== :: PublishResponse -> PublishResponse -> Bool
$c== :: PublishResponse -> PublishResponse -> Bool
Prelude.Eq, ReadPrec [PublishResponse]
ReadPrec PublishResponse
Int -> ReadS PublishResponse
ReadS [PublishResponse]
(Int -> ReadS PublishResponse)
-> ReadS [PublishResponse]
-> ReadPrec PublishResponse
-> ReadPrec [PublishResponse]
-> Read PublishResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PublishResponse]
$creadListPrec :: ReadPrec [PublishResponse]
readPrec :: ReadPrec PublishResponse
$creadPrec :: ReadPrec PublishResponse
readList :: ReadS [PublishResponse]
$creadList :: ReadS [PublishResponse]
readsPrec :: Int -> ReadS PublishResponse
$creadsPrec :: Int -> ReadS PublishResponse
Prelude.Read, Int -> PublishResponse -> ShowS
[PublishResponse] -> ShowS
PublishResponse -> String
(Int -> PublishResponse -> ShowS)
-> (PublishResponse -> String)
-> ([PublishResponse] -> ShowS)
-> Show PublishResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PublishResponse] -> ShowS
$cshowList :: [PublishResponse] -> ShowS
show :: PublishResponse -> String
$cshow :: PublishResponse -> String
showsPrec :: Int -> PublishResponse -> ShowS
$cshowsPrec :: Int -> PublishResponse -> ShowS
Prelude.Show, (forall x. PublishResponse -> Rep PublishResponse x)
-> (forall x. Rep PublishResponse x -> PublishResponse)
-> Generic PublishResponse
forall x. Rep PublishResponse x -> PublishResponse
forall x. PublishResponse -> Rep PublishResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PublishResponse x -> PublishResponse
$cfrom :: forall x. PublishResponse -> Rep PublishResponse x
Prelude.Generic)

-- |
-- Create a value of 'PublishResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'sequenceNumber', 'publishResponse_sequenceNumber' - This response element applies only to FIFO (first-in-first-out) topics.
--
-- The sequence number is a large, non-consecutive number that Amazon SNS
-- assigns to each message. The length of @SequenceNumber@ is 128 bits.
-- @SequenceNumber@ continues to increase for each @MessageGroupId@.
--
-- 'messageId', 'publishResponse_messageId' - Unique identifier assigned to the published message.
--
-- Length Constraint: Maximum 100 characters
--
-- 'httpStatus', 'publishResponse_httpStatus' - The response's http status code.
newPublishResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PublishResponse
newPublishResponse :: Int -> PublishResponse
newPublishResponse Int
pHttpStatus_ =
  PublishResponse' :: Maybe Text -> Maybe Text -> Int -> PublishResponse
PublishResponse'
    { $sel:sequenceNumber:PublishResponse' :: Maybe Text
sequenceNumber = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageId:PublishResponse' :: Maybe Text
messageId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PublishResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | This response element applies only to FIFO (first-in-first-out) topics.
--
-- The sequence number is a large, non-consecutive number that Amazon SNS
-- assigns to each message. The length of @SequenceNumber@ is 128 bits.
-- @SequenceNumber@ continues to increase for each @MessageGroupId@.
publishResponse_sequenceNumber :: Lens.Lens' PublishResponse (Prelude.Maybe Prelude.Text)
publishResponse_sequenceNumber :: (Maybe Text -> f (Maybe Text))
-> PublishResponse -> f PublishResponse
publishResponse_sequenceNumber = (PublishResponse -> Maybe Text)
-> (PublishResponse -> Maybe Text -> PublishResponse)
-> Lens PublishResponse PublishResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishResponse' {Maybe Text
sequenceNumber :: Maybe Text
$sel:sequenceNumber:PublishResponse' :: PublishResponse -> Maybe Text
sequenceNumber} -> Maybe Text
sequenceNumber) (\s :: PublishResponse
s@PublishResponse' {} Maybe Text
a -> PublishResponse
s {$sel:sequenceNumber:PublishResponse' :: Maybe Text
sequenceNumber = Maybe Text
a} :: PublishResponse)

-- | Unique identifier assigned to the published message.
--
-- Length Constraint: Maximum 100 characters
publishResponse_messageId :: Lens.Lens' PublishResponse (Prelude.Maybe Prelude.Text)
publishResponse_messageId :: (Maybe Text -> f (Maybe Text))
-> PublishResponse -> f PublishResponse
publishResponse_messageId = (PublishResponse -> Maybe Text)
-> (PublishResponse -> Maybe Text -> PublishResponse)
-> Lens PublishResponse PublishResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishResponse' {Maybe Text
messageId :: Maybe Text
$sel:messageId:PublishResponse' :: PublishResponse -> Maybe Text
messageId} -> Maybe Text
messageId) (\s :: PublishResponse
s@PublishResponse' {} Maybe Text
a -> PublishResponse
s {$sel:messageId:PublishResponse' :: Maybe Text
messageId = Maybe Text
a} :: PublishResponse)

-- | The response's http status code.
publishResponse_httpStatus :: Lens.Lens' PublishResponse Prelude.Int
publishResponse_httpStatus :: (Int -> f Int) -> PublishResponse -> f PublishResponse
publishResponse_httpStatus = (PublishResponse -> Int)
-> (PublishResponse -> Int -> PublishResponse)
-> Lens PublishResponse PublishResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishResponse' {Int
httpStatus :: Int
$sel:httpStatus:PublishResponse' :: PublishResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PublishResponse
s@PublishResponse' {} Int
a -> PublishResponse
s {$sel:httpStatus:PublishResponse' :: Int
httpStatus = Int
a} :: PublishResponse)

instance Prelude.NFData PublishResponse