Skip to content

Commit

Permalink
Merge pull request #141 from Seteh/feature/my-descriptions
Browse files Browse the repository at this point in the history
[gs]etMy(Short)?Description support.
  • Loading branch information
swamp-agr committed Mar 18, 2023
2 parents 498ae76 + e81a935 commit 41d8efd
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 0 deletions.
8 changes: 8 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Methods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module Telegram.Bot.API.Methods
, module Telegram.Bot.API.Methods.GetMe
, module Telegram.Bot.API.Methods.GetMyCommands
, module Telegram.Bot.API.Methods.GetMyDefaultAdministratorRights
, module Telegram.Bot.API.Methods.GetMyDescription
, module Telegram.Bot.API.Methods.GetMyShortDescription
, module Telegram.Bot.API.Methods.GetUserProfilePhotos
, module Telegram.Bot.API.Methods.LeaveChat
, module Telegram.Bot.API.Methods.PinChatMessage
Expand Down Expand Up @@ -67,6 +69,8 @@ module Telegram.Bot.API.Methods
, module Telegram.Bot.API.Methods.SetChatTitle
, module Telegram.Bot.API.Methods.SetMyCommands
, module Telegram.Bot.API.Methods.SetMyDefaultAdministratorRights
, module Telegram.Bot.API.Methods.SetMyDescription
, module Telegram.Bot.API.Methods.SetMyShortDescription
, module Telegram.Bot.API.Methods.StopMessageLiveLocation
, module Telegram.Bot.API.Methods.UnbanChatMember
, module Telegram.Bot.API.Methods.UnbanChatSenderChat
Expand Down Expand Up @@ -101,6 +105,8 @@ import Telegram.Bot.API.Methods.GetFile
import Telegram.Bot.API.Methods.GetMe
import Telegram.Bot.API.Methods.GetMyCommands
import Telegram.Bot.API.Methods.GetMyDefaultAdministratorRights
import Telegram.Bot.API.Methods.GetMyDescription
import Telegram.Bot.API.Methods.GetMyShortDescription
import Telegram.Bot.API.Methods.GetUserProfilePhotos
import Telegram.Bot.API.Methods.LeaveChat
import Telegram.Bot.API.Methods.PinChatMessage
Expand Down Expand Up @@ -131,6 +137,8 @@ import Telegram.Bot.API.Methods.SetChatStickerSet
import Telegram.Bot.API.Methods.SetChatTitle
import Telegram.Bot.API.Methods.SetMyCommands
import Telegram.Bot.API.Methods.SetMyDefaultAdministratorRights
import Telegram.Bot.API.Methods.SetMyDescription
import Telegram.Bot.API.Methods.SetMyShortDescription
import Telegram.Bot.API.Methods.StopMessageLiveLocation
import Telegram.Bot.API.Methods.UnbanChatMember
import Telegram.Bot.API.Methods.UnbanChatSenderChat
Expand Down
38 changes: 38 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Methods/GetMyDescription.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Telegram.Bot.API.Methods.GetMyDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Proxy
import GHC.Generics (Generic)
import Data.Text (Text)
import Servant.API
import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Types
import Telegram.Bot.API.Internal.TH

-- ** 'GetMyDescription'

newtype GetMyDescriptionRequest = GetMyDescriptionRequest
{ getMyDescriptionLanguageCode :: Maybe Text -- ^ A two-letter ISO 639-1 language code or an empty string.
}
deriving Generic

instance ToJSON GetMyDescriptionRequest where toJSON = gtoJSON
instance FromJSON GetMyDescriptionRequest where parseJSON = gparseJSON

type GetMyDescription = "getMyDescription"
:> ReqBody '[JSON] GetMyDescriptionRequest
:> Post '[JSON] (Response BotDescription)

-- | Use this method to get the current bot description for the given user language.
-- Returns 'BotDescription' on success.
getMyDescription :: GetMyDescriptionRequest -> ClientM (Response BotDescription)
getMyDescription = client (Proxy @GetMyDescription)

makeDefault ''GetMyDescriptionRequest
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Telegram.Bot.API.Methods.GetMyShortDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Proxy
import GHC.Generics (Generic)
import Data.Text (Text)
import Servant.API
import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Types
import Telegram.Bot.API.Internal.TH

-- ** 'GetMyShortDescription'

newtype GetMyShortDescriptionRequest = GetMyShortDescriptionRequest
{ getMyShortDescriptionLanguageCode :: Maybe Text -- ^ A two-letter ISO 639-1 language code or an empty string.
}
deriving Generic

instance ToJSON GetMyShortDescriptionRequest where toJSON = gtoJSON
instance FromJSON GetMyShortDescriptionRequest where parseJSON = gparseJSON

type GetMyShortDescription = "getMyShortDescription"
:> ReqBody '[JSON] GetMyShortDescriptionRequest
:> Post '[JSON] (Response BotShortDescription)

-- | Use this method to get the current bot short description for the given user language.
-- Returns 'BotShortDescription' on success.
getMyShortDescription :: GetMyShortDescriptionRequest -> ClientM (Response BotShortDescription)
getMyShortDescription = client (Proxy @GetMyShortDescription)

makeDefault ''GetMyShortDescriptionRequest
39 changes: 39 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Methods/SetMyDescription.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Telegram.Bot.API.Methods.SetMyDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Proxy
import GHC.Generics (Generic)
import Data.Text (Text)
import Servant.API
import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Internal.TH

-- ** 'setMyDescription'

data SetMyDescriptionRequest = SetMyDescriptionRequest
{ setMyDescriptionDescription :: Maybe Text -- ^ New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
, setMyDescriptionLanguageCode :: Maybe Text -- ^ A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.
}
deriving Generic

instance ToJSON SetMyDescriptionRequest where toJSON = gtoJSON
instance FromJSON SetMyDescriptionRequest where parseJSON = gparseJSON

type SetMyDescription = "setMyDescription"
:> ReqBody '[JSON] SetMyDescriptionRequest
:> Post '[JSON] (Response Bool)

-- | Use this method to change the bot's description,
-- which is shown in the chat with the bot if the chat is empty.
-- Returns 'True' on success.
setMyDescription :: SetMyDescriptionRequest -> ClientM (Response Bool)
setMyDescription = client (Proxy @SetMyDescription)

makeDefault ''SetMyDescriptionRequest
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Telegram.Bot.API.Methods.SetMyShortDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Proxy
import GHC.Generics (Generic)
import Data.Text (Text)
import Servant.API
import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Internal.TH

-- ** 'setMyShortDescription'

data SetMyShortDescriptionRequest = SetMyShortDescriptionRequest
{ setMyShortDescriptionDescription :: Maybe Text -- ^ New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
, setMyShortDescriptionLanguageCode :: Maybe Text -- ^ A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.
}
deriving Generic

instance ToJSON SetMyShortDescriptionRequest where toJSON = gtoJSON
instance FromJSON SetMyShortDescriptionRequest where parseJSON = gparseJSON

type SetMyShortDescription = "setMyShortDescription"
:> ReqBody '[JSON] SetMyShortDescriptionRequest
:> Post '[JSON] (Response Bool)

-- | Use this method to change the bot's short description,
-- which is shown on the bot's profile page and
-- is sent together with the link when users share the bot.
-- Returns 'True' on success.
setMyShortDescription :: SetMyShortDescriptionRequest -> ClientM (Response Bool)
setMyShortDescription = client (Proxy @SetMyShortDescription)

makeDefault ''SetMyShortDescriptionRequest
4 changes: 4 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Telegram.Bot.API.Types
, module Telegram.Bot.API.Types.Audio
, module Telegram.Bot.API.Types.BotCommand
, module Telegram.Bot.API.Types.BotCommandScope
, module Telegram.Bot.API.Types.BotDescription
, module Telegram.Bot.API.Types.BotShortDescription
, module Telegram.Bot.API.Types.CallbackGame
, module Telegram.Bot.API.Types.CallbackQuery
, module Telegram.Bot.API.Types.Chat
Expand Down Expand Up @@ -102,6 +104,8 @@ import Telegram.Bot.API.Types.Animation
import Telegram.Bot.API.Types.Audio
import Telegram.Bot.API.Types.BotCommand
import Telegram.Bot.API.Types.BotCommandScope
import Telegram.Bot.API.Types.BotDescription
import Telegram.Bot.API.Types.BotShortDescription
import Telegram.Bot.API.Types.CallbackGame
import Telegram.Bot.API.Types.CallbackQuery
import Telegram.Bot.API.Types.Chat
Expand Down
18 changes: 18 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types/BotDescription.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE DeriveGeneric #-}
module Telegram.Bot.API.Types.BotDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Text (Text)
import GHC.Generics (Generic)
import Telegram.Bot.API.Internal.Utils

-- ** 'BotDescription'

-- | This object represents the bot's description.
data BotDescription = BotDescription
{ botDescriptionDescription :: Text -- ^ The bot's description.
}
deriving (Generic, Show)

instance ToJSON BotDescription where toJSON = gtoJSON
instance FromJSON BotDescription where parseJSON = gparseJSON
18 changes: 18 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types/BotShortDescription.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE DeriveGeneric #-}
module Telegram.Bot.API.Types.BotShortDescription where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Text (Text)
import GHC.Generics (Generic)
import Telegram.Bot.API.Internal.Utils

-- ** 'BotShortDescription'

-- | This object represents the bot's short description.
data BotShortDescription = BotShortDescription
{ botShortDescriptionShortDescription :: Text -- ^ The bot's short description.
}
deriving (Generic, Show)

instance ToJSON BotShortDescription where toJSON = gtoJSON
instance FromJSON BotShortDescription where parseJSON = gparseJSON
6 changes: 6 additions & 0 deletions telegram-bot-api/telegram-bot-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ library
Telegram.Bot.API.Methods.GetMe
Telegram.Bot.API.Methods.GetMyCommands
Telegram.Bot.API.Methods.GetMyDefaultAdministratorRights
Telegram.Bot.API.Methods.GetMyDescription
Telegram.Bot.API.Methods.GetMyShortDescription
Telegram.Bot.API.Methods.GetUserProfilePhotos
Telegram.Bot.API.Methods.LeaveChat
Telegram.Bot.API.Methods.PinChatMessage
Expand Down Expand Up @@ -92,6 +94,8 @@ library
Telegram.Bot.API.Methods.SetChatTitle
Telegram.Bot.API.Methods.SetMyCommands
Telegram.Bot.API.Methods.SetMyDefaultAdministratorRights
Telegram.Bot.API.Methods.SetMyDescription
Telegram.Bot.API.Methods.SetMyShortDescription
Telegram.Bot.API.Methods.StopMessageLiveLocation
Telegram.Bot.API.Methods.UnbanChatMember
Telegram.Bot.API.Methods.UnbanChatSenderChat
Expand All @@ -107,6 +111,8 @@ library
Telegram.Bot.API.Types.Audio
Telegram.Bot.API.Types.BotCommand
Telegram.Bot.API.Types.BotCommandScope
Telegram.Bot.API.Types.BotDescription
Telegram.Bot.API.Types.BotShortDescription
Telegram.Bot.API.Types.CallbackGame
Telegram.Bot.API.Types.CallbackQuery
Telegram.Bot.API.Types.Chat
Expand Down
16 changes: 16 additions & 0 deletions telegram-bot-simple/src/Telegram/Bot/Simple/RunTG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ instance RunTG AnswerCallbackQueryRequest (Response Bool) where
instance RunTG SetMyDefaultAdministratorRightsRequest (Response Bool) where
runTG = runTG . setMyDefaultAdministratorRights

-- | Wrapper around 'SetMyDescriptionRequest' request type for 'setMyDescription' method.
instance RunTG SetMyDescriptionRequest (Response Bool) where
runTG = runTG . setMyDescription

-- | Wrapper around 'SetMyShortDescriptionRequest' request type for 'setMyShortDescription' method.
instance RunTG SetMyShortDescriptionRequest (Response Bool) where
runTG = runTG . setMyShortDescription

-- | Wrapper around 'CreateChatInviteLinkRequest' request type for 'createChatInviteLink' method.
instance RunTG CreateChatInviteLinkRequest (Response ChatInviteLink) where
runTG = runTG . createChatInviteLink
Expand All @@ -251,6 +259,14 @@ instance RunTG PromoteChatMemberRequest (Response Bool) where
instance RunTG GetMyDefaultAdministratorRightsRequest (Response ChatAdministratorRights) where
runTG = runTG . getMyDefaultAdministratorRights

-- | Wrapper around 'GetMyDescriptionRequest' request type for 'getMyDescription' method.
instance RunTG GetMyDescriptionRequest (Response BotDescription) where
runTG = runTG . getMyDescription

-- | Wrapper around 'GetMyShortDescriptionRequest' request type for 'getMyShortDescription' method.
instance RunTG GetMyShortDescriptionRequest (Response BotShortDescription) where
runTG = runTG . getMyShortDescription

-- | Wrapper around 'BanChatMemberRequest' request type for 'banChatMember' method.
instance RunTG BanChatMemberRequest (Response Bool) where
runTG = runTG . banChatMember
Expand Down

0 comments on commit 41d8efd

Please sign in to comment.