module Network.Haskbot.SlashCommand
(
SlashCom (..)
, fromParams
) where
import Control.Applicative ((<$>), (<*>))
import Data.Text (Text)
import Network.Haskbot.Internal.Environment (HaskbotM)
import Network.Haskbot.Internal.Request (Params, reqParam, optParam)
import Network.Haskbot.Types
import Network.Wai (Request)
data SlashCom
= SlashCom
{ token :: !Token
, teamID :: !TeamID
, channelID :: !ChannelID
, channelName :: !ChannelName
, userID :: !UserID
, userName :: !UserName
, command :: !Command
, optText :: Maybe Text
} deriving (Eq, Show)
fromParams :: Params -> HaskbotM SlashCom
fromParams params =
newSlashCom <$> reqParam' "token"
<*> reqParam' "team_id"
<*> reqParam' "channel_id"
<*> reqParam' "channel_name"
<*> reqParam' "user_id"
<*> reqParam' "user_name"
<*> reqParam' "command"
<*> optParam' "text"
where
reqParam' = reqParam params
optParam' = optParam params
newSlashCom :: Text -> Text -> Text -> Text
-> Text -> Text -> Text -> Maybe Text
-> SlashCom
newSlashCom a b c d e f g =
SlashCom (setToken a)
(setTeamID b)
(setChanID c)
(setChanName d)
(setUserID e)
(setUserName f)
(setCommand g)