module Web.Slack.Types.Message where
import Data.Aeson
import Data.Aeson.TH
import qualified Data.Text as T
import Data.Time.Clock.POSIX
import GHC.Generics
import Web.Slack.Types.Base
import Web.Slack.Types.Id
import Web.Slack.Utils
data MessagePayload = MessagePayload
{ messageId :: Int
, messageType :: T.Text
, messageChannel :: ChannelId
, messageText :: T.Text
} deriving (Show)
data PingPayload = PingPayload
{ pingId :: Int
, pingType :: T.Text
, pingTimestamp :: Int
} deriving (Show)
data Attachment = Attachment
{ attachmentFallback :: T.Text
, attachmentColor :: AttachmentColor
, attachmentPretext :: Maybe T.Text
, attachmentAuthorName :: Maybe T.Text
, attachmentAuthorLink :: Maybe URL
, attachmentAuthorIcon :: Maybe URL
, attachmentTitle :: Maybe T.Text
, attachmentTitleLink :: Maybe URL
, attachmentText :: Maybe T.Text
, attachmentFields :: [Field]
, attachmentImageUrl :: Maybe URL
, attachmentThumbUrl :: Maybe URL
, attachmentFooter :: Maybe T.Text
, attachmentFooterIcon :: Maybe URL
, attachmentTs :: Maybe POSIXTime
}
data Field = Field
{ fieldTitle :: Maybe T.Text
, fieldValue :: T.Text
, fieldShort :: Bool
}
data AttachmentColor
= DefaultColor
| GoodColor
| WarningColor
| DangerColor
| CustomColor T.Text
deriving (Generic)
defaultAttachment :: Attachment
defaultAttachment = Attachment
{ attachmentFallback = ""
, attachmentColor = DefaultColor
, attachmentPretext = Nothing
, attachmentAuthorName = Nothing
, attachmentAuthorLink = Nothing
, attachmentAuthorIcon = Nothing
, attachmentTitle = Nothing
, attachmentTitleLink = Nothing
, attachmentText = Nothing
, attachmentFields = []
, attachmentImageUrl = Nothing
, attachmentThumbUrl = Nothing
, attachmentFooter = Nothing
, attachmentFooterIcon = Nothing
, attachmentTs = Nothing
}
instance ToJSON AttachmentColor where
toEncoding x = toEncoding $ case x of
DefaultColor -> Nothing
GoodColor -> Just "good"
WarningColor -> Just "warning"
DangerColor -> Just "danger"
CustomColor c -> Just c
$(deriveToJSON defaultOptions {fieldLabelModifier = toSnake . drop 7} ''MessagePayload)
$(deriveToJSON defaultOptions {fieldLabelModifier = toSnake . drop 4} ''PingPayload)
$(deriveToJSON defaultOptions {fieldLabelModifier = toSnake . drop 10} ''Attachment)
$(deriveToJSON defaultOptions {fieldLabelModifier = toSnake . drop 5} ''Field)