-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChat.hs
32 lines (27 loc) · 1.28 KB
/
Chat.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
30
31
32
{-# LANGUAGE DeriveGeneric #-}
module Telegram.Chat
( Json(..)
, CType
) where
import Data.Aeson ( FromJSON
, parseJSON
, genericParseJSON
)
import Deserialization ( enumParseOptions
, customParseOptions
)
import GHC.Generics ( Generic )
data CType = Private | Group | Supergroup | Channel
deriving (Generic, Show)
instance FromJSON CType where
parseJSON = genericParseJSON enumParseOptions
data Json = Json
{ _id :: Int -- Unique identifier for this chat
, _type :: CType
, _title :: Maybe String -- Title, for supergroups, channels and group chats
, _username :: Maybe String -- Username, for private chats, supergroups and channels if available
, _first_name :: Maybe String -- First name of the other party in a private chat
, _last_name :: Maybe String -- Last name of the other party in a private chat
} deriving (Generic, Show)
instance FromJSON Json where
parseJSON = genericParseJSON customParseOptions