packages feed

telega 0.2.7 → 0.2.8

raw patch · 42 files changed

+499/−297 lines, 42 files

Files

CHANGELOG.md view
@@ -145,3 +145,11 @@ * Move `Caption`, `Duration` and `URI` modules into `Special` submodule * Define `MIME` newtype in `Special` submodule to replace vague `Text` * Rename `Size` to `Photosize` and move its content to `Photo` module++# 0.2.8+* Define `Filesize`, `Height` and `Width` newtypes in `Special` submodule to replace vague `Int`+* Move all `Special` fields of `File` object into exported submodule+* Define `Accessible` instances for `Audio`, `Document`, `Photo`, `Video`, `Voice`, `Moving`, `Callback`+* Move all modules from `Special`s up one level into `Field` submodule (add `Title` newtype)+* Create `Chat` submodule that contains `Conversation`, `Channel` and `Group` object+* Define `ID` data family to use its instances for `Accessible` instances
+ Network/API/Telegram/Bot/Field.hs view
@@ -0,0 +1,12 @@+module Network.API.Telegram.Bot.Field (module Exports) where++import Network.API.Telegram.Bot.Field.Caption as Exports+import Network.API.Telegram.Bot.Field.Duration as Exports+import Network.API.Telegram.Bot.Field.Filesize as Exports+import Network.API.Telegram.Bot.Field.Language as Exports+import Network.API.Telegram.Bot.Field.Name as Exports+import Network.API.Telegram.Bot.Field.MIME as Exports+import Network.API.Telegram.Bot.Field.Title as Exports+import Network.API.Telegram.Bot.Field.Height as Exports+import Network.API.Telegram.Bot.Field.Width as Exports+import Network.API.Telegram.Bot.Field.URI as Exports
+ Network/API/Telegram/Bot/Field/Caption.hs view
@@ -0,0 +1,21 @@+module Network.API.Telegram.Bot.Field.Caption (Caption (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), withText)+import "base" Control.Applicative (pure)+import "base" Data.Function ((.))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Caption = Caption Text deriving Show++instance Accessible Text Caption where+	access f (Caption txt) = (\txt' -> Caption txt') <$> f txt++instance FromJSON Caption where+	parseJSON = withText "Caption" (pure . Caption)++instance ToJSON Caption where+	toJSON (Caption txt) = toJSON txt
+ Network/API/Telegram/Bot/Field/Duration.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Field.Duration (Duration) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int)+import "base" Text.Show (Show)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Duration = Duration Int deriving Show++instance Accessible Int Duration where+	access f (Duration int) = (\int' -> Duration int') <$> f int++instance FromJSON Duration where+	parseJSON o = Duration <$> parseJSON o++instance ToJSON Duration where+	toJSON (Duration d) = toJSON d
+ Network/API/Telegram/Bot/Field/Filesize.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Field.Filesize (Filesize) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int)+import "base" Text.Show (Show)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Filesize = Filesize Int deriving Show++instance Accessible Int Filesize where+	access f (Filesize int) = (\int' -> Filesize int') <$> f int++instance FromJSON Filesize where+	parseJSON o = Filesize <$> parseJSON o++instance ToJSON Filesize where+	toJSON (Filesize d) = toJSON d
+ Network/API/Telegram/Bot/Field/Height.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Field.Height (Height) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int)+import "base" Text.Show (Show)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Height = Height Int deriving Show++instance Accessible Int Height where+	access f (Height int) = (\int' -> Height int') <$> f int++instance FromJSON Height where+	parseJSON o = Height <$> parseJSON o++instance ToJSON Height where+	toJSON (Height d) = toJSON d
+ Network/API/Telegram/Bot/Field/Language.hs view
@@ -0,0 +1,22 @@+module Network.API.Telegram.Bot.Field.Language (Language (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON)+	, ToJSON (toJSON), Value (String), withText)+import "base" Control.Applicative (pure)+import "base" Data.Function ((.))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Language = Language Text deriving Show++instance Accessible Text Language where+	access f (Language txt) = (\txt' -> Language txt') <$> f txt++instance FromJSON Language where+	parseJSON = withText "Language" (pure . Language)++instance ToJSON Language where+	toJSON (Language txt) = String txt
+ Network/API/Telegram/Bot/Field/MIME.hs view
@@ -0,0 +1,21 @@+module Network.API.Telegram.Bot.Field.MIME (MIME (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), withText)+import "base" Control.Applicative (pure)+import "base" Data.Function ((.))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype MIME = MIME Text deriving Show++instance Accessible Text MIME where+	access f (MIME txt) = (\txt' -> MIME txt') <$> f txt++instance FromJSON MIME where+	parseJSON = withText "MIME" (pure . MIME)++instance ToJSON MIME where+	toJSON (MIME txt) = toJSON txt
+ Network/API/Telegram/Bot/Field/Name.hs view
@@ -0,0 +1,61 @@+module Network.API.Telegram.Bot.Field.Name (Name (..), First (..), Last (..), Nick (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON)+	, ToJSON (toJSON), Value (String), withText)+import "base" Control.Applicative (pure)+import "base" Data.Function ((.), ($))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Name = Name Text deriving Show++instance Accessible Text Name where+	access f (Name txt) = (\txt' -> Name txt') <$> f txt++instance FromJSON Name where+	parseJSON = withText "Name" (pure . Name)++instance ToJSON Name where+	toJSON (Name txt) = String txt++data First a where First :: Name -> First Name++deriving instance Show a => Show (First a)++instance Accessible Text (First Name) where+	access f (First (Name txt)) = (\txt' -> First $ Name txt') <$> f txt++instance FromJSON (First Name) where+	parseJSON o = First <$> parseJSON o++instance ToJSON (First Name) where+	toJSON (First name) = toJSON name++data Last a where Last :: Name -> Last Name++deriving instance Show a => Show (Last a)++instance Accessible Text (Last Name) where+	access f (Last (Name txt)) = (\txt' -> Last $ Name txt') <$> f txt++instance FromJSON (Last Name) where+	parseJSON o = Last <$> parseJSON o++instance ToJSON (Last Name) where+	toJSON (Last name) = toJSON name++data Nick a where Nick :: Name -> Nick Name++deriving instance Show a => Show (Nick a)++instance Accessible Text (Nick Name) where+	access f (Nick (Name txt)) = (\txt' -> Nick $ Name txt') <$> f txt++instance FromJSON (Nick Name) where+	parseJSON o = Nick <$> parseJSON o++instance ToJSON (Nick Name) where+	toJSON (Nick name) = toJSON name
+ Network/API/Telegram/Bot/Field/Title.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Field.Title (Title) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Title = Title Text deriving Show++instance Accessible Text Title where+	access f (Title txt) = (\txt' -> Title txt') <$> f txt++instance FromJSON Title where+	parseJSON o = Title <$> parseJSON o++instance ToJSON Title where+	toJSON (Title d) = toJSON d
+ Network/API/Telegram/Bot/Field/URI.hs view
@@ -0,0 +1,27 @@+module Network.API.Telegram.Bot.Field.URI (URI (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), withText)+import "base" Control.Applicative (pure)+import "base" Data.Eq (Eq)+import "base" Data.Function ((.))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))+import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident))++newtype URI = URI Text deriving (Eq, Show)++instance Accessible Text URI where+	access f (URI txt) = (\txt' -> URI txt') <$> f txt++instance Identifiable URI where+	type Identificator URI = Text+	ident (URI txt) = txt++instance FromJSON URI where+	parseJSON = withText "URI" (pure . URI)++instance ToJSON URI where+	toJSON (URI txt) = toJSON txt
+ Network/API/Telegram/Bot/Field/Width.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Field.Width (Width) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int)+import "base" Text.Show (Show)++import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))++newtype Width = Width Int deriving Show++instance Accessible Int Width where+	access f (Width int) = (\int' -> Width int') <$> f int++instance FromJSON Width where+	parseJSON o = Width <$> parseJSON o++instance ToJSON Width where+	toJSON (Width d) = toJSON d
Network/API/Telegram/Bot/Object.hs view
@@ -2,5 +2,5 @@  import Network.API.Telegram.Bot.Object.Update as Exports import Network.API.Telegram.Bot.Object.Sender as Exports-import Network.API.Telegram.Bot.Object.Name as Exports import Network.API.Telegram.Bot.Object.Member as Exports+import Network.API.Telegram.Bot.Object.Chat as Exports
+ Network/API/Telegram/Bot/Object/Chat.hs view
@@ -0,0 +1,24 @@+module Network.API.Telegram.Bot.Object.Chat (module Exports, Chat, ID (..)) where++import Network.API.Telegram.Bot.Object.Chat.Group as Exports+import Network.API.Telegram.Bot.Object.Chat.Conversation as Exports+import Network.API.Telegram.Bot.Object.Chat.Channel as Exports++import "base" Data.Functor ((<$>))+import "base" Data.Int (Int64)++import Network.API.Telegram.Bot.Property (Accessible (access), ID)++data Chat++data instance ID Chat = CHAT Int64++instance Accessible (ID Chat) Channel where+	access f (Channel i title) = (\(CHAT i') -> Channel i' title) <$> f (CHAT i)++instance Accessible (ID Chat) Conversation where+	access f (Conversation i) = (\(CHAT i') -> Conversation i') <$> f (CHAT i)++instance Accessible (ID Chat) Group where+	access f (Basic i title) = (\(CHAT i') -> Basic i' title) <$> f (CHAT i)+	access f (Super i title description) = (\(CHAT i') -> Super i' title description) <$> f (CHAT i)
+ Network/API/Telegram/Bot/Object/Chat/Channel.hs view
@@ -0,0 +1,24 @@+module Network.API.Telegram.Bot.Object.Chat.Channel (Channel (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))+import "base" Control.Applicative ((<*>))+import "base" Control.Monad ((>>=), fail)+import "base" Data.Function (($))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int64)+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Field (Title)+import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))++data Channel = Channel Int64 Title deriving Show++instance Identifiable Channel where+	type Identificator Channel = Int64+	ident (Channel i _) = i++instance FromJSON Channel where+	parseJSON = withObject "Channel" $ \chat -> chat .: "type" >>= \case+		("channel" :: Text) -> Channel <$> chat .: "id" <*> chat .: "title"+		_ -> fail "Not a channel chat!"
+ Network/API/Telegram/Bot/Object/Chat/Conversation.hs view
@@ -0,0 +1,22 @@+module Network.API.Telegram.Bot.Object.Chat.Conversation (Conversation (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))+import "base" Control.Monad ((>>=), fail)+import "base" Data.Function (($))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int64)+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))++data Conversation = Conversation Int64 deriving Show++instance Identifiable Conversation where+	type Identificator Conversation = Int64+	ident (Conversation i) = i++instance FromJSON Conversation where+	parseJSON = withObject "Conversation" $ \chat -> chat .: "type" >>= \case+		("private" :: Text) -> Conversation <$> chat .: "id"+		_ -> fail "Not a private chat!"
+ Network/API/Telegram/Bot/Object/Chat/Group.hs view
@@ -0,0 +1,30 @@+module Network.API.Telegram.Bot.Object.Chat.Group (Group (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))+import "base" Control.Applicative ((<*>))+import "base" Control.Monad ((>>=), fail)+import "base" Data.Function (($))+import "base" Data.Functor ((<$>))+import "base" Data.Int (Int64)+import "base" Data.Maybe (Maybe)+import "base" Text.Show (Show)+import "text" Data.Text (Text)++import Network.API.Telegram.Bot.Field (Title)+import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))++data Group+	= Basic Int64 Title+	| Super Int64 Title (Maybe Text)+	deriving Show++instance Identifiable Group where+	type Identificator Group = Int64+	ident (Basic i _ ) = i+	ident (Super i _ _) = i++instance FromJSON Group where+	parseJSON = withObject "Group" $ \chat -> chat .: "type" >>= \case+		("group" :: Text) -> Basic <$> chat .: "id" <*> chat .: "title"+		("supergroup" :: Text) -> Super <$> chat .: "id" <*> chat .: "title" <*> chat .:? "description"+		_ -> fail "Neither group nor supergroup!"
− Network/API/Telegram/Bot/Object/Language.hs
@@ -1,22 +0,0 @@-module Network.API.Telegram.Bot.Object.Language (Language (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON)-	, ToJSON (toJSON), Value (String), withText)-import "base" Control.Applicative (pure)-import "base" Data.Function ((.))-import "base" Data.Functor ((<$>))-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))--newtype Language = Language Text deriving Show--instance Accessible Text Language where-	access f (Language txt) = (\txt' -> Language txt') <$> f txt--instance FromJSON Language where-	parseJSON = withText "Language" (pure . Language)--instance ToJSON Language where-	toJSON (Language txt) = String txt
− Network/API/Telegram/Bot/Object/Name.hs
@@ -1,62 +0,0 @@-module Network.API.Telegram.Bot.Object.Name-	(Name (..), First (..), Last (..), Nick (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON)-	, ToJSON (toJSON), Value (String), withText)-import "base" Control.Applicative (pure)-import "base" Data.Function ((.), ($))-import "base" Data.Functor ((<$>))-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))--newtype Name = Name Text deriving Show--instance Accessible Text Name where-	access f (Name txt) = (\txt' -> Name txt') <$> f txt--instance FromJSON Name where-	parseJSON = withText "Name" (pure . Name)--instance ToJSON Name where-	toJSON (Name txt) = String txt--data First a where First :: Name -> First Name--deriving instance Show a => Show (First a)--instance Accessible Text (First a) where-	access f (First (Name txt)) = (\txt' -> First $ Name txt') <$> f txt--instance FromJSON (First Name) where-	parseJSON o = First <$> parseJSON o--instance ToJSON (First Name) where-	toJSON (First name) = toJSON name--data Last a where Last :: Name -> Last Name--deriving instance Show a => Show (Last a)--instance Accessible Text (Last a) where-	access f (Last (Name txt)) = (\txt' -> Last $ Name txt') <$> f txt--instance FromJSON (Last Name) where-	parseJSON o = Last <$> parseJSON o--instance ToJSON (Last Name) where-	toJSON (Last name) = toJSON name--data Nick a where Nick :: Name -> Nick Name--deriving instance Show a => Show (Nick a)--instance Accessible Text (Nick a) where-	access f (Nick (Name txt)) = (\txt' -> Nick $ Name txt') <$> f txt--instance FromJSON (Nick Name) where-	parseJSON o = Nick <$> parseJSON o--instance ToJSON (Nick Name) where-	toJSON (Nick name) = toJSON name
Network/API/Telegram/Bot/Object/Sender.hs view
@@ -12,10 +12,8 @@ import "base" Data.Maybe (Maybe) import "base" Text.Show (Show) -import Network.API.Telegram.Bot.Object.Language (Language)-import Network.API.Telegram.Bot.Object.Name (Name, First, Last, Nick)-import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))-import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Field (Language, Name, First, Last, Nick)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident))  data Sender 	= Bot Int (Maybe (Nick Name)) (First Name) (Maybe (Last Name)) (Maybe Language)
Network/API/Telegram/Bot/Object/Update.hs view
@@ -6,13 +6,13 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "base" Control.Applicative ((<*>), (<|>))-import "base" Data.Eq (Eq ((==))) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int) import "base" Text.Show (Show) -import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Object.Chat (Chat)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident), ID)  data Update 	= Query Int Callback@@ -20,8 +20,10 @@ 	| Incoming Int Message 	deriving Show -instance Eq Update where-	u == u' = ident u == ident u'+instance Accessible (ID Chat) Update where+	access f (Query i callback) = Query i <$> access f callback+	access f (Membership i moving) = Membership i <$> access f moving+	access f (Incoming i message) = Incoming i <$> access f message  instance Identifiable Update where 	type Identificator Update = Int
Network/API/Telegram/Bot/Object/Update/Callback.hs view
@@ -12,11 +12,10 @@ import "base" Text.Show (Show) import "text" Data.Text (Text) +import Network.API.Telegram.Bot.Object.Chat (Chat) import Network.API.Telegram.Bot.Object.Sender (Sender) import Network.API.Telegram.Bot.Object.Update.Message (Message)-import Network.API.Telegram.Bot.Object.Update.Message.Origin (Origin)-import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))-import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident), ID) import Network.API.Telegram.Bot.Property.Persistable (Persistable (Payload, Returning, payload, endpoint)) import Network.API.Telegram.Bot.Utils (field) @@ -25,9 +24,17 @@ instance Eq Callback where 	c == c' = ident c == ident c' -instance Accessible Origin Callback where-	access f (Datatext cq_id from msg dttxt) = flip-		(Datatext cq_id from) dttxt <$> access f msg+instance Accessible Sender Callback where+	access f (Datatext cq_id sender msg dttxt) =+		(\sender' -> Datatext cq_id sender' msg dttxt) <$> f sender++instance Accessible Message Callback where+	access f (Datatext cq_id sender msg dttxt) =+		(\msg' -> Datatext cq_id sender msg' dttxt) <$> f msg++instance Accessible (ID Chat) Callback where+	access f (Datatext cq_id sender msg dttxt) =+		flip (Datatext cq_id sender) dttxt <$> access f msg  instance FromJSON Callback where 	parseJSON = withObject "Callback" $ \v ->
Network/API/Telegram/Bot/Object/Update/Message.hs view
@@ -7,11 +7,11 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), Value (Object), withObject, (.:)) import "aeson" Data.Aeson.Types (Object, Parser)-import "base" Control.Applicative (Applicative ((<*>)), Alternative ((<|>)))+import "base" Control.Applicative ((<*>), (<|>)) import "base" Control.Monad (Monad ((>>=)), fail) import "base" Data.Bool (Bool (True)) import "base" Data.Eq (Eq ((==)))-import "base" Data.Function (($))+import "base" Data.Function (flip, ($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int, Int64) import "base" Data.Semigroup ((<>))@@ -19,8 +19,8 @@ import "text" Data.Text (Text) import "with" Data.With (type (:&:)((:&:))) -import Network.API.Telegram.Bot.Object.Update.Message.Content (Content)-import Network.API.Telegram.Bot.Object.Update.Message.Origin (Origin (Private, Group, Channel))+import Network.API.Telegram.Bot.Field (Caption, URI)+import Network.API.Telegram.Bot.Object.Chat (Chat, ID) import Network.API.Telegram.Bot.Property.Accessible (Accessible (access)) import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident)) import Network.API.Telegram.Bot.Property.Persistable (Persistable (Payload, Returning, payload, endpoint))@@ -45,6 +45,11 @@ 	access f (Forwarded msg_id origin content) = (\origin' -> Forwarded msg_id origin' content) <$> f origin 	access f (Replied msg_id origin content msg) = (\origin' -> Replied msg_id origin' content msg) <$> f origin +instance Accessible (ID Chat) Message where+	access f (Direct msg_id origin content) = flip (Direct msg_id) content <$> access f origin+	access f (Forwarded msg_id origin content) = flip (Forwarded msg_id) content <$> access f origin+	access f (Replied msg_id origin content msg) = Replied msg_id origin content <$> access f msg+ instance Identifiable Message where 	type Identificator Message = Int 	ident (Direct i _ _) = i@@ -60,7 +65,7 @@ 			<*> (v .: "forward_from_chat" >>= channel) <*> parseJSON (Object v) where  			channel :: Value -> Parser Origin-			channel = withObject "Channel" $ \c -> Channel <$> c .: "id" <*> c .: "title"+			channel = withObject "Channel" $ \c -> Blog <$> c .: "id"  		forward_chat :: Object -> Parser Message 		forward_chat v = Forwarded <$> v .: "message_id"
Network/API/Telegram/Bot/Object/Update/Message/Content.hs view
@@ -19,6 +19,8 @@ import "base" Prelude ((+)) import "text" Data.Text (Text, drop, take) +import Network.API.Telegram.Bot.Field (Caption)+ data Status = Opened | Closed 	deriving Show 
Network/API/Telegram/Bot/Object/Update/Message/Content/File.hs view
@@ -5,9 +5,6 @@ import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Photo as Exports import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Video as Exports import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Voice as Exports-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Caption as Exports-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration as Exports-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI as Exports  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "base" Control.Applicative ((<|>))
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Audio.hs view
@@ -2,19 +2,20 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show) import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI (URI)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration (Duration)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME (MIME)-import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Field (Duration, Filesize, MIME, Title, URI)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident)) -data Audio = Audio URI Duration (Maybe Text) (Maybe Text) (Maybe MIME) (Maybe Int) deriving Show+data Audio = Audio URI Duration (Maybe Text) (Maybe Title) (Maybe MIME) (Maybe Filesize) deriving Show++instance Accessible Duration Audio where+	access f (Audio uri duration performer title mime fs) =+		(\duration' -> Audio uri duration' performer title mime fs) <$> f duration  instance Identifiable Audio where 	type Identificator Audio = URI
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Document.hs view
@@ -2,18 +2,15 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)-import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME (MIME)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI (URI)+import Network.API.Telegram.Bot.Field (Filesize, MIME, Title, URI) import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident)) -data Document = Document URI (Maybe Text) (Maybe MIME) (Maybe Int) deriving Show+data Document = Document URI (Maybe Title) (Maybe MIME) (Maybe Filesize) deriving Show  instance Identifiable Document where 	type Identificator Document = URI
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Photo.hs view
@@ -3,25 +3,32 @@ import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "base" Control.Applicative ((<*>)) import "base" Data.Eq (Eq ((==)))-import "base" Data.Int (Int) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Data.Maybe (Maybe) import "base" Text.Show (Show)-import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Field (Height, Width, Filesize, URI)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident))  data Photo -data Photosize = Photosize Text Int Int (Maybe Int) deriving Show+data Photosize = Photosize URI Height Width (Maybe Filesize) deriving Show  instance Eq Photosize where 	s == s' = ident s == ident s' +instance Accessible Height Photosize where+	access f (Photosize uri height width fs) =+		(\height' -> Photosize uri height' width fs) <$> f height++instance Accessible Width Photosize where+	access f (Photosize uri height width fs) =+		(\width' -> Photosize uri height width' fs) <$> f width+ instance Identifiable Photosize where-	type Identificator Photosize = Text-	ident (Photosize file_id _ _ _) = file_id+	type Identificator Photosize = URI+	ident (Photosize uri _ _ _) = uri  instance FromJSON Photosize where 	parseJSON = withObject "Photosize" $ \v -> Photosize <$> v .: "file_id"
− Network/API/Telegram/Bot/Object/Update/Message/Content/File/Special/Caption.hs
@@ -1,21 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Caption (Caption (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), Value (String), withText)-import "base" Control.Applicative (pure)-import "base" Data.Function ((.))-import "base" Data.Functor ((<$>))-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))--newtype Caption = Caption Text deriving Show--instance Accessible Text Caption where-	access f (Caption txt) = (\txt' -> Caption txt') <$> f txt--instance FromJSON Caption where-	parseJSON = withText "Caption" (pure . Caption)--instance ToJSON Caption where-	toJSON (Caption txt) = String txt
− Network/API/Telegram/Bot/Object/Update/Message/Content/File/Special/Duration.hs
@@ -1,19 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration (Duration) where--import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON))-import "base" Data.Functor ((<$>))-import "base" Data.Int (Int)-import "base" Text.Show (Show)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))--newtype Duration = Duration Int deriving Show--instance Accessible Int Duration where-	access f (Duration int) = (\int' -> Duration int') <$> f int--instance FromJSON Duration where-	parseJSON o = Duration <$> parseJSON o--instance ToJSON Duration where-	toJSON (Duration d) = toJSON d
− Network/API/Telegram/Bot/Object/Update/Message/Content/File/Special/MIME.hs
@@ -1,21 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME (MIME (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), Value (String), withText)-import "base" Control.Applicative (pure)-import "base" Data.Function ((.))-import "base" Data.Functor ((<$>))-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))--newtype MIME = MIME Text deriving Show--instance Accessible Text MIME where-	access f (MIME txt) = (\txt' -> MIME txt') <$> f txt--instance FromJSON MIME where-	parseJSON = withText "MIME" (pure . MIME)--instance ToJSON MIME where-	toJSON (MIME txt) = String txt
− Network/API/Telegram/Bot/Object/Update/Message/Content/File/Special/URI.hs
@@ -1,27 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI (URI (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), Value (String), withText)-import "base" Control.Applicative (pure)-import "base" Data.Eq (Eq)-import "base" Data.Function ((.))-import "base" Data.Functor ((<$>))-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))-import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident))--newtype URI = URI Text deriving (Eq, Show)--instance Accessible Text URI where-	access f (URI txt) = (\txt' -> URI txt') <$> f txt--instance Identifiable URI where-	type Identificator URI = Text-	ident (URI txt) = txt--instance FromJSON URI where-	parseJSON = withText "URI" (pure . URI)--instance ToJSON URI where-	toJSON (URI txt) = String txt
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Video.hs view
@@ -2,19 +2,27 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)-import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration (Duration)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME (MIME)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI (URI)-import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Field (Duration, Filesize, MIME, Height, Width, URI)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident)) -data Video = Video URI Duration Int Int (Maybe MIME) (Maybe Int) deriving Show+data Video = Video URI Duration Height Width (Maybe MIME) (Maybe Filesize) deriving Show++instance Accessible Duration Video where+	access f (Video uri duration height width mime fs) =+		(\duration' -> Video uri duration' height width mime fs) <$> f duration++instance Accessible Height Video where+	access f (Video uri duration height width mime fs) =+		(\height' -> Video uri duration height' width mime fs) <$> f height++instance Accessible Width Video where+	access f (Video uri duration height width mime fs) =+		(\width' -> Video uri duration height width' mime fs) <$> f width  instance Identifiable Video where 	type Identificator Video = URI
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Voice.hs view
@@ -2,18 +2,19 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show) -import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration (Duration)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME (MIME)-import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI (URI)-import Network.API.Telegram.Bot.Property (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Field (Duration, Filesize, MIME, URI)+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident)) -data Voice = Voice URI Duration (Maybe MIME) (Maybe Int) deriving Show+data Voice = Voice URI Duration (Maybe MIME) (Maybe Filesize) deriving Show++instance Accessible Duration Voice where+	access f (Voice uri duration mime fs) =+		(\duration' -> Voice uri duration' mime fs) <$> f duration  instance Identifiable Voice where 	type Identificator Voice = URI
Network/API/Telegram/Bot/Object/Update/Message/Content/Info/Contact.hs view
@@ -9,7 +9,7 @@ import "base" Text.Show (Show) import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Object.Name (Name, First, Last)+import Network.API.Telegram.Bot.Field (Name, First, Last) import Network.API.Telegram.Bot.Property.Accessible (Accessible (access))  data Contact = Contact (First Name) (Maybe (Last Name)) (Maybe Int) Text (Maybe Text) deriving Show
Network/API/Telegram/Bot/Object/Update/Message/Content/Info/Venue.hs view
@@ -8,10 +8,10 @@ import "base" Text.Show (Show) import "text" Data.Text (Text) +import Network.API.Telegram.Bot.Field (Title) import Network.API.Telegram.Bot.Object.Update.Message.Content.Info.Location (Location) -data Venue = Venue Text Text Location (Maybe Text) (Maybe Text)-	deriving Show+data Venue = Venue Title Text Location (Maybe Text) (Maybe Text) deriving Show  instance FromJSON Venue where 	parseJSON = withObject "Venue" $ \i -> Venue
Network/API/Telegram/Bot/Object/Update/Message/Content/Poll/Option.hs view
@@ -1,19 +1,19 @@ module Network.API.Telegram.Bot.Object.Update.Message.Content.Poll.Option (Option (..)) where -import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON)-	, Value (String), withObject, (.:))+import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), withObject, (.:)) import "base" Control.Applicative ((<*>)) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int) import "base" Text.Show (Show)-import "text" Data.Text (Text) -data Option = Option Text Int deriving Show+import Network.API.Telegram.Bot.Field (Title) +data Option = Option Title Int deriving Show+ instance FromJSON Option where 	parseJSON = withObject "Option" $ \v -> Option 		<$> v .: "text" <*> v .: "voter_counter"  instance ToJSON Option where-	toJSON (Option opt _) = String opt+	toJSON (Option title _) = toJSON title
Network/API/Telegram/Bot/Object/Update/Message/Origin.hs view
@@ -1,40 +1,32 @@ module Network.API.Telegram.Bot.Object.Update.Message.Origin (Origin (..)) where  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))-import "aeson" Data.Aeson.Types (Object, Parser, Value (Object))-import "base" Control.Applicative (Applicative ((<*>)))+import "base" Control.Applicative ((<*>), (<|>)) import "base" Control.Monad (Monad ((>>=)))-import "base" Data.Eq (Eq ((==)))-import "base" Data.Function (($))+import "base" Data.Function (flip, ($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int64) import "base" Text.Show (Show)-import "text" Data.Text (Text) +import Network.API.Telegram.Bot.Object.Chat (Chat, ID, Channel, Conversation, Group) import Network.API.Telegram.Bot.Object.Sender (Sender)-import Network.API.Telegram.Bot.Object.Update.Moving.Group (Group)-import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))+import Network.API.Telegram.Bot.Property (Accessible (access), Identifiable (Identificator, ident)) -data Origin-	= Private Int64 Sender-	| Group Group Sender-	| Channel Int64 Text-	deriving Show+data Origin = Private Conversation Sender | Group Group Sender | Blog Channel deriving Show -instance Eq Origin where-	o == o' = ident o == ident o'+instance Accessible (ID Chat) Origin where+	access f (Private conversation sender) = flip Private sender <$> access f conversation+	access f (Group group sender) = flip Group sender <$> access f group+	access f (Blog channel) = Blog <$> access f channel  instance Identifiable Origin where 	type Identificator Origin = Int64-	ident (Private i _) = i+	ident (Private c _) = ident c 	ident (Group g _) = ident g-	ident (Channel i _) = i+	ident (Blog c) = ident c  instance FromJSON Origin where-	parseJSON = withObject "Message" $ \v -> v .: "chat" >>= chat v where--		chat :: Object -> Value -> Parser Origin-		chat v = withObject "Origin" $ \c -> c .: "type" >>= \case-			("private" :: Text) -> Private <$> c .: "id" <*> v .: "from"-			("channel" :: Text) -> Channel <$> c .: "id" <*> c .: "title"-			_ -> parseJSON (Object v)+	parseJSON = withObject "Message" $ \msg -> msg .: "chat" >>= \chat ->+		(Group <$> parseJSON chat <*> msg .: "from") <|>+		(Private <$> parseJSON chat <*> msg .: "from") <|>+		(Blog <$> parseJSON chat)
Network/API/Telegram/Bot/Object/Update/Moving.hs view
@@ -1,6 +1,4 @@-module Network.API.Telegram.Bot.Object.Update.Moving (module Exports, Moving (..)) where--import Network.API.Telegram.Bot.Object.Update.Moving.Group as Exports+module Network.API.Telegram.Bot.Object.Update.Moving (Moving (..)) where  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "base" Control.Applicative ((<*>), (<|>))@@ -8,12 +6,23 @@ import "base" Data.Functor ((<$>)) import "base" Text.Show (Show) +import Network.API.Telegram.Bot.Object.Chat (Chat)+import Network.API.Telegram.Bot.Object.Chat.Group (Group) import Network.API.Telegram.Bot.Object.Sender (Sender)+import Network.API.Telegram.Bot.Property (Accessible (access), ID)  data Moving 	= Gone Sender Group 	| Joined [Sender] Group 	deriving Show++instance Accessible Group Moving where+	access f (Gone sender group) = (\group' -> Gone sender group') <$> f group+	access f (Joined senders group) = (\group' -> Joined senders group') <$> f group++instance Accessible (ID Chat) Moving where+	access f (Gone sender group) = Gone sender <$> access f group+	access f (Joined senders group) = Joined senders <$> access f group  instance FromJSON Moving where 	parseJSON = withObject "Moving" $ \v ->
− Network/API/Telegram/Bot/Object/Update/Moving/Group.hs
@@ -1,29 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Moving.Group (Group (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))-import "base" Control.Applicative ((<*>))-import "base" Control.Monad ((>>=), fail)-import "base" Data.Function (($))-import "base" Data.Functor ((<$>))-import "base" Data.Int (Int64)-import "base" Data.Maybe (Maybe)-import "base" Text.Show (Show)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))--data Group-	= Basic Int64 Text-	| Super Int64 Text (Maybe Text)-	deriving Show--instance Identifiable Group where-	type Identificator Group = Int64-	ident (Basic i _ ) = i-	ident (Super i _ _) = i--instance FromJSON Group where-	parseJSON = withObject "Group" $ \v -> v .: "type" >>= \case-		("group" :: Text) -> Basic <$> v .: "id" <*> v .: "title"-		("supergroup" :: Text) -> Super <$> v .: "id" <*> v .: "title" <*> v .:? "description"-		_ -> fail "Neither group nor supergroup!"
Network/API/Telegram/Bot/Property/Identifiable.hs view
@@ -1,6 +1,8 @@-module Network.API.Telegram.Bot.Property.Identifiable (Identifiable (..)) where+module Network.API.Telegram.Bot.Property.Identifiable (Identifiable (..), ID) where  class Identifiable o where 	{-# MINIMAL ident #-} 	type family Identificator o :: * 	ident :: o -> Identificator o++data family ID a :: *
telega.cabal view
@@ -1,5 +1,5 @@ name:                telega-version:             0.2.7+version:             0.2.8 synopsis:            Telegram Bot API binding description:         High-level bindings, typed entities, inline mode only homepage:            https://github.com/iokasimov/telega@@ -21,12 +21,25 @@   exposed-modules:     Network.API.Telegram.Bot     Network.API.Telegram.Bot.Core+    Network.API.Telegram.Bot.Field+    Network.API.Telegram.Bot.Field.Caption+    Network.API.Telegram.Bot.Field.Duration+    Network.API.Telegram.Bot.Field.Language+    Network.API.Telegram.Bot.Field.Name+    Network.API.Telegram.Bot.Field.Filesize+    Network.API.Telegram.Bot.Field.MIME+    Network.API.Telegram.Bot.Field.Title+    Network.API.Telegram.Bot.Field.URI+    Network.API.Telegram.Bot.Field.Height+    Network.API.Telegram.Bot.Field.Width     Network.API.Telegram.Bot.Object-    Network.API.Telegram.Bot.Object.Language+    Network.API.Telegram.Bot.Object.Chat+    Network.API.Telegram.Bot.Object.Chat.Channel+    Network.API.Telegram.Bot.Object.Chat.Conversation+    Network.API.Telegram.Bot.Object.Chat.Group     Network.API.Telegram.Bot.Object.Member     Network.API.Telegram.Bot.Object.Member.Powers     Network.API.Telegram.Bot.Object.Member.Restrictions-    Network.API.Telegram.Bot.Object.Name     Network.API.Telegram.Bot.Object.Sender     Network.API.Telegram.Bot.Object.Update     Network.API.Telegram.Bot.Object.Update.Callback@@ -34,10 +47,6 @@     Network.API.Telegram.Bot.Object.Update.Message     Network.API.Telegram.Bot.Object.Update.Message.Content     Network.API.Telegram.Bot.Object.Update.Message.Content.File-    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Caption-    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.Duration-    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.MIME-    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Special.URI     Network.API.Telegram.Bot.Object.Update.Message.Content.File.Audio     Network.API.Telegram.Bot.Object.Update.Message.Content.File.Document     Network.API.Telegram.Bot.Object.Update.Message.Content.File.Photo@@ -53,7 +62,6 @@     Network.API.Telegram.Bot.Object.Update.Message.Keyboard.Button     Network.API.Telegram.Bot.Object.Update.Message.Origin     Network.API.Telegram.Bot.Object.Update.Moving-    Network.API.Telegram.Bot.Object.Update.Moving.Group     Network.API.Telegram.Bot.Property     Network.API.Telegram.Bot.Property.Accessible     Network.API.Telegram.Bot.Property.Identifiable