packages feed

telega 0.1.6 → 0.1.7

raw patch · 10 files changed

+195/−15 lines, 10 files

Files

CHANGELOG.md view
@@ -46,3 +46,11 @@ * Put `Keyboard` submodule into `Message` submodule * Put `Callback`, `Message` and `Moving` modules into `Update` submodule * Rename `From` to `Sender` and move it from `Message` and `Update` submodules++# 0.1.7+* Define `Identifiable` instance for `Callback` datatype+* Add `Reply` constructor to `Message` datatype+* Add `Attachment` constructor to `Content` datatype+* Define `File` for animations, audio, documents, photos, videos or voices+* Extract `Size` datatype into separated module within `Content` submodule+* Define `Location` and `Info` datatypes within `Content` submodule
Network/Telegram/API/Bot/Object/Update/Message.hs view
@@ -20,21 +20,22 @@ data Message 	= Direct Int Origin Content 	| Forward Int Origin Content+	| Reply Int Origin Content Message 	deriving Show  instance FromJSON Message where 	parseJSON = withObject "Message" $ \v ->-		forward_from_channel v <|> forward_from_chat v <|> direct v where+		forward_channel v <|> forward_chat v <|> reply v <|> direct v where -		forward_from_channel :: Object -> Parser Message-		forward_from_channel v = Forward <$> v .: "forward_from_message_id"+		forward_channel :: Object -> Parser Message+		forward_channel v = Forward <$> 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_from_chat :: Object -> Parser Message-		forward_from_chat v = Forward <$> v .: "message_id"+		forward_chat :: Object -> Parser Message+		forward_chat v = Forward <$> v .: "message_id" 			<*> (v .: "chat" >>= chat) <*> parseJSON (Object v) where  			chat :: Value -> Parser Origin@@ -43,6 +44,10 @@ 				("group" :: Text) -> Group <$> c .: "id" <*> c .: "title" <*> v .: "forward_from" 				("supergroup" :: Text) -> Supergroup <$> c .: "id" <*> c .: "title" <*> v .: "forward_from" 				_ -> fail "Type of chat is not defined"++		reply :: Object -> Parser Message+		reply v = Reply <$> v .: "message_id" <*> parseJSON (Object v)+			<*> parseJSON (Object v) <*> v .: "reply_to_message"  		direct :: Object -> Parser Message 		direct v = Direct <$> v .: "message_id"
Network/Telegram/API/Bot/Object/Update/Message/Content.hs view
@@ -1,13 +1,18 @@-module Network.Telegram.API.Bot.Object.Update.Message.Content (Content (..)) where+module Network.Telegram.API.Bot.Object.Update.Message.Content (Content (..), module Exports) where -import "aeson" Data.Aeson (FromJSON (parseJSON), withArray, withObject, (.:))-import "aeson" Data.Aeson.Types (Object, Parser, Value)+import Network.Telegram.API.Bot.Object.Update.Message.Content.File as Exports+import Network.Telegram.API.Bot.Object.Update.Message.Content.Info as Exports+import Network.Telegram.API.Bot.Object.Update.Message.Content.Size as Exports++import "aeson" Data.Aeson (FromJSON (parseJSON), withArray, withObject, (.:), (.:?))+import "aeson" Data.Aeson.Types (Object, Parser, Value (Object)) import "base" Control.Applicative (Applicative ((<*>)), Alternative (empty, (<|>))) import "base" Control.Monad (Monad ((>>=)), fail) import "base" Data.Function ((.), ($)) import "base" Data.Functor ((<$>)) import "base" Data.Foldable (Foldable (foldr)) import "base" Data.Int (Int)+import "base" Data.Maybe (Maybe) import "base" Text.Show (Show) import "base" Prelude ((+)) import "text" Data.Text (Text, drop, take)@@ -15,17 +20,16 @@ data Content 	= Textual Text 	| Command Text+	| Attachment (Maybe Text) File+	| Information Info 	deriving Show  instance FromJSON Content where-	parseJSON = withObject "Content" $ \v -> command v <|> textual v where+	parseJSON = withObject "Content" $ \v -> command v <|> attachment v <|> other v <|> textual v where  		command :: Object -> Parser Content 		command v = Command <$> (v .: "entities" >>= command_entity >>= extract_command v) -		textual :: Object -> Parser Content-		textual v = Textual <$> v .: "text"- 		command_entity :: Value -> Parser (Int, Int) 		command_entity = withArray "Command content" $ \a -> 			foldr ((<|>) . entity) empty a where@@ -37,3 +41,12 @@  		extract_command :: Object -> (Int, Int) -> Parser Text 		extract_command v (ofs, len) = (take len . drop (ofs + 1)) <$> v .: "text"++		attachment :: Object -> Parser Content+		attachment v = Attachment <$> v .:? "caption" <*> parseJSON (Object v)++		other :: Object -> Parser Content+		other v = Information <$> parseJSON (Object v)++		textual :: Object -> Parser Content+		textual v = Textual <$> v .: "text"
+ Network/Telegram/API/Bot/Object/Update/Message/Content/File.hs view
@@ -0,0 +1,68 @@+module Network.Telegram.API.Bot.Object.Update.Message.Content.File (File (..)) 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 "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.Telegram.API.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)+	| 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 :: 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"++		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"++		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"++		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"
+ Network/Telegram/API/Bot/Object/Update/Message/Content/Info.hs view
@@ -0,0 +1,41 @@+module Network.Telegram.API.Bot.Object.Update.Message.Content.Info (Info (..)) where++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.Telegram.API.Bot.Object.Update.Message.Content.Location (Location)++data Info = Point Location+	| Contact (Maybe Int) Text (Maybe Text) Text (Maybe Text)+	| Venue Location Text Text (Maybe Text) (Maybe Text)+	deriving Show++instance FromJSON Info where+	parseJSON = withObject "Info" $ \v -> contact v <|> venue v <|> point v where++		contact :: Object -> Parser Info+		contact v = v .: "contact" >>= info where++			info :: Value -> Parser Info+			info = withObject "Contact" $ \i -> Contact <$> i .:? "user_id"+				<*> i .: "first_name" <*> i .:? "last_name"+				<*> i .: "phone_number" <*> i .:? "vcard"++		venue :: Object -> Parser Info+		venue v = v .: "venue" >>= info where++			info :: Value -> Parser Info+			info = withObject "Venue" $ \i -> Venue+				<$> i .: "location" <*> i .: "title" <*> i .: "address"+				<*> i .:? "foursquare_id" <*> i .:? "foursquare_type"++		point :: Object -> Parser Info+		point v = Point <$> v .: "location"
+ Network/Telegram/API/Bot/Object/Update/Message/Content/Location.hs view
@@ -0,0 +1,15 @@+module Network.Telegram.API.Bot.Object.Update.Message.Content.Location (Location (..)) where++import "aeson" Data.Aeson (FromJSON (parseJSON), 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"
+ Network/Telegram/API/Bot/Object/Update/Message/Content/Size.hs view
@@ -0,0 +1,17 @@+module Network.Telegram.API.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/Telegram/API/Bot/Property/Accessible.hs view
@@ -6,7 +6,7 @@  import Network.Telegram.API.Bot.Object (Object) import Network.Telegram.API.Bot.Object.Update.Callback (Callback (Datatext))-import Network.Telegram.API.Bot.Object.Update.Message (Message (Direct, Forward))+import Network.Telegram.API.Bot.Object.Update.Message (Message (Direct, Forward, Reply)) import Network.Telegram.API.Bot.Object.Update.Message.Content (Content) import Network.Telegram.API.Bot.Object.Update.Message.Origin (Origin) @@ -16,6 +16,7 @@ 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@@ -24,3 +25,4 @@ 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/Telegram/API/Bot/Property/Identifiable.hs view
@@ -1,10 +1,12 @@ module Network.Telegram.API.Bot.Property.Identifiable (Identifiable (..), Identificator) where  import "base" Data.Int (Int, Int64)+import "text" Data.Text (Text)  import Network.Telegram.API.Bot.Object (Object) import Network.Telegram.API.Bot.Object.Update (Update (Query, Membership, Incoming))-import Network.Telegram.API.Bot.Object.Update.Message (Message (Direct, Forward))+import Network.Telegram.API.Bot.Object.Update.Callback (Callback (Datatext))+import Network.Telegram.API.Bot.Object.Update.Message (Message (Direct, Forward, Reply)) import Network.Telegram.API.Bot.Object.Update.Message.Origin (Origin (Private, Group, Supergroup, Channel)) import Network.Telegram.API.Bot.Object.Sender (Sender (Bot, User)) @@ -14,14 +16,19 @@ 	{-# 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
telega.cabal view
@@ -1,5 +1,5 @@ name:                telega-version:             0.1.6+version:             0.1.7 synopsis:            Telegram Bot API binding description:         High-level bindings, typed entities, inline mode only homepage:            https://github.com/iokasimov/telega@@ -29,6 +29,10 @@     Network.Telegram.API.Bot.Object.Update.Callback.Notification     Network.Telegram.API.Bot.Object.Update.Message     Network.Telegram.API.Bot.Object.Update.Message.Content+    Network.Telegram.API.Bot.Object.Update.Message.Content.File+    Network.Telegram.API.Bot.Object.Update.Message.Content.Info+    Network.Telegram.API.Bot.Object.Update.Message.Content.Location+    Network.Telegram.API.Bot.Object.Update.Message.Content.Size     Network.Telegram.API.Bot.Object.Update.Message.Keyboard     Network.Telegram.API.Bot.Object.Update.Message.Keyboard.Button     Network.Telegram.API.Bot.Object.Update.Message.Origin