{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Dialogflow.V2.Fulfillment.Webhook.Response where
import Data.Aeson ( parseJSON
, toJSON
, withObject
, FromJSON
, ToJSON
, (.:)
, (.=) )
import Dialogflow.Util (noNullObjects)
import qualified Data.Map as M
import Dialogflow.V2.Fulfillment.Webhook.Request (Context)
import Dialogflow.V2.Fulfillment.Message
import qualified Dialogflow.V2.Fulfillment.Payload.Google as G
data EventInput =
EventInput { eventInputName :: String
, eventInputParameters :: Maybe (M.Map String String)
, eventInputLanguageCode :: String
} deriving (Eq, Show)
instance FromJSON EventInput where
parseJSON = withObject "eventInput" $ \ei -> do
eventInputName <- ei .: "name"
eventInputParameters <- ei .: "parameters"
eventInputLanguageCode <- ei .: "language_code"
return EventInput{..}
instance ToJSON EventInput where
toJSON EventInput{..} =
noNullObjects [ "name" .= eventInputName
, "parameters" .= eventInputParameters
, "language_code" .= eventInputLanguageCode ]
data WebhookResponse = WebhookResponse
{ fulfillmentText :: Maybe String
, fulfillmentMessages :: Maybe [Message]
, source :: Maybe String
, payload :: Maybe G.GooglePayload
, outputContexts :: Maybe [Context]
, followupEventInput :: Maybe EventInput
} deriving (Eq, Show)
instance ToJSON WebhookResponse where
toJSON WebhookResponse{..} =
noNullObjects [ "fulfillmentText" .= fulfillmentText
, "fulfillmentMessages" .= fulfillmentMessages
, "source" .= source
, "payload" .= payload
, "outputContexts" .= outputContexts
, "followupEventInput" .= followupEventInput ]