{-# 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.ConnectParticipant.SendMessage
-- 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. Note that ConnectionToken is used for invoking this API
-- instead of ParticipantToken.
--
-- The Amazon Connect Participant Service APIs do not use
-- <https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Signature Version 4 authentication>.
module Amazonka.ConnectParticipant.SendMessage
  ( -- * Creating a Request
    SendMessage (..),
    newSendMessage,

    -- * Request Lenses
    sendMessage_clientToken,
    sendMessage_contentType,
    sendMessage_content,
    sendMessage_connectionToken,

    -- * Destructuring the Response
    SendMessageResponse (..),
    newSendMessageResponse,

    -- * Response Lenses
    sendMessageResponse_absoluteTime,
    sendMessageResponse_id,
    sendMessageResponse_httpStatus,
  )
where

import Amazonka.ConnectParticipant.Types
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

-- | /See:/ 'newSendMessage' smart constructor.
data SendMessage = SendMessage'
  { -- | A unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request.
    SendMessage -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The type of the content. Supported types are text\/plain.
    SendMessage -> Text
contentType :: Prelude.Text,
    -- | The content of the message.
    SendMessage -> Text
content :: Prelude.Text,
    -- | The authentication token associated with the connection.
    SendMessage -> Text
connectionToken :: Prelude.Text
  }
  deriving (SendMessage -> SendMessage -> Bool
(SendMessage -> SendMessage -> Bool)
-> (SendMessage -> SendMessage -> Bool) -> Eq SendMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendMessage -> SendMessage -> Bool
$c/= :: SendMessage -> SendMessage -> Bool
== :: SendMessage -> SendMessage -> Bool
$c== :: SendMessage -> SendMessage -> Bool
Prelude.Eq, ReadPrec [SendMessage]
ReadPrec SendMessage
Int -> ReadS SendMessage
ReadS [SendMessage]
(Int -> ReadS SendMessage)
-> ReadS [SendMessage]
-> ReadPrec SendMessage
-> ReadPrec [SendMessage]
-> Read SendMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendMessage]
$creadListPrec :: ReadPrec [SendMessage]
readPrec :: ReadPrec SendMessage
$creadPrec :: ReadPrec SendMessage
readList :: ReadS [SendMessage]
$creadList :: ReadS [SendMessage]
readsPrec :: Int -> ReadS SendMessage
$creadsPrec :: Int -> ReadS SendMessage
Prelude.Read, Int -> SendMessage -> ShowS
[SendMessage] -> ShowS
SendMessage -> String
(Int -> SendMessage -> ShowS)
-> (SendMessage -> String)
-> ([SendMessage] -> ShowS)
-> Show SendMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendMessage] -> ShowS
$cshowList :: [SendMessage] -> ShowS
show :: SendMessage -> String
$cshow :: SendMessage -> String
showsPrec :: Int -> SendMessage -> ShowS
$cshowsPrec :: Int -> SendMessage -> ShowS
Prelude.Show, (forall x. SendMessage -> Rep SendMessage x)
-> (forall x. Rep SendMessage x -> SendMessage)
-> Generic SendMessage
forall x. Rep SendMessage x -> SendMessage
forall x. SendMessage -> Rep SendMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendMessage x -> SendMessage
$cfrom :: forall x. SendMessage -> Rep SendMessage x
Prelude.Generic)

-- |
-- Create a value of 'SendMessage' 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:
--
-- 'clientToken', 'sendMessage_clientToken' - A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
--
-- 'contentType', 'sendMessage_contentType' - The type of the content. Supported types are text\/plain.
--
-- 'content', 'sendMessage_content' - The content of the message.
--
-- 'connectionToken', 'sendMessage_connectionToken' - The authentication token associated with the connection.
newSendMessage ::
  -- | 'contentType'
  Prelude.Text ->
  -- | 'content'
  Prelude.Text ->
  -- | 'connectionToken'
  Prelude.Text ->
  SendMessage
newSendMessage :: Text -> Text -> Text -> SendMessage
newSendMessage
  Text
pContentType_
  Text
pContent_
  Text
pConnectionToken_ =
    SendMessage' :: Maybe Text -> Text -> Text -> Text -> SendMessage
SendMessage'
      { $sel:clientToken:SendMessage' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:contentType:SendMessage' :: Text
contentType = Text
pContentType_,
        $sel:content:SendMessage' :: Text
content = Text
pContent_,
        $sel:connectionToken:SendMessage' :: Text
connectionToken = Text
pConnectionToken_
      }

-- | A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
sendMessage_clientToken :: Lens.Lens' SendMessage (Prelude.Maybe Prelude.Text)
sendMessage_clientToken :: (Maybe Text -> f (Maybe Text)) -> SendMessage -> f SendMessage
sendMessage_clientToken = (SendMessage -> Maybe Text)
-> (SendMessage -> Maybe Text -> SendMessage)
-> Lens SendMessage SendMessage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessage' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:SendMessage' :: SendMessage -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: SendMessage
s@SendMessage' {} Maybe Text
a -> SendMessage
s {$sel:clientToken:SendMessage' :: Maybe Text
clientToken = Maybe Text
a} :: SendMessage)

-- | The type of the content. Supported types are text\/plain.
sendMessage_contentType :: Lens.Lens' SendMessage Prelude.Text
sendMessage_contentType :: (Text -> f Text) -> SendMessage -> f SendMessage
sendMessage_contentType = (SendMessage -> Text)
-> (SendMessage -> Text -> SendMessage)
-> Lens SendMessage SendMessage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessage' {Text
contentType :: Text
$sel:contentType:SendMessage' :: SendMessage -> Text
contentType} -> Text
contentType) (\s :: SendMessage
s@SendMessage' {} Text
a -> SendMessage
s {$sel:contentType:SendMessage' :: Text
contentType = Text
a} :: SendMessage)

-- | The content of the message.
sendMessage_content :: Lens.Lens' SendMessage Prelude.Text
sendMessage_content :: (Text -> f Text) -> SendMessage -> f SendMessage
sendMessage_content = (SendMessage -> Text)
-> (SendMessage -> Text -> SendMessage)
-> Lens SendMessage SendMessage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessage' {Text
content :: Text
$sel:content:SendMessage' :: SendMessage -> Text
content} -> Text
content) (\s :: SendMessage
s@SendMessage' {} Text
a -> SendMessage
s {$sel:content:SendMessage' :: Text
content = Text
a} :: SendMessage)

-- | The authentication token associated with the connection.
sendMessage_connectionToken :: Lens.Lens' SendMessage Prelude.Text
sendMessage_connectionToken :: (Text -> f Text) -> SendMessage -> f SendMessage
sendMessage_connectionToken = (SendMessage -> Text)
-> (SendMessage -> Text -> SendMessage)
-> Lens SendMessage SendMessage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessage' {Text
connectionToken :: Text
$sel:connectionToken:SendMessage' :: SendMessage -> Text
connectionToken} -> Text
connectionToken) (\s :: SendMessage
s@SendMessage' {} Text
a -> SendMessage
s {$sel:connectionToken:SendMessage' :: Text
connectionToken = Text
a} :: SendMessage)

instance Core.AWSRequest SendMessage where
  type AWSResponse SendMessage = SendMessageResponse
  request :: SendMessage -> Request SendMessage
request = Service -> SendMessage -> Request SendMessage
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SendMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SendMessage)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse SendMessage))
-> Logger
-> Service
-> Proxy SendMessage
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SendMessage)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe Text -> Int -> SendMessageResponse
SendMessageResponse'
            (Maybe Text -> Maybe Text -> Int -> SendMessageResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> SendMessageResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"AbsoluteTime")
            Either String (Maybe Text -> Int -> SendMessageResponse)
-> Either String (Maybe Text)
-> Either String (Int -> SendMessageResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Id")
            Either String (Int -> SendMessageResponse)
-> Either String Int -> Either String SendMessageResponse
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 SendMessage

instance Prelude.NFData SendMessage

instance Core.ToHeaders SendMessage where
  toHeaders :: SendMessage -> ResponseHeaders
toHeaders SendMessage' {Maybe Text
Text
connectionToken :: Text
content :: Text
contentType :: Text
clientToken :: Maybe Text
$sel:connectionToken:SendMessage' :: SendMessage -> Text
$sel:content:SendMessage' :: SendMessage -> Text
$sel:contentType:SendMessage' :: SendMessage -> Text
$sel:clientToken:SendMessage' :: SendMessage -> Maybe Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"X-Amz-Bearer" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
connectionToken,
        HeaderName
"Content-Type"
          HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/x-amz-json-1.1" :: Prelude.ByteString)
      ]

instance Core.ToJSON SendMessage where
  toJSON :: SendMessage -> Value
toJSON SendMessage' {Maybe Text
Text
connectionToken :: Text
content :: Text
contentType :: Text
clientToken :: Maybe Text
$sel:connectionToken:SendMessage' :: SendMessage -> Text
$sel:content:SendMessage' :: SendMessage -> Text
$sel:contentType:SendMessage' :: SendMessage -> Text
$sel:clientToken:SendMessage' :: SendMessage -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
clientToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ContentType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
contentType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Content" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
content)
          ]
      )

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

instance Core.ToQuery SendMessage where
  toQuery :: SendMessage -> QueryString
toQuery = QueryString -> SendMessage -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newSendMessageResponse' smart constructor.
data SendMessageResponse = SendMessageResponse'
  { -- | The time when the message was sent.
    --
    -- It\'s specified in ISO 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For
    -- example, 2019-11-08T02:41:28.172Z.
    SendMessageResponse -> Maybe Text
absoluteTime :: Prelude.Maybe Prelude.Text,
    -- | The ID of the message.
    SendMessageResponse -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    SendMessageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SendMessageResponse -> SendMessageResponse -> Bool
(SendMessageResponse -> SendMessageResponse -> Bool)
-> (SendMessageResponse -> SendMessageResponse -> Bool)
-> Eq SendMessageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SendMessageResponse -> SendMessageResponse -> Bool
$c/= :: SendMessageResponse -> SendMessageResponse -> Bool
== :: SendMessageResponse -> SendMessageResponse -> Bool
$c== :: SendMessageResponse -> SendMessageResponse -> Bool
Prelude.Eq, ReadPrec [SendMessageResponse]
ReadPrec SendMessageResponse
Int -> ReadS SendMessageResponse
ReadS [SendMessageResponse]
(Int -> ReadS SendMessageResponse)
-> ReadS [SendMessageResponse]
-> ReadPrec SendMessageResponse
-> ReadPrec [SendMessageResponse]
-> Read SendMessageResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendMessageResponse]
$creadListPrec :: ReadPrec [SendMessageResponse]
readPrec :: ReadPrec SendMessageResponse
$creadPrec :: ReadPrec SendMessageResponse
readList :: ReadS [SendMessageResponse]
$creadList :: ReadS [SendMessageResponse]
readsPrec :: Int -> ReadS SendMessageResponse
$creadsPrec :: Int -> ReadS SendMessageResponse
Prelude.Read, Int -> SendMessageResponse -> ShowS
[SendMessageResponse] -> ShowS
SendMessageResponse -> String
(Int -> SendMessageResponse -> ShowS)
-> (SendMessageResponse -> String)
-> ([SendMessageResponse] -> ShowS)
-> Show SendMessageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendMessageResponse] -> ShowS
$cshowList :: [SendMessageResponse] -> ShowS
show :: SendMessageResponse -> String
$cshow :: SendMessageResponse -> String
showsPrec :: Int -> SendMessageResponse -> ShowS
$cshowsPrec :: Int -> SendMessageResponse -> ShowS
Prelude.Show, (forall x. SendMessageResponse -> Rep SendMessageResponse x)
-> (forall x. Rep SendMessageResponse x -> SendMessageResponse)
-> Generic SendMessageResponse
forall x. Rep SendMessageResponse x -> SendMessageResponse
forall x. SendMessageResponse -> Rep SendMessageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendMessageResponse x -> SendMessageResponse
$cfrom :: forall x. SendMessageResponse -> Rep SendMessageResponse x
Prelude.Generic)

-- |
-- Create a value of 'SendMessageResponse' 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:
--
-- 'absoluteTime', 'sendMessageResponse_absoluteTime' - The time when the message was sent.
--
-- It\'s specified in ISO 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For
-- example, 2019-11-08T02:41:28.172Z.
--
-- 'id', 'sendMessageResponse_id' - The ID of the message.
--
-- 'httpStatus', 'sendMessageResponse_httpStatus' - The response's http status code.
newSendMessageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SendMessageResponse
newSendMessageResponse :: Int -> SendMessageResponse
newSendMessageResponse Int
pHttpStatus_ =
  SendMessageResponse' :: Maybe Text -> Maybe Text -> Int -> SendMessageResponse
SendMessageResponse'
    { $sel:absoluteTime:SendMessageResponse' :: Maybe Text
absoluteTime =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:SendMessageResponse' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SendMessageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The time when the message was sent.
--
-- It\'s specified in ISO 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ. For
-- example, 2019-11-08T02:41:28.172Z.
sendMessageResponse_absoluteTime :: Lens.Lens' SendMessageResponse (Prelude.Maybe Prelude.Text)
sendMessageResponse_absoluteTime :: (Maybe Text -> f (Maybe Text))
-> SendMessageResponse -> f SendMessageResponse
sendMessageResponse_absoluteTime = (SendMessageResponse -> Maybe Text)
-> (SendMessageResponse -> Maybe Text -> SendMessageResponse)
-> Lens
     SendMessageResponse SendMessageResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessageResponse' {Maybe Text
absoluteTime :: Maybe Text
$sel:absoluteTime:SendMessageResponse' :: SendMessageResponse -> Maybe Text
absoluteTime} -> Maybe Text
absoluteTime) (\s :: SendMessageResponse
s@SendMessageResponse' {} Maybe Text
a -> SendMessageResponse
s {$sel:absoluteTime:SendMessageResponse' :: Maybe Text
absoluteTime = Maybe Text
a} :: SendMessageResponse)

-- | The ID of the message.
sendMessageResponse_id :: Lens.Lens' SendMessageResponse (Prelude.Maybe Prelude.Text)
sendMessageResponse_id :: (Maybe Text -> f (Maybe Text))
-> SendMessageResponse -> f SendMessageResponse
sendMessageResponse_id = (SendMessageResponse -> Maybe Text)
-> (SendMessageResponse -> Maybe Text -> SendMessageResponse)
-> Lens
     SendMessageResponse SendMessageResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SendMessageResponse' {Maybe Text
id :: Maybe Text
$sel:id:SendMessageResponse' :: SendMessageResponse -> Maybe Text
id} -> Maybe Text
id) (\s :: SendMessageResponse
s@SendMessageResponse' {} Maybe Text
a -> SendMessageResponse
s {$sel:id:SendMessageResponse' :: Maybe Text
id = Maybe Text
a} :: SendMessageResponse)

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

instance Prelude.NFData SendMessageResponse