packages feed

telega 0.1.7 → 0.1.8

raw patch · 5 files changed

+73/−23 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Property.Persistable.Post Network.Telegram.API.Bot.Object.Update.Message.Message
+ Network.Telegram.API.Bot.Object.Update.Message: Directly :: Messaging
+ Network.Telegram.API.Bot.Object.Update.Message: Forwarding :: Messaging
+ Network.Telegram.API.Bot.Object.Update.Message: Replying :: Messaging
+ Network.Telegram.API.Bot.Object.Update.Message: data Messaging
+ Network.Telegram.API.Bot.Property.Persistable: Fetch :: Capacity
+ Network.Telegram.API.Bot.Property.Persistable: PL :: a -> PL c o a
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Object.Update.Message.Directly Network.Telegram.API.Bot.Object.Update.Message.Message
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Object.Update.Message.Forwarding Network.Telegram.API.Bot.Object.Update.Message.Message
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Object.Update.Message.Replying Network.Telegram.API.Bot.Object.Update.Message.Message
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Property.Persistable.Fetch Network.Telegram.API.Bot.Object.Member.Member
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Property.Persistable.Fetch Network.Telegram.API.Bot.Object.Sender.Sender
+ Network.Telegram.API.Bot.Property.Persistable: instance Network.Telegram.API.Bot.Property.Persistable.Persistable 'Network.Telegram.API.Bot.Property.Persistable.Post Network.Telegram.API.Bot.Object.Update.Message.Keyboard.Keyboard
+ Network.Telegram.API.Bot.Property.Persistable: newtype PL c o a
- Network.Telegram.API.Bot.Object.Update.Moving: Gone :: Sender -> Moving
+ Network.Telegram.API.Bot.Object.Update.Moving: Gone :: Sender -> (Int64, Text) -> Moving
- Network.Telegram.API.Bot.Object.Update.Moving: Joined :: [Sender] -> Moving
+ Network.Telegram.API.Bot.Object.Update.Moving: Joined :: [Sender] -> (Int64, Text) -> Moving

Files

CHANGELOG.md view
@@ -54,3 +54,11 @@ * 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++# 0.1.8+* Add information about `Group` or `Supergroup` (id and title) into `Moving` datatype+* Add `Fetch` capacity, define `Persistable Fetch` for `Sender` to get info about bot+* Define `PL` newtype to avoid violating injectivity annotation of `Payload` type family+* Define `Messaging` datatype to separate direct, reply and forward `Message`+* Make first argument of `Payload` type family poly kinded (enable `PolyKinds`)+* Define `Persistable` instance for `Directly`, `Forwarding` and `Replying` `Message`
Network/Telegram/API/Bot/Object/Update/Message.hs view
@@ -1,4 +1,4 @@-module Network.Telegram.API.Bot.Object.Update.Message (Message (..), module Exports) where+module Network.Telegram.API.Bot.Object.Update.Message (Message (..), Messaging (..), module Exports) where  import Network.Telegram.API.Bot.Object.Update.Message.Content as Exports import Network.Telegram.API.Bot.Object.Update.Message.Keyboard as Exports@@ -16,6 +16,8 @@  import Network.Telegram.API.Bot.Object.Update.Message.Content (Content) import Network.Telegram.API.Bot.Object.Update.Message.Origin (Origin (Private, Group, Supergroup, Channel))++data Messaging = Directly | Forwarding | Replying  data Message 	= Direct Int Origin Content
Network/Telegram/API/Bot/Object/Update/Moving.hs view
@@ -2,20 +2,29 @@  import "aeson" Data.Aeson (FromJSON (parseJSON), withObject, (.:)) import "aeson" Data.Aeson.Types (Object, Parser)-import "base" Control.Applicative (Alternative ((<|>)))+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.Telegram.API.Bot.Object.Sender (Sender) -data Moving = Gone Sender | Joined [Sender] deriving Show+data Moving+	= Gone Sender (Int64, Text)+	| Joined [Sender] (Int64, Text)+	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"+		gone v = Gone <$> v .: "left_chat_member" <*> (v .: "chat" >>= chat)  		joined :: Object -> Parser Moving-		joined v = Joined <$> v .: "new_chat_members"+		joined v = Joined <$> v .: "new_chat_members" <*> (v .: "chat" >>= chat)++		chat :: Object -> Parser (Int64, Text)+		chat c = (,) <$> c .: "id" <*> c .: "title"
Network/Telegram/API/Bot/Property/Persistable.hs view
@@ -1,4 +1,4 @@-module Network.Telegram.API.Bot.Property.Persistable (Persistable (..), Payload, Capacity (..)) where+module Network.Telegram.API.Bot.Property.Persistable (Persistable (..), Payload, PL (..), Capacity (..)) where  import "aeson" Data.Aeson (FromJSON, Value, decode, object, (.=)) import "base" Control.Exception (try)@@ -6,7 +6,7 @@ import "base" Data.Function (flip, (.), ($)) import "base" Data.Functor (Functor (fmap), (<$>)) import "base" Data.Int (Int, Int64)-import "base" Data.Maybe (Maybe (Just, Nothing), fromJust)+import "base" Data.Maybe (fromJust) import "base" Data.Semigroup (Semigroup ((<>))) import "base" Data.String (String) import "base" Data.Tuple (snd)@@ -18,12 +18,26 @@ import "wreq" Network.Wreq.Session (post)  import Network.Telegram.API.Bot.Core (Telegram, Token (Token), Ok, result)-import Network.Telegram.API.Bot.Object (Keyboard, Notification, Message, Object)+import Network.Telegram.API.Bot.Object (Object, Keyboard, Notification, Member, Sender)+import Network.Telegram.API.Bot.Object.Update.Message (Message, Messaging (Directly, Forwarding, Replying)) -data Capacity = Post | Edit | Purge+data Capacity = Fetch | Post | Edit | Purge -type family Payload (c :: Capacity) o = r | r -> c o+newtype PL c o a = PL a +type family Payload (c :: k) o = r | r -> o c++type instance Payload 'Post Keyboard = PL 'Post Keyboard (Int64, Text, Keyboard)+type instance Payload 'Edit Keyboard = PL 'Edit Keyboard (Int64, Int, Keyboard)+type instance Payload 'Fetch Member = PL 'Fetch Member (Int64, Int)+type instance Payload 'Purge Message = PL 'Purge Message (Int64, Int)+type instance Payload 'Post Notification = PL 'Post Notification (Text, Text)+type instance Payload 'Fetch Sender = PL 'Fetch Sender ()++type instance Payload 'Directly Message = PL 'Directly Message (Int64, Text)+type instance Payload 'Forwarding Message = PL 'Forwarding Message (Int64, Int64, Int)+type instance Payload 'Replying Message = PL 'Replying Message (Int64, Int, Text)+ class Object o => Persistable c o where 	{-# MINIMAL payload, endpoint #-} 	payload :: Payload c o -> Value@@ -36,25 +50,42 @@ 			. fmap (fromJust . join . fmap result . decode @(Ok a) . responseBody) 				. flip (post session) p $ "https://api.telegram.org/" <> unpack token <> "/" <> e -type instance Payload 'Edit Keyboard = (Int64, Int, Keyboard)-type instance Payload 'Post Message = (Int64, Text, Maybe Keyboard)-type instance Payload 'Purge Message = (Int64, Int)-type instance Payload 'Post Notification = (Text, Text)- instance Persistable 'Edit Keyboard where-	payload (chat_id, message_id, reply_markup) = object+	payload (PL (chat_id, message_id, reply_markup)) = object 		["chat_id" .= chat_id, "message_id" .= message_id, "reply_markup" .= reply_markup] 	endpoint _ = "editMessageReplyMarkup" -instance Persistable 'Post Message where-	payload (chat_id, text, Nothing) = object ["chat_id" .= chat_id, "text" .= text]-	payload (chat_id, text, Just kb) = object ["chat_id" .= chat_id, "text" .= text, "reply_markup" .= kb]+instance Persistable 'Post Keyboard where+	payload (PL (chat_id, text, kb)) = object+		["chat_id" .= chat_id, "text" .= text, "reply_markup" .= kb] 	endpoint _ = "sendMessage" +instance Persistable 'Fetch Member where+	payload (PL (chat_id, user_id)) = object ["chat_id" .= chat_id, "user_id" .= user_id]+	endpoint _ = "getChatMember"++instance Persistable 'Directly Message where+	payload (PL (chat_id, text)) = object ["chat_id" .= chat_id, "text" .= text]+	endpoint _ = "sendMessage"++instance Persistable 'Forwarding Message where+	payload (PL (chat_id, from_chat_id, message_id)) = object+		["chat_id" .= chat_id, "from_chat_id" .= from_chat_id, "message_id" .= message_id]+	endpoint _ = "forwardMessage"++instance Persistable 'Replying Message where+	payload (PL (chat_id, reply_to_message_id, text)) = object+		["chat_id" .= chat_id, "reply_to_message_id" .= reply_to_message_id, "text" .= text]+	endpoint _ = "sendMessage"+ instance Persistable 'Purge Message where-	payload (chat_id, message_id) = object ["chat_id" .= chat_id, "message_id" .= message_id]+	payload (PL (chat_id, message_id)) = object ["chat_id" .= chat_id, "message_id" .= message_id] 	endpoint _ = "deleteMessage"  instance Persistable 'Post Notification where-	payload (cbq_id, text) = object ["callback_query_id" .= cbq_id, "text" .= text]+	payload (PL (cbq_id, text)) = object ["callback_query_id" .= cbq_id, "text" .= text] 	endpoint _ = "answerCallbackQuery"++instance Persistable 'Fetch Sender where+	payload (PL ()) = object []+	endpoint _ = "getMe"
telega.cabal view
@@ -1,5 +1,5 @@ name:                telega-version:             0.1.7+version:             0.1.8 synopsis:            Telegram Bot API binding description:         High-level bindings, typed entities, inline mode only homepage:            https://github.com/iokasimov/telega@@ -44,6 +44,6 @@   build-depends: base == 4.*, transformers, lens, aeson, text, time, http-client, wreq   default-extensions: DataKinds, LambdaCase, OverloadedStrings, NoImplicitPrelude, PackageImports,     AllowAmbiguousTypes, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances, UndecidableSuperClasses,-    TypeApplications, TypeFamilies, TypeFamilyDependencies, TypeOperators+    TypeApplications, TypeFamilies, TypeFamilyDependencies, TypeOperators, PolyKinds   default-language: Haskell2010   ghc-options: -Wall -fno-warn-tabs