-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.hs
29 lines (26 loc) · 898 Bytes
/
Update.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE
DeriveGeneric
, OverloadedStrings
#-}
module Vk.Update
( Update(..)
)
where
import Data.Aeson.Types ( (.:)
, FromJSON
, Parser
, parseJSON
, withObject
)
import Data.Text ( Text )
import qualified Vk.Message as Message
data Update =
NewMessage Message.Json
| UnsupportedUpdate
instance FromJSON Update where
parseJSON = withObject "" $ \upd -> do
utype <- upd .: "type" :: Parser Text
let obj = upd .: "object"
case utype of
"message_new" -> NewMessage <$> (obj >>= (.: "message"))
_ -> return UnsupportedUpdate