packages feed

telega 0.2.1 → 0.2.2

raw patch · 22 files changed

+166/−267 lines, 22 filesdep +unordered-containersdep +with

Dependencies added: unordered-containers, with

Files

CHANGELOG.md view
@@ -1,6 +1,6 @@ # 0.1.1 * Define `chat` lens for `Update` datatype-* Add string identificator to `Callback` datatype+* Add string ident to `Callback` datatype * Define `Notification` datatype * Define `Droppable` typeclass @@ -87,3 +87,15 @@ * Rename `request` method to `persist` in `Persistable` type class * Distribute `Persistable` instances on objects that belong to them * Add `Polling` constructor to `Content` for `Poll` object++# 0.2.2+* Define `Persistable` instances for `Poll`, `Audio`, `Document`, `Video`, `Voice` datatypes+* Define `Group` datatype for representation basic groups and supergroups+* Remove `Object` type family to distribute `Accessible` and `Identifiable` instances+* Put `Identificator` type family into `Identifiable` type class+* Rename `identifcator` to `ident`, add MINIMAL pragma to `Accessible`+* Include `Group` information into `Moving` object+* Method `payload` in `Persistable` type class defines hash table, not `JSON` value+* Rename `Message` constructors to use old name as `Capacity` constructors+* Define `Persistable` instance for `Reply`-ing messages+* Temporary delete old `Persistable` instances
Network/API/Telegram/Bot/Object.hs view
@@ -1,22 +1,6 @@-module Network.API.Telegram.Bot.Object (module Exports, Object) where+module Network.API.Telegram.Bot.Object (module Exports) where  import Network.API.Telegram.Bot.Object.Update as Exports import Network.API.Telegram.Bot.Object.Sender as Exports import Network.API.Telegram.Bot.Object.Member as Exports--import "base" Data.Kind (Constraint)--type family Object (a :: *) :: Constraint-type instance Object Sender = ()-type instance Object Update = ()-type instance Object Notification = ()-type instance Object Moving = ()-type instance Object Message = ()-type instance Object Member = ()-type instance Object Keyboard = ()-type instance Object Content = ()-type instance Object Origin = ()-type instance Object Callback = ()-type instance Object Button = ()-type instance Object Info = ()-type instance Object Location = ()+import Network.API.Telegram.Bot.Object.Group as Exports
+ Network/API/Telegram/Bot/Object/Group.hs view
@@ -0,0 +1,22 @@+module Network.API.Telegram.Bot.Object.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)++data Group+	= Basic Int64 Text+	| Super Int64 Text (Maybe Text)+	deriving Show++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/Object/Member.hs view
@@ -16,8 +16,6 @@ import "time" Data.Time.Clock.POSIX (POSIXTime)  import Network.API.Telegram.Bot.Object.Sender (Sender)-import Network.API.Telegram.Bot.Property.Persistable-	(Persistable (Payload, payload, endpoint), Capacity (Fetch))  data Member 	= Creator Sender@@ -37,8 +35,3 @@ 		("left" :: Text) -> Left <$> v .: "user" 		("kicked" :: Text) -> Kicked <$> v .: "user" <*> v.: "until_date" 		_ -> fail "Status of chat member is not defined"--instance Persistable 'Fetch Member where-	type instance Payload 'Fetch Member = Tagged ('Fetch Member) (Int64, Int)-	payload (untag -> (chat_id, user_id)) = object ["chat_id" .= chat_id, "user_id" .= user_id]-	endpoint _ = "getChatMember"
Network/API/Telegram/Bot/Object/Sender.hs view
@@ -15,8 +15,7 @@ import "tagged" Data.Tagged (Tagged) import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Property.Persistable-	(Persistable (Payload, payload, endpoint), Capacity (Fetch))+import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))  data Sender 	= Bot Int (Maybe Text) Text (Maybe Text) (Maybe Text)@@ -35,16 +34,14 @@ 		>>= bool (sender v User) (sender v Bot) where  		sender :: Object -> Whom -> Parser Sender-		sender v f = f <$> v .: "id"-			<*> v .:? "username"-			<*> v .: "first_name"-			<*> v .:? "last_name"+		sender v f = f <$> v .: "id" <*> v .:? "username"+			<*> v .: "first_name" <*> v .:? "last_name" 			<*> v .:? "language_code" -instance Persistable 'Fetch Sender where-	type instance Payload 'Fetch Sender = Tagged ('Fetch Sender) ()-	payload _ = object []-	endpoint _ = "getMe"+instance Identifiable Sender where+	type instance Identificator Sender = Int+	ident (Bot i _ _ _ _) = i+	ident (User i _ _ _ _) = i  nickname :: Lens' Sender (Maybe Text) nickname f (Bot uid nn fn ln lng) = (\nn' -> Bot uid nn' fn ln lng) <$> f nn
Network/API/Telegram/Bot/Object/Update.hs view
@@ -15,6 +15,7 @@ import Network.API.Telegram.Bot.Object.Update.Callback (Callback) import Network.API.Telegram.Bot.Object.Update.Message (Message) import Network.API.Telegram.Bot.Object.Update.Moving (Moving)+import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))  data Update 	= Query Int Callback@@ -34,3 +35,9 @@  		incoming :: Object -> Parser Update 		incoming v = Incoming <$> v .: "update_id" <*> v .: "message"++instance Identifiable Update where+	type instance Identificator Update = Int+	ident (Query i _) = i+	ident (Membership i _) = i+	ident (Incoming i _) = i
Network/API/Telegram/Bot/Object/Update/Callback.hs view
@@ -4,15 +4,26 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "base" Control.Applicative (Applicative ((<*>)))-import "base" Data.Function (($))+import "base" Data.Function (flip, ($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show) import "text" Data.Text (Text)  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))  data Callback = Datatext Text Message Text deriving Show +instance Accessible Origin Callback where+	access f (Datatext cq_id msg dttxt) = flip+		(Datatext cq_id) dttxt <$> access f msg+ instance FromJSON Callback where 	parseJSON = withObject "Callback" $ \v -> 		Datatext <$> v .: "id" <*> v .: "message" <*> v .: "data"++instance Identifiable Callback where+	type instance Identificator Callback = Text+	ident (Datatext i _ _) = i
Network/API/Telegram/Bot/Object/Update/Callback/Notification.hs view
@@ -1,14 +1,3 @@ module Network.API.Telegram.Bot.Object.Update.Callback.Notification (Notification) where -import "aeson" Data.Aeson (object, (.=))-import "tagged" Data.Tagged (Tagged, untag)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Persistable (Persistable (Payload, payload, endpoint), Capacity (Post))- data Notification--instance Persistable 'Post Notification where-	type instance Payload 'Post Notification = Tagged ('Post Notification) (Text, Text)-	payload (untag -> (cbq_id, text)) = object ["callback_query_id" .= cbq_id, "text" .= text]-	endpoint _ = "answerCallbackQuery"
Network/API/Telegram/Bot/Object/Update/Message.hs view
@@ -4,42 +4,54 @@ import Network.API.Telegram.Bot.Object.Update.Message.Keyboard as Exports import Network.API.Telegram.Bot.Object.Update.Message.Origin as Exports -import "aeson" Data.Aeson (FromJSON (parseJSON), Value (Object), object, withObject, (.:), (.=))+import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), Value (Object), withObject, (.:)) import "aeson" Data.Aeson.Types (Object, Parser) import "base" Control.Applicative (Applicative ((<*>)), Alternative ((<|>))) import "base" Control.Monad (Monad ((>>=)), fail)-import "base" Data.Bool (Bool (True, False)) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int, Int64)+import "base" Data.Semigroup ((<>)) import "base" Text.Show (Show)-import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)+import "unordered-containers" Data.HashMap.Strict (singleton)+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, Supergroup, Channel))-import Network.API.Telegram.Bot.Property.Persistable (Persistable (Payload, payload, endpoint)-	, Capacity (Send, Edit, Purge), Inform (Notify, Silently), Way (Directly, Forwarding, Replying))+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, payload, endpoint), Capacity (Send))  data Message 	= Direct Int Origin Content-	| Forward Int Origin Content-	| Reply Int Origin Content Message+	| Forwarded Int Origin Content+	| Replied Int Origin Content Message 	deriving Show +instance Accessible Content Message where+	access f (Direct msg_id origin content) = (\content' -> Direct msg_id origin content') <$> f content+	access f (Forwarded msg_id origin content) = (\content' -> Forwarded msg_id origin content') <$> f content+	access f (Replied msg_id origin content msg) = (\content' -> Replied msg_id origin content' msg) <$> f content++instance Accessible Origin Message where+	access f (Direct msg_id origin content) = (\origin' -> Direct msg_id origin' content) <$> f origin+	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 FromJSON Message where 	parseJSON = withObject "Message" $ \v -> 		forward_channel v <|> forward_chat v <|> reply v <|> direct v where  		forward_channel :: Object -> Parser Message-		forward_channel v = Forward <$> v .: "forward_from_message_id"+		forward_channel v = Forwarded <$> v .: "forward_from_message_id" 			<*> (v .: "forward_from_chat" >>= channel) <*> parseJSON (Object v) where  			channel :: Value -> Parser Origin 			channel = withObject "Channel" $ \c -> Channel <$> c .: "id" <*> c .: "title"  		forward_chat :: Object -> Parser Message-		forward_chat v = Forward <$> v .: "message_id"+		forward_chat v = Forwarded <$> v .: "message_id" 			<*> (v .: "chat" >>= chat) <*> parseJSON (Object v) where  			chat :: Value -> Parser Origin@@ -50,66 +62,20 @@ 				_ -> fail "Type of chat is not defined"  		reply :: Object -> Parser Message-		reply v = Reply <$> v .: "message_id" <*> parseJSON (Object v)+		reply v = Replied <$> v .: "message_id" <*> parseJSON (Object v) 			<*> parseJSON (Object v) <*> v .: "reply_to_message"  		direct :: Object -> Parser Message 		direct v = Direct <$> v .: "message_id" 			<*> parseJSON (Object v) <*> parseJSON (Object v) -instance Persistable ('Send 'Notify 'Directly) Message where-	type instance Payload ('Send 'Notify 'Directly) Message-		= Tagged ('Send 'Notify 'Directly Message) (Int64, Text)-	payload (untag -> (chat_id, text)) = object-		["chat_id" .= chat_id, "text" .= text, "disable_notification" .= False]-	endpoint _ = "sendMessage"--instance Persistable ('Send 'Silently 'Directly) Message where-	type instance Payload ('Send 'Silently 'Directly) Message-		= Tagged ('Send 'Silently 'Directly Message) (Int64, Text)-	payload (untag -> (chat_id, text)) = object-		["chat_id" .= chat_id, "text" .= text, "disable_notification" .= True]-	endpoint _ = "sendMessage"--instance Persistable ('Send 'Notify 'Forwarding) Message where-	type instance Payload ('Send 'Notify 'Forwarding) Message-		= Tagged ('Send 'Notify 'Forwarding Message) (Int64, Int64, Int)-	payload (untag -> (chat_id, from_chat_id, message_id)) = object-		["chat_id" .= chat_id, "from_chat_id" .= from_chat_id,-			"message_id" .= message_id, "disable_notification" .= False]-	endpoint _ = "forwardMessage"--instance Persistable ('Send 'Silently 'Forwarding) Message where-	type instance Payload ('Send 'Silently 'Forwarding) Message-		= Tagged ('Send 'Silently 'Forwarding Message) (Int64, Int64, Int)-	payload (untag -> (chat_id, from_chat_id, message_id)) = object-		["chat_id" .= chat_id, "from_chat_id" .= from_chat_id,-			"message_id" .= message_id, "disable_notification" .= True]-	endpoint _ = "forwardMessage"--instance Persistable ('Send 'Notify 'Replying) Message where-	type instance Payload ('Send 'Notify 'Replying) Message-		= Tagged ('Send 'Notify 'Replying Message) (Int64, Int, Text)-	payload (untag -> (chat_id, reply_to_message_id, text)) = object-		["chat_id" .= chat_id, "reply_to_message_id" .= reply_to_message_id,-			"text" .= text, "disable_notification" .= False]-	endpoint _ = "sendMessage"+instance Identifiable Message where+	type instance Identificator Message = Int+	ident (Direct i _ _) = i+	ident (Forwarded i _ _) = i+	ident (Replied i _ _ _) = i -instance Persistable ('Send 'Silently 'Replying) Message where-	type instance Payload ('Send 'Silently 'Replying) Message-		= Tagged ('Send 'Silently 'Replying Message) (Int64, Int, Text)-	payload (untag -> (chat_id, reply_to_message_id, text)) = object-		["chat_id" .= chat_id, "reply_to_message_id" .= reply_to_message_id,-			"text" .= text, "disable_notification" .= True]+instance Persistable ('Send Message) where+	type instance Payload ('Send Message) = (Int64 :&: Text)+	payload (chat_id :&: text) = singleton "chat_id" (toJSON chat_id) <> singleton "text" (toJSON text) 	endpoint _ = "sendMessage"--instance Persistable 'Edit Message where-	type instance Payload 'Edit Message = Tagged ('Edit Message) (Int64, Int, Text)-	payload (untag -> (chat_id, message_id, text)) = object-		["chat_id" .= chat_id, "message_id" .= message_id, "text" .= text]-	endpoint _ = "editMessageText"--instance Persistable 'Purge Message where-	type instance Payload 'Purge Message = Tagged ('Purge Message) (Int64, Int)-	payload (untag -> (chat_id, message_id)) = object ["chat_id" .= chat_id, "message_id" .= message_id]-	endpoint _ = "deleteMessage"
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Audio.hs view
@@ -1,12 +1,15 @@ module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Audio (Audio (..)) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))+import "aeson" Data.Aeson (FromJSON (parseJSON)+	, object, withObject, (.:), (.:?), (.=)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int)+import "base" Data.Bool (Bool (True, False))+import "base" Data.Int (Int, Int64) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)+import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)  import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size (Size)
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Document.hs view
@@ -1,12 +1,14 @@ module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Document (Document (..)) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))+import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, object, (.:), (.:?), (.=)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int)+import "base" Data.Bool (Bool (True, False))+import "base" Data.Int (Int, Int64) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)+import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)  import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size (Size)
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Video.hs view
@@ -1,12 +1,15 @@ module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Video (Video (..)) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))+import "aeson" Data.Aeson (FromJSON (parseJSON)+	, object, withObject, (.:), (.:?), (.=)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int)+import "base" Data.Bool (Bool (True, False))+import "base" Data.Int (Int, Int64) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)+import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)  import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size (Size)
Network/API/Telegram/Bot/Object/Update/Message/Content/File/Voice.hs view
@@ -1,12 +1,15 @@ module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Voice (Voice (..)) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))+import "aeson" Data.Aeson (FromJSON (parseJSON)+	, object, withObject, (.:), (.:?), (.=)) import "base" Control.Applicative ((<*>))-import "base" Data.Int (Int)+import "base" Data.Bool (Bool (True, False))+import "base" Data.Int (Int, Int64) import "base" Data.Maybe (Maybe) import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Text.Show (Show)+import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)  data Voice = Voice Text Int (Maybe Text) (Maybe Int) deriving Show
Network/API/Telegram/Bot/Object/Update/Message/Content/Info/Location.hs view
@@ -8,11 +8,7 @@ import "base" Data.Int (Int, Int64) import "base" GHC.Float (Float) import "base" Text.Show (Show)-import "tagged" Data.Tagged (Tagged, untag) -import Network.API.Telegram.Bot.Property.Persistable (Persistable (Payload, payload, endpoint)-	, Capacity (Send), Inform (Notify, Silently), Way (Directly, Replying))- data Location = Location Float Float deriving Show  instance FromJSON Location where@@ -22,35 +18,3 @@ instance ToJSON Location where 	toJSON (Location latitude longitude) = object 		["latitude" .= latitude, "longitude" .= longitude]--instance Persistable ('Send 'Notify 'Directly) Location where-	type instance Payload ('Send 'Notify 'Directly) Location-		= Tagged ('Send 'Notify 'Directly Location) (Int64, Location, Int)-	payload (untag -> (chat_id, Location latitude longitude, live_period)) =-		object ["chat_id" .= chat_id, "latitude" .= latitude, "longitude" .= longitude,-			"live_period" .= live_period, "disable_notification" .= False]-	endpoint _ = "sendLocation"--instance Persistable ('Send 'Silently 'Directly) Location where-	type instance Payload ('Send 'Silently 'Directly) Location-		= Tagged ('Send 'Silently 'Directly Location) (Int64, Location, Int)-	payload (untag -> (chat_id, Location latitude longitude, live_period)) =-		object ["chat_id" .= chat_id, "latitude" .= latitude, "longitude" .= longitude,-			"live_period" .= live_period, "disable_notification" .= True]-	endpoint _ = "sendLocation"--instance Persistable ('Send 'Notify 'Replying) Location where-	type instance Payload ('Send 'Notify 'Replying) Location-		= Tagged ('Send 'Notify 'Replying Location) (Int64, Location, Int, Int)-	payload (untag -> (chat_id, Location latitude longitude, live_period, reply_to_message_id)) = object-		["chat_id" .= chat_id, "latitude" .= latitude, "longitude" .= longitude, "live_period" .= live_period,-			"reply_to_message_id" .= reply_to_message_id, "disable_notification" .= False]-	endpoint _ = "sendLocation"--instance Persistable ('Send 'Silently 'Replying) Location where-	type instance Payload ('Send 'Silently 'Replying) Location-		= Tagged ('Send 'Silently 'Replying Location) (Int64, Location, Int, Int)-	payload (untag -> (chat_id, Location latitude longitude, live_period, reply_to_message_id)) = object-		["chat_id" .= chat_id, "latitude" .= latitude, "longitude" .= longitude, "live_period" .= live_period,-			"reply_to_message_id" .= reply_to_message_id, "disable_notification" .= True]-	endpoint _ = "sendLocation"
Network/API/Telegram/Bot/Object/Update/Message/Content/Poll.hs view
@@ -2,14 +2,16 @@  import Network.API.Telegram.Bot.Object.Update.Message.Content.Poll.Option as Exports -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))+import "aeson" Data.Aeson (FromJSON (parseJSON), object, withObject, (.:), (.=)) import "aeson" Data.Aeson.Types (Object, Parser) import "base" Control.Applicative ((<*>)) import "base" Control.Monad ((>>=))-import "base" Data.Bool (bool)+import "base" Data.Bool (Bool (True, False), bool) import "base" Data.Function (($)) import "base" Data.Functor ((<$>))+import "base" Data.Int (Int, Int64) import "base" Text.Show (Show)+import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)  data Poll
Network/API/Telegram/Bot/Object/Update/Message/Keyboard.hs view
@@ -6,12 +6,11 @@ import "base" Data.Function (($)) import "base" Data.Functor ((<$>)) import "base" Data.Int (Int, Int64)+import "base" Data.Semigroup ((<>)) import "base" Text.Show (Show) import "tagged" Data.Tagged (Tagged, untag) import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Property.Persistable-	(Persistable (Payload, payload, endpoint), Capacity (Edit, Post))+import "unordered-containers" Data.HashMap.Strict (singleton)  data Keyboard = Inline [[Button]] deriving Show @@ -22,17 +21,3 @@ instance ToJSON Keyboard where 	toJSON (Inline buttons) = object 		["inline_keyboard" .= buttons]--instance Persistable 'Edit Keyboard where-	type instance Payload 'Edit Keyboard-		= Tagged ('Edit Keyboard) (Int64, Int, Keyboard)-	payload (untag -> (chat_id, message_id, reply_markup)) = object-		["chat_id" .= chat_id, "message_id" .= message_id, "reply_markup" .= reply_markup]-	endpoint _ = "editMessageReplyMarkup"--instance Persistable 'Post Keyboard where-	type instance Payload 'Post Keyboard-		= Tagged ('Post Keyboard) (Int64, Text, Keyboard)-	payload (untag -> (chat_id, text, kb)) = object-		["chat_id" .= chat_id, "text" .= text, "reply_markup" .= kb]-	endpoint _ = "sendMessage"
Network/API/Telegram/Bot/Object/Update/Message/Origin.hs view
@@ -11,6 +11,7 @@ import "text" Data.Text (Text)  import Network.API.Telegram.Bot.Object.Sender (Sender)+import Network.API.Telegram.Bot.Property.Identifiable (Identifiable (Identificator, ident))  data Origin 	= Private Int64 Sender@@ -29,3 +30,10 @@ 			("supergroup" :: Text) -> Supergroup <$> c .: "id" <*> c .: "title" <*> v .: "from" 			("channel" :: Text) -> Channel <$> c .: "id" <*> c .: "title" 			_ -> fail "Type of chat is not defined"++instance Identifiable Origin where+	type instance Identificator Origin = Int64+	ident (Private i _) = i+	ident (Group i _ _) = i+	ident (Supergroup i _ _) = i+	ident (Channel i _) = i
Network/API/Telegram/Bot/Object/Update/Moving.hs view
@@ -3,28 +3,23 @@ import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "aeson" Data.Aeson.Types (Object, Parser) import "base" Control.Applicative ((<*>), (<|>))-import "base" Control.Monad ((>>=)) 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.Object.Group (Group) import Network.API.Telegram.Bot.Object.Sender (Sender)  data Moving-	= Gone Sender (Int64, Text)-	| Joined [Sender] (Int64, Text)+	= Gone Sender Group+	| Joined [Sender] Group 	deriving Show  instance FromJSON Moving where 	parseJSON = withObject "Moving" $ \v -> gone v <|> joined v where  		gone :: Object -> Parser Moving-		gone v = Gone <$> v .: "left_chat_member" <*> (v .: "chat" >>= chat)+		gone v = Gone <$> v .: "left_chat_member" <*> v .: "chat"  		joined :: Object -> Parser Moving-		joined v = Joined <$> v .: "new_chat_members" <*> (v .: "chat" >>= chat)--		chat :: Object -> Parser (Int64, Text)-		chat c = (,) <$> c .: "id" <*> c .: "title"+		joined v = Joined <$> v .: "new_chat_members" <*> v .: "chat"
Network/API/Telegram/Bot/Property/Accessible.hs view
@@ -1,28 +1,7 @@ module Network.API.Telegram.Bot.Property.Accessible (Accessible (..)) where -import "base" Data.Function (flip)-import "base" Data.Functor ((<$>)) import "lens" Control.Lens (Lens') -import Network.API.Telegram.Bot.Object (Object)-import Network.API.Telegram.Bot.Object.Update.Callback (Callback (Datatext))-import Network.API.Telegram.Bot.Object.Update.Message (Message (Direct, Forward, Reply))-import Network.API.Telegram.Bot.Object.Update.Message.Content (Content)-import Network.API.Telegram.Bot.Object.Update.Message.Origin (Origin)--class Object source => Accessible target source where+class Accessible target source where+	{-# MINIMAL access #-} 	access :: Lens' source target--instance Accessible Content Message where-	access f (Direct msg_id origin content) = (\content' -> Direct msg_id origin content') <$> f content-	access f (Forward msg_id origin content) = (\content' -> Forward msg_id origin content') <$> f content-	access f (Reply msg_id origin content msg) = (\content' -> Reply msg_id origin content' msg) <$> f content--instance Accessible Origin Callback where-	access f (Datatext cq_id msg dttxt) = flip-		(Datatext cq_id) dttxt <$> access f msg--instance Accessible Origin Message where-	access f (Direct msg_id origin content) = (\origin' -> Direct msg_id origin' content) <$> f origin-	access f (Forward msg_id origin content) = (\origin' -> Forward msg_id origin' content) <$> f origin-	access f (Reply msg_id origin content msg) = (\origin' -> Reply msg_id origin' content msg) <$> f origin
Network/API/Telegram/Bot/Property/Identifiable.hs view
@@ -1,46 +1,6 @@-module Network.API.Telegram.Bot.Property.Identifiable (Identifiable (..), Identificator) where--import "base" Data.Int (Int, Int64)-import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Object (Object)-import Network.API.Telegram.Bot.Object.Update (Update (Query, Membership, Incoming))-import Network.API.Telegram.Bot.Object.Update.Callback (Callback (Datatext))-import Network.API.Telegram.Bot.Object.Update.Message (Message (Direct, Forward, Reply))-import Network.API.Telegram.Bot.Object.Update.Message.Origin (Origin (Private, Group, Supergroup, Channel))-import Network.API.Telegram.Bot.Object.Sender (Sender (Bot, User))--type family Identificator o = i--class Object o => Identifiable o where-	{-# MINIMAL identificator #-}-	identificator :: o -> Identificator o--type instance Identificator Callback = Text-type instance Identificator Message = Int-type instance Identificator Origin = Int64-type instance Identificator Sender = Int-type instance Identificator Update = Int--instance Identifiable Callback where-	identificator (Datatext i _ _) = i--instance Identifiable Message where-	identificator (Direct i _ _) = i-	identificator (Forward i _ _) = i-	identificator (Reply i _ _ _) = i--instance Identifiable Origin where-	identificator (Private i _) = i-	identificator (Group i _ _) = i-	identificator (Supergroup i _ _) = i-	identificator (Channel i _) = i--instance Identifiable Sender where-	identificator (Bot i _ _ _ _) = i-	identificator (User i _ _ _ _) = i+module Network.API.Telegram.Bot.Property.Identifiable (Identifiable (..)) where -instance Identifiable Update where-	identificator (Query i _) = i-	identificator (Membership i _) = i-	identificator (Incoming i _) = i+class Identifiable o where+	{-# MINIMAL ident #-}+	type family Identificator o :: *+	ident :: o -> Identificator o
Network/API/Telegram/Bot/Property/Persistable.hs view
@@ -1,11 +1,13 @@ module Network.API.Telegram.Bot.Property.Persistable-	(Persistable (..), Capacity (..), Inform (..), Way (..)) where+	(Persistable (..), Capacity (..), Silenlty (..)) where -import "aeson" Data.Aeson (FromJSON, Value, decode)+import "aeson" Data.Aeson (FromJSON, ToJSON (toJSON), Value (Object), Object, decode) import "base" Control.Exception (try) import "base" Control.Monad (Monad ((>>=)), join)+import "base" Data.Bool (Bool (True)) import "base" Data.Function (flip, (.), ($)) import "base" Data.Functor (Functor (fmap), (<$>))+import "base" Data.Int (Int) import "base" Data.Maybe (fromJust) import "base" Data.Semigroup (Semigroup ((<>))) import "base" Data.String (String)@@ -15,25 +17,36 @@ import "transformers" Control.Monad.Trans.Class (lift) import "transformers" Control.Monad.Trans.Except (ExceptT (ExceptT)) import "transformers" Control.Monad.Trans.Reader (ask)+import "unordered-containers" Data.HashMap.Strict (singleton)+import "with" Data.With (type (:&:)((:&:))) import "wreq" Network.Wreq.Session (post)  import Network.API.Telegram.Bot.Core (Telegram, Token (Token), Ok, result) -data Inform = Silently | Notify--data Way = Directly | Forwarding | Replying+data Capacity object = Send object | Reply object -data Capacity object = Send Inform Way object | Post object | Fetch object | Edit object | Purge object+data Silenlty (capacity :: * -> Capacity *) object = Silenlty -class Persistable capacity object where+class Persistable action where 	{-# MINIMAL payload, endpoint #-}-	type Payload (capacity :: * -> Capacity *) object = payload | payload -> capacity object-	payload :: Payload capacity object -> Value-	endpoint :: Payload capacity object -> String-	persist :: FromJSON r => Payload capacity object -> Telegram e r-	persist x = request (endpoint x) (payload x) where+	type Payload action = payload | payload -> action+	payload :: Payload action -> Object+	endpoint :: Payload action -> String+	persist :: FromJSON r => Payload action -> Telegram e r+	persist x = request (endpoint x) (Object $ payload x) where  		request :: forall a e . FromJSON a => String -> Value -> Telegram e a 		request e p = snd <$> ask >>= \(session, Token token) -> lift . ExceptT . try 			. fmap (fromJust . join . fmap result . decode @(Ok a) . responseBody) 				. flip (post session) p $ "https://api.telegram.org/" <> unpack token <> "/" <> e++instance Persistable ('Send obj) => Persistable (Silenlty 'Send obj) where+	type Payload (Silenlty 'Send obj) = (Silenlty 'Send obj :&: Payload ('Send obj))+	payload (_ :&: x) = payload x <> singleton "disable_notification" (toJSON True)+	endpoint (_ :&: x) = endpoint x++instance Persistable ('Send obj) => Persistable ('Reply obj) where+	type Payload ('Reply obj) = (Int :&: Payload ('Send obj))+	payload (reply_to_message_id :&: x) = payload x <> singleton+		"reply_to_message_id" (toJSON reply_to_message_id)+	endpoint (_ :&: x) = endpoint x
telega.cabal view
@@ -1,5 +1,5 @@ name:                telega-version:             0.2.1+version:             0.2.2 synopsis:            Telegram Bot API binding description:         High-level bindings, typed entities, inline mode only homepage:            https://github.com/iokasimov/telega@@ -22,6 +22,7 @@     Network.API.Telegram.Bot     Network.API.Telegram.Bot.Core     Network.API.Telegram.Bot.Object+    Network.API.Telegram.Bot.Object.Group     Network.API.Telegram.Bot.Object.Member     Network.API.Telegram.Bot.Object.Member.Powers     Network.API.Telegram.Bot.Object.Member.Restrictions@@ -49,7 +50,7 @@     Network.API.Telegram.Bot.Property.Accessible     Network.API.Telegram.Bot.Property.Identifiable     Network.API.Telegram.Bot.Property.Persistable-  build-depends: base == 4.*, transformers, tagged, lens, aeson, text, time, http-client, wreq+  build-depends: base == 4.*, transformers, tagged, with, lens, aeson, text, unordered-containers, time, http-client, wreq   default-extensions: DataKinds, LambdaCase, OverloadedStrings, NoImplicitPrelude, PackageImports, ViewPatterns,     AllowAmbiguousTypes, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances, UndecidableSuperClasses,     FlexibleInstances, TypeApplications, TypeFamilies, TypeFamilyDependencies, TypeOperators, PolyKinds