telegram-bot-simple 0.2.0 → 0.3.0
raw patch · 9 files changed
+99/−18 lines, 9 filesdep ~servant-clientnew-uploader
Dependency ranges changed: servant-client
Files
- CHANGELOG.md +16/−0
- README.md +6/−0
- src/Telegram/Bot/API/Chat.hs +26/−0
- src/Telegram/Bot/API/MakingRequests.hs +2/−3
- src/Telegram/Bot/API/Methods.hs +13/−0
- src/Telegram/Bot/API/Types.hs +19/−3
- src/Telegram/Bot/Simple/BotApp.hs +10/−6
- src/Telegram/Bot/Simple/UpdateParser.hs +0/−1
- telegram-bot-simple.cabal +7/−5
CHANGELOG.md view
@@ -1,3 +1,19 @@+0.3.0+---++- Add `underline` and `strikethrough` `MessageEntityTypes` (see [#25]( https://github.com/fizruk/telegram-bot-simple/pull/25 ));+- Fix for Stack 15 (see [#24]( https://github.com/fizruk/telegram-bot-simple/pull/24 ));+- Fix installation after breaking change in `servant-0.16` (see [#21]( https://github.com/fizruk/telegram-bot-simple/pull/21 ));+- Add `phonenumber` type (see [#23]( https://github.com/fizruk/telegram-bot-simple/pull/23 ));+- Add `cashtag` message entity type (close #19) (see [#20]( https://github.com/fizruk/telegram-bot-simple/pull/20 ));+- Feat/kick chat member (see [#17]( https://github.com/fizruk/telegram-bot-simple/pull/17 ));+- Feat/delete message method (see [#16]( https://github.com/fizruk/telegram-bot-simple/pull/16 ));+- Fix `startBotAsync`, add `processActionsIndefinitely` (see [#12]( https://github.com/fizruk/telegram-bot-simple/pull/12 ));+- Add some badges to README (Hackage/Stackage/Travis) (see [11f13f3]( https://github.com/fizruk/telegram-bot-simple/commit/11f13f3 ));+- Remove temporary `files/scripts` from repo (see [6bc9f48]( https://github.com/fizruk/telegram-bot-simple/commit/6bc9f48 ));+- Add info about LambdaConf 2018 workshop and contributing (see [1ba4d95]( https://github.com/fizruk/telegram-bot-simple/commit/1ba4d95 ));+- Add `Data.Monoid` import to fix builds on GHC 8.2 (see [c798001]( https://github.com/fizruk/telegram-bot-simple/commit/c798001 ));+ 0.2.0 ---
README.md view
@@ -1,5 +1,11 @@ # telegram-bot-simple +[](https://travis-ci.org/fizruk/telegram-bot-simple)++[](http://hackage.haskell.org/package/telegram-bot-simple)+[](http://stackage.org/lts/package/telegram-bot-simple)+[](http://stackage.org/nightly/package/telegram-bot-simple)+ Easy to use library for building Telegram bots in Haskell. _**Disclaimer:** this library is under development.
+ src/Telegram/Bot/API/Chat.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}+module Telegram.Bot.API.Chat where++import Data.Coerce (coerce)+import Data.Proxy+import Servant.API+import Servant.Client hiding (Response)++import Telegram.Bot.API.Internal.Utils+import Telegram.Bot.API.MakingRequests+import Telegram.Bot.API.Types++-- * Available methods++-- ** 'kickChatMember'+type KickChatMember = "kickChatMember"+ :> RequiredQueryParam "chat_id" ChatId+ :> RequiredQueryParam "user_id" UserId+ :> Get '[JSON] (Response Bool)++-- | Use this method to kick user from chat.+-- On success, the sent Bool is returned.+kickChatMember :: ChatId -> UserId -> ClientM (Response Bool)+kickChatMember = client (Proxy @KickChatMember)
src/Telegram/Bot/API/MakingRequests.hs view
@@ -23,12 +23,11 @@ (Text.unpack ("/bot" <> toUrlPiece token)) defaultTelegramClientEnv :: Token -> IO ClientEnv-defaultTelegramClientEnv token = ClientEnv+defaultTelegramClientEnv token = mkClientEnv <$> newManager tlsManagerSettings <*> pure (botBaseUrl token)- <*> pure Nothing -defaultRunBot :: Token -> ClientM a -> IO (Either ServantError a)+defaultRunBot :: Token -> ClientM a -> IO (Either ClientError a) defaultRunBot token bot = do env <- defaultTelegramClientEnv token runClientM bot env
src/Telegram/Bot/API/Methods.hs view
@@ -27,6 +27,19 @@ getMe :: ClientM (Response User) getMe = client (Proxy @GetMe) +-- ** 'deleteMessage'++-- | Notice that deleting by POST method was bugged, so we use GET+type DeleteMessage = "deleteMessage"+ :> RequiredQueryParam "chat_id" ChatId+ :> RequiredQueryParam "message_id" MessageId+ :> Get '[JSON] (Response Bool)++-- | Use this method to delete message in chat.+-- On success, the sent Bool is returned.+deleteMessage :: ChatId -> MessageId -> ClientM (Response Bool)+deleteMessage = client (Proxy @DeleteMessage)+ -- ** 'sendMessage' type SendMessage
src/Telegram/Bot/API/Types.hs view
@@ -1,19 +1,25 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-} module Telegram.Bot.API.Types where import Data.Aeson (ToJSON(..), FromJSON(..))+import Data.Coerce (coerce) import Data.Int (Int32) import Data.Hashable (Hashable) import Data.String-import Data.Text (Text)+import Data.Text (Text, pack) import Data.Time.Clock.POSIX (POSIXTime) import GHC.Generics (Generic)+import Servant.API import Telegram.Bot.API.Internal.Utils +type RequiredQueryParam = QueryParam' '[Required, Strict]+ newtype Seconds = Seconds Int32 deriving (Eq, Show, Num, ToJSON, FromJSON) @@ -37,6 +43,8 @@ newtype UserId = UserId Int32 deriving (Eq, Show, ToJSON, FromJSON) +instance ToHttpApiData UserId where toUrlPiece = pack . show @Int32 . coerce+ -- ** Chat -- | This object represents a chat.@@ -62,6 +70,8 @@ newtype ChatId = ChatId Integer deriving (Eq, Show, ToJSON, FromJSON, Hashable) +instance ToHttpApiData ChatId where toUrlPiece a = pack . show @Integer $ coerce a+ -- | Type of chat. data ChatType = ChatTypePrivate@@ -129,6 +139,8 @@ newtype MessageId = MessageId Int32 deriving (Eq, Show, ToJSON, FromJSON) +instance ToHttpApiData MessageId where toUrlPiece a = pack . show @Int32 $ coerce a+ -- | The unique identifier of a media message group a message belongs to. newtype MediaGroupId = MediaGroupId Text deriving (Eq, Show, ToJSON, FromJSON)@@ -137,14 +149,14 @@ -- | This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. data MessageEntity = MessageEntity- { messageEntityType :: MessageEntityType -- ^ Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)+ { messageEntityType :: MessageEntityType -- ^ Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), underline (underlined text), strikethrough, code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames) , messageEntityOffset :: Int32 -- ^ Offset in UTF-16 code units to the start of the entity , messageEntityLength :: Int32 -- ^ Length of the entity in UTF-16 code units , messageEntityUrl :: Maybe Text -- ^ For “text_link” only, url that will be opened after user taps on the text , messageEntityUser :: Maybe User -- ^ For “text_mention” only, the mentioned user } deriving (Generic, Show) --- | Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)+-- | Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), underline (underlined text), strikethrough, code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames), cashtag, phone_number data MessageEntityType = MessageEntityMention | MessageEntityHashtag@@ -153,10 +165,14 @@ | MessageEntityEmail | MessageEntityBold | MessageEntityItalic+ | MessageEntityUnderline -- ^ See <https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1text_entity_type_underline.html>+ | MessageEntityStrikethrough -- ^ See <https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1text_entity_type_strikethrough.html> | MessageEntityCode | MessageEntityPre | MessageEntityTextLink | MessageEntityTextMention+ | MessageEntityCashtag -- ^ See <https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1text_entity_type_cashtag.html>.+ | MessageEntityPhoneNumber -- ^ See <https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1text_entity_type_phone_number.html>. deriving (Eq, Show, Generic) instance ToJSON MessageEntityType where toJSON = gtoJSON
src/Telegram/Bot/Simple/BotApp.hs view
@@ -25,8 +25,7 @@ -- directly to the bot. startBotAsync :: BotApp model action -> ClientEnv -> IO (action -> IO ()) startBotAsync bot env = do- botEnv <- defaultBotEnv bot env- jobThreadIds <- scheduleBotJobs botEnv (botJobs bot)+ botEnv <- startBotEnv bot env fork_ $ startBotPolling bot botEnv return (issueAction botEnv Nothing) where@@ -37,11 +36,9 @@ startBotAsync_ bot env = void (startBotAsync bot env) -- | Start bot with update polling in the main thread.-startBot :: BotApp model action -> ClientEnv -> IO (Either ServantError ())+startBot :: BotApp model action -> ClientEnv -> IO (Either ClientError ()) startBot bot env = do- botEnv <- defaultBotEnv bot env- jobThreadIds <- scheduleBotJobs botEnv (botJobs bot)- _actionsThreadId <- processActionsIndefinitely bot botEnv+ botEnv <- startBotEnv bot env runClientM (startBotPolling bot botEnv) env -- | Like 'startBot', but ignores result.@@ -57,3 +54,10 @@ -- @ getEnvToken :: String -> IO Telegram.Token getEnvToken varName = fromString <$> getEnv varName++startBotEnv :: BotApp model action -> ClientEnv -> IO (BotEnv model action)+startBotEnv bot env = do+ botEnv <- defaultBotEnv bot env+ _jobThreadIds <- scheduleBotJobs botEnv (botJobs bot)+ _actionsThreadId <- processActionsIndefinitely bot botEnv+ return botEnv
src/Telegram/Bot/Simple/UpdateParser.hs view
@@ -26,7 +26,6 @@ instance Monad UpdateParser where return = pure UpdateParser x >>= f = UpdateParser (\u -> x u >>= flip runUpdateParser u . f)- fail _ = empty mkParser :: (Update -> Maybe a) -> UpdateParser a mkParser = UpdateParser
telegram-bot-simple.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 4280984aa13d278dcdd078adc9dbae36453194881344c26a0dc1fb8e4f46ee35+-- hash: 815631caa1274f24031eaa1ec3c4ea08c75d46b660a0b266eeea28b0f123c325 name: telegram-bot-simple-version: 0.2.0+version: 0.3.0 synopsis: Easy to use library for building Telegram bots. description: Please see the README on Github at <https://github.com/fizruk/telegram-bot-simple#readme> category: Web@@ -17,10 +19,9 @@ license: BSD3 license-file: LICENSE build-type: Simple-cabal-version: >= 1.10 extra-source-files:- CHANGELOG.md README.md+ CHANGELOG.md source-repository head type: git@@ -29,6 +30,7 @@ library exposed-modules: Telegram.Bot.API+ Telegram.Bot.API.Chat Telegram.Bot.API.Games Telegram.Bot.API.GettingUpdates Telegram.Bot.API.InlineMode