{-# 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.Connect.UpdateContactAttributes
-- 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)
--
-- Creates or updates user-defined contact attributes associated with the
-- specified contact.
--
-- You can create or update user-defined attributes for both ongoing and
-- completed contacts. For example, while the call is active, you can
-- update the customer\'s name or the reason the customer called. You can
-- add notes about steps that the agent took during the call that display
-- to the next agent that takes the call. You can also update attributes
-- for a contact using data from your CRM application and save the data
-- with the contact in Amazon Connect. You could also flag calls for
-- additional analysis, such as legal review or to identify abusive
-- callers.
--
-- Contact attributes are available in Amazon Connect for 24 months, and
-- are then deleted. For information about CTR retention and the maximum
-- size of the CTR attributes section, see
-- <https://docs.aws.amazon.com/connect/latest/adminguide/amazon-connect-service-limits.html#feature-limits Feature specifications>
-- in the /Amazon Connect Administrator Guide/.
--
-- __Important:__ You cannot use the operation to update attributes for
-- contacts that occurred prior to the release of the API, which was
-- September 12, 2018. You can update attributes only for contacts that
-- started after the release of the API. If you attempt to update
-- attributes for a contact that occurred prior to the release of the API,
-- a 400 error is returned. This applies also to queued callbacks that were
-- initiated prior to the release of the API but are still active in your
-- instance.
module Amazonka.Connect.UpdateContactAttributes
  ( -- * Creating a Request
    UpdateContactAttributes (..),
    newUpdateContactAttributes,

    -- * Request Lenses
    updateContactAttributes_initialContactId,
    updateContactAttributes_instanceId,
    updateContactAttributes_attributes,

    -- * Destructuring the Response
    UpdateContactAttributesResponse (..),
    newUpdateContactAttributesResponse,

    -- * Response Lenses
    updateContactAttributesResponse_httpStatus,
  )
where

import Amazonka.Connect.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:/ 'newUpdateContactAttributes' smart constructor.
data UpdateContactAttributes = UpdateContactAttributes'
  { -- | The identifier of the contact. This is the identifier of the contact
    -- associated with the first interaction with the contact center.
    UpdateContactAttributes -> Text
initialContactId :: Prelude.Text,
    -- | The identifier of the Amazon Connect instance. You can find the
    -- instanceId in the ARN of the instance.
    UpdateContactAttributes -> Text
instanceId :: Prelude.Text,
    -- | The Amazon Connect attributes. These attributes can be accessed in
    -- contact flows just like any other contact attributes.
    --
    -- You can have up to 32,768 UTF-8 bytes across all attributes for a
    -- contact. Attribute keys can include only alphanumeric, dash, and
    -- underscore characters.
    UpdateContactAttributes -> HashMap Text Text
attributes :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (UpdateContactAttributes -> UpdateContactAttributes -> Bool
(UpdateContactAttributes -> UpdateContactAttributes -> Bool)
-> (UpdateContactAttributes -> UpdateContactAttributes -> Bool)
-> Eq UpdateContactAttributes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateContactAttributes -> UpdateContactAttributes -> Bool
$c/= :: UpdateContactAttributes -> UpdateContactAttributes -> Bool
== :: UpdateContactAttributes -> UpdateContactAttributes -> Bool
$c== :: UpdateContactAttributes -> UpdateContactAttributes -> Bool
Prelude.Eq, ReadPrec [UpdateContactAttributes]
ReadPrec UpdateContactAttributes
Int -> ReadS UpdateContactAttributes
ReadS [UpdateContactAttributes]
(Int -> ReadS UpdateContactAttributes)
-> ReadS [UpdateContactAttributes]
-> ReadPrec UpdateContactAttributes
-> ReadPrec [UpdateContactAttributes]
-> Read UpdateContactAttributes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateContactAttributes]
$creadListPrec :: ReadPrec [UpdateContactAttributes]
readPrec :: ReadPrec UpdateContactAttributes
$creadPrec :: ReadPrec UpdateContactAttributes
readList :: ReadS [UpdateContactAttributes]
$creadList :: ReadS [UpdateContactAttributes]
readsPrec :: Int -> ReadS UpdateContactAttributes
$creadsPrec :: Int -> ReadS UpdateContactAttributes
Prelude.Read, Int -> UpdateContactAttributes -> ShowS
[UpdateContactAttributes] -> ShowS
UpdateContactAttributes -> String
(Int -> UpdateContactAttributes -> ShowS)
-> (UpdateContactAttributes -> String)
-> ([UpdateContactAttributes] -> ShowS)
-> Show UpdateContactAttributes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateContactAttributes] -> ShowS
$cshowList :: [UpdateContactAttributes] -> ShowS
show :: UpdateContactAttributes -> String
$cshow :: UpdateContactAttributes -> String
showsPrec :: Int -> UpdateContactAttributes -> ShowS
$cshowsPrec :: Int -> UpdateContactAttributes -> ShowS
Prelude.Show, (forall x.
 UpdateContactAttributes -> Rep UpdateContactAttributes x)
-> (forall x.
    Rep UpdateContactAttributes x -> UpdateContactAttributes)
-> Generic UpdateContactAttributes
forall x. Rep UpdateContactAttributes x -> UpdateContactAttributes
forall x. UpdateContactAttributes -> Rep UpdateContactAttributes x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateContactAttributes x -> UpdateContactAttributes
$cfrom :: forall x. UpdateContactAttributes -> Rep UpdateContactAttributes x
Prelude.Generic)

-- |
-- Create a value of 'UpdateContactAttributes' 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:
--
-- 'initialContactId', 'updateContactAttributes_initialContactId' - The identifier of the contact. This is the identifier of the contact
-- associated with the first interaction with the contact center.
--
-- 'instanceId', 'updateContactAttributes_instanceId' - The identifier of the Amazon Connect instance. You can find the
-- instanceId in the ARN of the instance.
--
-- 'attributes', 'updateContactAttributes_attributes' - The Amazon Connect attributes. These attributes can be accessed in
-- contact flows just like any other contact attributes.
--
-- You can have up to 32,768 UTF-8 bytes across all attributes for a
-- contact. Attribute keys can include only alphanumeric, dash, and
-- underscore characters.
newUpdateContactAttributes ::
  -- | 'initialContactId'
  Prelude.Text ->
  -- | 'instanceId'
  Prelude.Text ->
  UpdateContactAttributes
newUpdateContactAttributes :: Text -> Text -> UpdateContactAttributes
newUpdateContactAttributes
  Text
pInitialContactId_
  Text
pInstanceId_ =
    UpdateContactAttributes' :: Text -> Text -> HashMap Text Text -> UpdateContactAttributes
UpdateContactAttributes'
      { $sel:initialContactId:UpdateContactAttributes' :: Text
initialContactId =
          Text
pInitialContactId_,
        $sel:instanceId:UpdateContactAttributes' :: Text
instanceId = Text
pInstanceId_,
        $sel:attributes:UpdateContactAttributes' :: HashMap Text Text
attributes = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty
      }

-- | The identifier of the contact. This is the identifier of the contact
-- associated with the first interaction with the contact center.
updateContactAttributes_initialContactId :: Lens.Lens' UpdateContactAttributes Prelude.Text
updateContactAttributes_initialContactId :: (Text -> f Text)
-> UpdateContactAttributes -> f UpdateContactAttributes
updateContactAttributes_initialContactId = (UpdateContactAttributes -> Text)
-> (UpdateContactAttributes -> Text -> UpdateContactAttributes)
-> Lens UpdateContactAttributes UpdateContactAttributes Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateContactAttributes' {Text
initialContactId :: Text
$sel:initialContactId:UpdateContactAttributes' :: UpdateContactAttributes -> Text
initialContactId} -> Text
initialContactId) (\s :: UpdateContactAttributes
s@UpdateContactAttributes' {} Text
a -> UpdateContactAttributes
s {$sel:initialContactId:UpdateContactAttributes' :: Text
initialContactId = Text
a} :: UpdateContactAttributes)

-- | The identifier of the Amazon Connect instance. You can find the
-- instanceId in the ARN of the instance.
updateContactAttributes_instanceId :: Lens.Lens' UpdateContactAttributes Prelude.Text
updateContactAttributes_instanceId :: (Text -> f Text)
-> UpdateContactAttributes -> f UpdateContactAttributes
updateContactAttributes_instanceId = (UpdateContactAttributes -> Text)
-> (UpdateContactAttributes -> Text -> UpdateContactAttributes)
-> Lens UpdateContactAttributes UpdateContactAttributes Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateContactAttributes' {Text
instanceId :: Text
$sel:instanceId:UpdateContactAttributes' :: UpdateContactAttributes -> Text
instanceId} -> Text
instanceId) (\s :: UpdateContactAttributes
s@UpdateContactAttributes' {} Text
a -> UpdateContactAttributes
s {$sel:instanceId:UpdateContactAttributes' :: Text
instanceId = Text
a} :: UpdateContactAttributes)

-- | The Amazon Connect attributes. These attributes can be accessed in
-- contact flows just like any other contact attributes.
--
-- You can have up to 32,768 UTF-8 bytes across all attributes for a
-- contact. Attribute keys can include only alphanumeric, dash, and
-- underscore characters.
updateContactAttributes_attributes :: Lens.Lens' UpdateContactAttributes (Prelude.HashMap Prelude.Text Prelude.Text)
updateContactAttributes_attributes :: (HashMap Text Text -> f (HashMap Text Text))
-> UpdateContactAttributes -> f UpdateContactAttributes
updateContactAttributes_attributes = (UpdateContactAttributes -> HashMap Text Text)
-> (UpdateContactAttributes
    -> HashMap Text Text -> UpdateContactAttributes)
-> Lens
     UpdateContactAttributes
     UpdateContactAttributes
     (HashMap Text Text)
     (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateContactAttributes' {HashMap Text Text
attributes :: HashMap Text Text
$sel:attributes:UpdateContactAttributes' :: UpdateContactAttributes -> HashMap Text Text
attributes} -> HashMap Text Text
attributes) (\s :: UpdateContactAttributes
s@UpdateContactAttributes' {} HashMap Text Text
a -> UpdateContactAttributes
s {$sel:attributes:UpdateContactAttributes' :: HashMap Text Text
attributes = HashMap Text Text
a} :: UpdateContactAttributes) ((HashMap Text Text -> f (HashMap Text Text))
 -> UpdateContactAttributes -> f UpdateContactAttributes)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> UpdateContactAttributes
-> f UpdateContactAttributes
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest UpdateContactAttributes where
  type
    AWSResponse UpdateContactAttributes =
      UpdateContactAttributesResponse
  request :: UpdateContactAttributes -> Request UpdateContactAttributes
request = Service
-> UpdateContactAttributes -> Request UpdateContactAttributes
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateContactAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateContactAttributes)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateContactAttributes))
-> Logger
-> Service
-> Proxy UpdateContactAttributes
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateContactAttributes)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateContactAttributesResponse
UpdateContactAttributesResponse'
            (Int -> UpdateContactAttributesResponse)
-> Either String Int
-> Either String UpdateContactAttributesResponse
forall (f :: * -> *) a b. Functor 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 UpdateContactAttributes

instance Prelude.NFData UpdateContactAttributes

instance Core.ToHeaders UpdateContactAttributes where
  toHeaders :: UpdateContactAttributes -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateContactAttributes -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 UpdateContactAttributes where
  toJSON :: UpdateContactAttributes -> Value
toJSON UpdateContactAttributes' {Text
HashMap Text Text
attributes :: HashMap Text Text
instanceId :: Text
initialContactId :: Text
$sel:attributes:UpdateContactAttributes' :: UpdateContactAttributes -> HashMap Text Text
$sel:instanceId:UpdateContactAttributes' :: UpdateContactAttributes -> Text
$sel:initialContactId:UpdateContactAttributes' :: UpdateContactAttributes -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"InitialContactId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
initialContactId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
attributes)
          ]
      )

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

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

-- | /See:/ 'newUpdateContactAttributesResponse' smart constructor.
data UpdateContactAttributesResponse = UpdateContactAttributesResponse'
  { -- | The response's http status code.
    UpdateContactAttributesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateContactAttributesResponse
-> UpdateContactAttributesResponse -> Bool
(UpdateContactAttributesResponse
 -> UpdateContactAttributesResponse -> Bool)
-> (UpdateContactAttributesResponse
    -> UpdateContactAttributesResponse -> Bool)
-> Eq UpdateContactAttributesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateContactAttributesResponse
-> UpdateContactAttributesResponse -> Bool
$c/= :: UpdateContactAttributesResponse
-> UpdateContactAttributesResponse -> Bool
== :: UpdateContactAttributesResponse
-> UpdateContactAttributesResponse -> Bool
$c== :: UpdateContactAttributesResponse
-> UpdateContactAttributesResponse -> Bool
Prelude.Eq, ReadPrec [UpdateContactAttributesResponse]
ReadPrec UpdateContactAttributesResponse
Int -> ReadS UpdateContactAttributesResponse
ReadS [UpdateContactAttributesResponse]
(Int -> ReadS UpdateContactAttributesResponse)
-> ReadS [UpdateContactAttributesResponse]
-> ReadPrec UpdateContactAttributesResponse
-> ReadPrec [UpdateContactAttributesResponse]
-> Read UpdateContactAttributesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateContactAttributesResponse]
$creadListPrec :: ReadPrec [UpdateContactAttributesResponse]
readPrec :: ReadPrec UpdateContactAttributesResponse
$creadPrec :: ReadPrec UpdateContactAttributesResponse
readList :: ReadS [UpdateContactAttributesResponse]
$creadList :: ReadS [UpdateContactAttributesResponse]
readsPrec :: Int -> ReadS UpdateContactAttributesResponse
$creadsPrec :: Int -> ReadS UpdateContactAttributesResponse
Prelude.Read, Int -> UpdateContactAttributesResponse -> ShowS
[UpdateContactAttributesResponse] -> ShowS
UpdateContactAttributesResponse -> String
(Int -> UpdateContactAttributesResponse -> ShowS)
-> (UpdateContactAttributesResponse -> String)
-> ([UpdateContactAttributesResponse] -> ShowS)
-> Show UpdateContactAttributesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateContactAttributesResponse] -> ShowS
$cshowList :: [UpdateContactAttributesResponse] -> ShowS
show :: UpdateContactAttributesResponse -> String
$cshow :: UpdateContactAttributesResponse -> String
showsPrec :: Int -> UpdateContactAttributesResponse -> ShowS
$cshowsPrec :: Int -> UpdateContactAttributesResponse -> ShowS
Prelude.Show, (forall x.
 UpdateContactAttributesResponse
 -> Rep UpdateContactAttributesResponse x)
-> (forall x.
    Rep UpdateContactAttributesResponse x
    -> UpdateContactAttributesResponse)
-> Generic UpdateContactAttributesResponse
forall x.
Rep UpdateContactAttributesResponse x
-> UpdateContactAttributesResponse
forall x.
UpdateContactAttributesResponse
-> Rep UpdateContactAttributesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateContactAttributesResponse x
-> UpdateContactAttributesResponse
$cfrom :: forall x.
UpdateContactAttributesResponse
-> Rep UpdateContactAttributesResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateContactAttributesResponse' 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:
--
-- 'httpStatus', 'updateContactAttributesResponse_httpStatus' - The response's http status code.
newUpdateContactAttributesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateContactAttributesResponse
newUpdateContactAttributesResponse :: Int -> UpdateContactAttributesResponse
newUpdateContactAttributesResponse Int
pHttpStatus_ =
  UpdateContactAttributesResponse' :: Int -> UpdateContactAttributesResponse
UpdateContactAttributesResponse'
    { $sel:httpStatus:UpdateContactAttributesResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    UpdateContactAttributesResponse