packages feed

telega 0.2.0 → 0.2.1

raw patch · 21 files changed

+355/−230 lines, 21 files

Files

CHANGELOG.md view
@@ -80,3 +80,10 @@ * Put `Payload` type family into `Persistable` type class  # 0.2.1+* Define `Poll` and his `Option` datatypes+* Put `Size` into `File`, `Option` into `Poll`, `Location` into `Info` created submodules+* Extract `Audio`,`Document`, `Video`, `Voice` from `File` datatype into modules+* Remove `Animation` construction from `File` datatype+* 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
Network/API/Telegram/Bot/Object/Member.hs view
@@ -3,17 +3,21 @@ import Network.API.Telegram.Bot.Object.Member.Powers as Exports import Network.API.Telegram.Bot.Object.Member.Restrictions as Exports -import "aeson" Data.Aeson (FromJSON (parseJSON), Value (Object), withObject, (.:))+import "aeson" Data.Aeson (FromJSON (parseJSON), Value (Object), object, withObject, (.:), (.=)) import "base" Control.Applicative (Applicative ((<*>))) import "base" Control.Monad (Monad ((>>=)), fail) import "base" Data.Bool (Bool)+import "base" Data.Int (Int, Int64) 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 "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@@ -33,3 +37,8 @@ 		("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
@@ -1,6 +1,6 @@ module Network.API.Telegram.Bot.Object.Sender (Sender (..), nickname, firstname, lastname) where -import "aeson" Data.Aeson (FromJSON (parseJSON), Object, withObject, (.:), (.:?))+import "aeson" Data.Aeson (FromJSON (parseJSON), Object, object, withObject, (.:), (.:?)) import "aeson" Data.Aeson.Types (Parser) import "base" Control.Applicative (Applicative ((<*>))) import "base" Control.Monad (Monad ((>>=)))@@ -12,8 +12,12 @@ import "base" Data.Maybe (Maybe) import "base" Text.Show (Show) import "lens" Control.Lens (Lens')+import "tagged" Data.Tagged (Tagged) import "text" Data.Text (Text) +import Network.API.Telegram.Bot.Property.Persistable+	(Persistable (Payload, payload, endpoint), Capacity (Fetch))+ data Sender 	= Bot Int (Maybe Text) Text (Maybe Text) (Maybe Text) 	| User Int (Maybe Text) Text (Maybe Text) (Maybe Text)@@ -36,6 +40,11 @@ 			<*> 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"  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/Callback/Notification.hs view
@@ -1,3 +1,14 @@ 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,18 +4,22 @@ 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), withObject, (.:))+import "aeson" Data.Aeson (FromJSON (parseJSON), Value (Object), 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)+import "base" Data.Int (Int, Int64) 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 (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))  data Message 	= Direct Int Origin Content@@ -52,3 +56,60 @@ 		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 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]+	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.hs view
@@ -2,8 +2,7 @@  import Network.API.Telegram.Bot.Object.Update.Message.Content.File as Exports import Network.API.Telegram.Bot.Object.Update.Message.Content.Info as Exports-import Network.API.Telegram.Bot.Object.Update.Message.Content.Location as Exports-import Network.API.Telegram.Bot.Object.Update.Message.Content.Size as Exports+import Network.API.Telegram.Bot.Object.Update.Message.Content.Poll as Exports  import "aeson" Data.Aeson (FromJSON (parseJSON), withArray, withObject, (.:), (.:?)) import "aeson" Data.Aeson.Types (Object, Parser, Value (Object))@@ -22,11 +21,12 @@ 	= Textual Text 	| Command Text 	| Attachment (Maybe Text) File+	| Polling Poll 	| Information Info 	deriving Show  instance FromJSON Content where-	parseJSON = withObject "Content" $ \v -> command v <|> attachment v <|> other v <|> textual v where+	parseJSON = withObject "Content" $ \v -> command v <|> attachment v <|> information v <|> polling v <|> textual v where  		command :: Object -> Parser Content 		command v = Command <$> (v .: "entities" >>= command_entity >>= extract_command v)@@ -46,8 +46,11 @@ 		attachment :: Object -> Parser Content 		attachment v = Attachment <$> v .:? "caption" <*> parseJSON (Object v) -		other :: Object -> Parser Content-		other v = Information <$> parseJSON (Object v)+		information :: Object -> Parser Content+		information v = Information <$> parseJSON (Object v)++		polling :: Object -> Parser Content+		polling v = Polling <$> v .: "poll"  		textual :: Object -> Parser Content 		textual v = Textual <$> v .: "text"
Network/API/Telegram/Bot/Object/Update/Message/Content/File.hs view
@@ -1,68 +1,41 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.File (File (..)) where+module Network.API.Telegram.Bot.Object.Update.Message.Content.File (File (..), module Exports) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?))-import "aeson" Data.Aeson.Types (Object, Parser, Value)-import "base" Control.Applicative (Applicative ((<*>)), Alternative ((<|>)))-import "base" Control.Monad (Monad ((>>=)))+import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Audio as Exports+import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Document as Exports+import Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size 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 "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))+import "aeson" Data.Aeson.Types (Object, Parser)+import "base" Control.Applicative ((<|>)) import "base" Data.Function (($)) import "base" Data.Functor ((<$>))-import "base" Data.Int (Int)-import "base" Data.Maybe (Maybe) import "base" Text.Show (Show)-import "text" Data.Text (Text) -import Network.API.Telegram.Bot.Object.Update.Message.Content.Size (Size)- data File-	= Animation Text Int Int Int (Maybe Size) (Maybe Text) (Maybe Text) (Maybe Int)-	| Audio Text Int (Maybe Text) (Maybe Text) (Maybe Text) (Maybe Int) (Maybe Size)-	| Document Text (Maybe Size) (Maybe Text) (Maybe Text) (Maybe Int)-	| Video Text Int Int Int (Maybe Size) (Maybe Text) (Maybe Int)-	| Voice Text Int (Maybe Text) (Maybe Int)+	= Audiofile Audio+	| Videofile Video+	| General Document+	| Voicerecord Voice 	| Photo [Size] 	deriving Show  instance FromJSON File where 	parseJSON = withObject "Message" $ \v -> photo v <|> document v-		<|> audio v <|> video v <|> animation v <|> voice v where--		animation :: Object -> Parser File-		animation v = v .: "animation" >>= file where--			file :: Value -> Parser File-			file = withObject "Animation" $ \f -> Animation <$> f .: "file_id"-				<*> f .: "width" <*> f .: "height" <*> f .: "duration" <*> f .:? "thumb"-				<*> f .:? "file_name" <*> f .:? "mime_type" <*> f .:? "file_size"+		<|> audio v <|> video v <|> voice v where  		audio :: Object -> Parser File-		audio v = v .: "audio" >>= file where--			file :: Value -> Parser File-			file = withObject "Audio" $ \f -> Audio <$> f .: "file_id"-				<*> f .: "duration" <*> f .:? "performer" <*> f .:? "title"-				<*> f .:? "mime_type" <*> f .:? "file_size" <*> f .:? "thumb"+		audio v = Audiofile <$> v .: "audio"  		document :: Object -> Parser File-		document v = v .: "document" >>= file where--			file :: Value -> Parser File-			file = withObject "Document" $ \f -> Document <$> f .: "file_id"-				<*> f .:? "thumb" <*> f .:? "file_name" <*> f .:? "mime_type" <*> f .:? "file_size"+		document v = General <$> v .: "document"  		photo :: Object -> Parser File 		photo v = Photo <$> v .: "photo"  		video :: Object -> Parser File-		video v = v .: "video" >>= file where--			file :: Value -> Parser File-			file = withObject "Video" $ \f -> Video <$> f .: "file_id"-				<*> f .: "width" <*> f .: "height" <*> f .: "duration"-				<*> f .:?  "thumb" <*> f .:? "mime_type" <*> f .:? "file_size"+		video v = Videofile <$> v .: "video"  		voice :: Object -> Parser File-		voice v = v .: "voice" >>= file where--			file :: Value -> Parser File-			file = withObject "Voice" $ \f -> Voice <$> f .: "file_id"-				<*> f .: "duration" <*> f .:? "mime_type" <*> f .:? "file_size"+		voice v = Voicerecord <$> v .: "voice"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/File/Audio.hs view
@@ -0,0 +1,20 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Audio (Audio (..)) where++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.Size (Size)++data Audio = Audio Text Int (Maybe Text) (Maybe Text) (Maybe Text) (Maybe Int) (Maybe Size)+	deriving Show++instance FromJSON Audio where+	parseJSON = withObject "Audio" $ \v -> Audio <$> v .: "file_id"+		<*> v .: "duration" <*> v .:? "performer" <*> v .:? "title"+		<*> v .:? "mime_type" <*> v .:? "file_size" <*> v .:? "thumb"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/File/Document.hs view
@@ -0,0 +1,19 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Document (Document (..)) where++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.Size (Size)++data Document = Document Text (Maybe Size) (Maybe Text) (Maybe Text) (Maybe Int)+	deriving Show++instance FromJSON Document where+	parseJSON = withObject "Document" $ \v -> Document <$> v .: "file_id"+		<*> v .:? "thumb" <*> v .:? "file_name" <*> v .:? "mime_type" <*> v .:? "file_size"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/File/Size.hs view
@@ -0,0 +1,16 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size (Size (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))+import "base" Control.Applicative ((<*>))+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)++data Size = Size Text Int Int (Maybe Int) deriving Show++instance FromJSON Size where+	parseJSON = withObject "Size" $ \v -> Size <$> v .: "file_id"+		<*> v .: "width" <*> v .: "height" <*> v .: "file_size"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/File/Video.hs view
@@ -0,0 +1,20 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Video (Video (..)) where++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.Size (Size)++data Video = Video Text Int Int Int (Maybe Size) (Maybe Text) (Maybe Int)+	deriving Show++instance FromJSON Video where+	parseJSON = withObject "Video" $ \v -> Video <$> v .: "file_id"+		<*> v .: "width" <*> v .: "height" <*> v .: "duration"+		<*> v .:?  "thumb" <*> v .:? "mime_type" <*> v .:? "file_size"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/File/Voice.hs view
@@ -0,0 +1,16 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.File.Voice (Voice (..)) where++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)++data Voice = Voice Text Int (Maybe Text) (Maybe Int) deriving Show++instance FromJSON Voice where+	parseJSON = withObject "Voice" $ \v -> Voice <$> v .: "file_id"+		<*> v .: "duration" <*> v .:? "mime_type" <*> v .:? "file_size"
Network/API/Telegram/Bot/Object/Update/Message/Content/Info.hs view
@@ -1,17 +1,16 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.Info (Info (..)) where+module Network.API.Telegram.Bot.Object.Update.Message.Content.Info (Info (..), module Exports) where +import Network.API.Telegram.Bot.Object.Update.Message.Content.Info.Location as Exports+ import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:), (.:?)) import "aeson" Data.Aeson.Types (Object, Parser, Value) import "base" Control.Applicative ((<*>), (<|>)) import "base" Control.Monad ((>>=)) import "base" Data.Function (($)) import "base" Data.Functor ((<$>))-import "base" Data.Int (Int) import "base" Data.Maybe (Maybe) import "base" Text.Show (Show) import "text" Data.Text (Text)--import Network.API.Telegram.Bot.Object.Update.Message.Content.Location (Location)  data Info = Point Location 	| Contact Text (Maybe Text) Text (Maybe Text)
+ Network/API/Telegram/Bot/Object/Update/Message/Content/Info/Location.hs view
@@ -0,0 +1,56 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.Info.Location (Location (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), object, withObject, (.:), (.=))+import "base" Control.Applicative ((<*>))+import "base" Data.Bool (Bool (True, False))+import "base" Data.Function (($))+import "base" Data.Functor ((<$>))+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+	parseJSON = withObject "Location" $ \v -> Location+		<$> v .: "longitude" <*> v .: "latitude"++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/Location.hs
@@ -1,19 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.Location (Location (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), object, withObject, (.:), (.=))-import "base" Control.Applicative ((<*>))-import "base" Data.Function (($))-import "base" Data.Functor ((<$>))-import "base" GHC.Float (Float)-import "base" Text.Show (Show)--data Location = Location Float Float-	deriving Show--instance FromJSON Location where-	parseJSON = withObject "Location" $ \v -> Location-		<$> v .: "longitude" <*> v .: "latitude"--instance ToJSON Location where-	toJSON (Location latitude longitude) = object-		["latitude" .= latitude, "longitude" .= longitude]
+ Network/API/Telegram/Bot/Object/Update/Message/Content/Poll.hs view
@@ -0,0 +1,27 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.Poll (Poll (..)) where++import Network.API.Telegram.Bot.Object.Update.Message.Content.Poll.Option as Exports++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.Bool (bool)+import "base" Data.Function (($))+import "base" Data.Functor ((<$>))+import "base" Text.Show (Show)+import "text" Data.Text (Text)++data Poll+	= Opened Text Text [Option]+	| Closed Text Text [Option]+	deriving Show++type State = Text -> Text -> [Option] -> Poll++instance FromJSON Poll where+	parseJSON = withObject "Pool" $ \v -> v .: "is_closed"+		>>= bool (state v Opened) (state v Closed) where++		state :: Object -> State -> Parser Poll+		state v f = f <$> v .: "id" <*> v .: "question" <*> v .: "options"
+ Network/API/Telegram/Bot/Object/Update/Message/Content/Poll/Option.hs view
@@ -0,0 +1,15 @@+module Network.API.Telegram.Bot.Object.Update.Message.Content.Poll.Option (Option (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), 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++instance FromJSON Option where+	parseJSON = withObject "Option" $ \v -> Option+		<$> v .: "text" <*> v .: "voter_counter"
− Network/API/Telegram/Bot/Object/Update/Message/Content/Size.hs
@@ -1,17 +0,0 @@-module Network.API.Telegram.Bot.Object.Update.Message.Content.Size (Size (..)) where--import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:))-import "base" Control.Applicative ((<*>))-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)--data Size = Size Text Int Int (Maybe Int)-	deriving Show--instance FromJSON Size where-	parseJSON = withObject "Size" $ \v -> Size <$> v .: "file_id"-		<*> v .: "width" <*> v .: "height" <*> v .: "file_size"
Network/API/Telegram/Bot/Object/Update/Message/Keyboard.hs view
@@ -5,9 +5,13 @@ import "aeson" Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), object, withObject, (.:), (.=)) 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) -import Network.API.Telegram.Bot.Object.Update.Message.Keyboard.Button (Button)+import Network.API.Telegram.Bot.Property.Persistable+	(Persistable (Payload, payload, endpoint), Capacity (Edit, Post))  data Keyboard = Inline [[Button]] deriving Show @@ -18,3 +22,17 @@ 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/Property/Persistable.hs view
@@ -1,29 +1,23 @@ module Network.API.Telegram.Bot.Property.Persistable 	(Persistable (..), Capacity (..), Inform (..), Way (..)) where -import "aeson" Data.Aeson (FromJSON, Value, decode, object, (.=))+import "aeson" Data.Aeson (FromJSON, Value, decode) import "base" Control.Exception (try) import "base" Control.Monad (Monad ((>>=)), join)-import "base" Data.Bool (Bool (False, True)) import "base" Data.Function (flip, (.), ($)) import "base" Data.Functor (Functor (fmap), (<$>))-import "base" Data.Int (Int, Int64) import "base" Data.Maybe (fromJust) import "base" Data.Semigroup (Semigroup ((<>))) import "base" Data.String (String) import "base" Data.Tuple (snd) import "http-client" Network.HTTP.Client (Response (responseBody))-import "tagged" Data.Tagged (Tagged, untag)-import "text" Data.Text (Text, unpack)+import "text" Data.Text (unpack) import "transformers" Control.Monad.Trans.Class (lift) import "transformers" Control.Monad.Trans.Except (ExceptT (ExceptT)) import "transformers" Control.Monad.Trans.Reader (ask) import "wreq" Network.Wreq.Session (post)  import Network.API.Telegram.Bot.Core (Telegram, Token (Token), Ok, result)-import Network.API.Telegram.Bot.Object (Object, Keyboard, Notification, Member, Sender)-import Network.API.Telegram.Bot.Object.Update.Message (Message)-import Network.API.Telegram.Bot.Object.Update.Message.Content.Location (Location (Location))  data Inform = Silently | Notify @@ -31,133 +25,15 @@  data Capacity object = Send Inform Way object | Post object | Fetch object | Edit object | Purge object -class Object object => Persistable capacity object where+class Persistable capacity object where 	{-# MINIMAL payload, endpoint #-} 	type Payload (capacity :: * -> Capacity *) object = payload | payload -> capacity object 	payload :: Payload capacity object -> Value 	endpoint :: Payload capacity object -> String-	request :: FromJSON r => Payload capacity object -> Telegram e r-	request x = request' (endpoint x) (payload x) where+	persist :: FromJSON r => Payload capacity object -> Telegram e r+	persist x = request (endpoint x) (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+		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 '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"--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"--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"--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 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]-	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"----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"----instance Persistable 'Fetch Sender where-	type instance Payload 'Fetch Sender = Tagged ('Fetch Sender) ()-	payload _ = object []-	endpoint _ = "getMe"
telega.cabal view
@@ -1,5 +1,5 @@ name:                telega-version:             0.2.0+version:             0.2.1 synopsis:            Telegram Bot API binding description:         High-level bindings, typed entities, inline mode only homepage:            https://github.com/iokasimov/telega@@ -32,9 +32,15 @@     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.Audio+    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Document+    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Size+    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Video+    Network.API.Telegram.Bot.Object.Update.Message.Content.File.Voice     Network.API.Telegram.Bot.Object.Update.Message.Content.Info-    Network.API.Telegram.Bot.Object.Update.Message.Content.Location-    Network.API.Telegram.Bot.Object.Update.Message.Content.Size+    Network.API.Telegram.Bot.Object.Update.Message.Content.Info.Location+    Network.API.Telegram.Bot.Object.Update.Message.Content.Poll+    Network.API.Telegram.Bot.Object.Update.Message.Content.Poll.Option     Network.API.Telegram.Bot.Object.Update.Message.Keyboard     Network.API.Telegram.Bot.Object.Update.Message.Keyboard.Button     Network.API.Telegram.Bot.Object.Update.Message.Origin