Skip to content

Commit

Permalink
Merge pull request #183 from fizruk/bot-api-7.3
Browse files Browse the repository at this point in the history
Bot API 7.3
  • Loading branch information
swamp-agr authored May 25, 2024
2 parents e966fb7 + 032540d commit d404f7e
Show file tree
Hide file tree
Showing 18 changed files with 379 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import Telegram.Bot.API.Internal.TH

-- | Request parameters for 'editMessageLiveLocation'.
data EditMessageLiveLocationRequest = EditMessageLiveLocationRequest
{ editMessageLiveLocationChatId :: Maybe SomeChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername)
, editMessageLiveLocationMessageId :: Maybe MessageId -- ^ Required if inline_message_id is not specified. Identifier of the message with live location to stop
, editMessageLiveLocationInlineMessageId :: Maybe Text -- ^ Required if chat_id and message_id are not specified. Identifier of the inline message
, editMessageLiveLocationLatitude :: Float -- ^ Latitude of new location
, editMessageLiveLocationLongitude :: Float -- ^ Longitude of new location
, editMessageLiveLocationHorizontalAccuracy :: Maybe Float -- ^ The radius of uncertainty for the location, measured in meters; 0-1500
{ editMessageLiveLocationChatId :: Maybe SomeChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format \@channelusername).
, editMessageLiveLocationMessageId :: Maybe MessageId -- ^ Required if inline_message_id is not specified. Identifier of the message with live location to stop.
, editMessageLiveLocationInlineMessageId :: Maybe Text -- ^ Required if chat_id and message_id are not specified. Identifier of the inline message.
, editMessageLiveLocationLatitude :: Float -- ^ Latitude of new location.
, editMessageLiveLocationLongitude :: Float -- ^ Longitude of new location.
, editMessageLiveLocationLivePeriod :: Maybe Int -- ^ New period in seconds during which the location can be updated, starting from the message send date. If @0x7FFFFFFF@ is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current @live_period@ by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then @live_period@ remains unchanged.
, editMessageLiveLocationHorizontalAccuracy :: Maybe Float -- ^ The radius of uncertainty for the location, measured in meters; 0-1500.
, editMessageLiveLocationHeading :: Maybe Int -- ^ Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
, editMessageLiveLocationProximityAlertRadius :: Maybe Int -- ^ Maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
, editMessageLiveLocationReplyMarkup :: Maybe InlineKeyboardMarkup -- ^ Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
Expand Down
4 changes: 2 additions & 2 deletions telegram-bot-api/src/Telegram/Bot/API/Methods/GetChat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import Telegram.Bot.API.Types

type GetChat = "getChat"
:> RequiredQueryParam "chat_id" SomeChatId
:> Post '[JSON] (Response Chat)
:> Post '[JSON] (Response ChatFullInfo)

-- | Use this method to get up to date information
-- about the chat (current name of the user for
-- one-on-one conversations, current username of
-- a user, group or channel, etc.).
-- Returns a Chat object on success.
getChat :: SomeChatId -- ^ Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
-> ClientM (Response Chat)
-> ClientM (Response ChatFullInfo)
getChat = client (Proxy @GetChat)
26 changes: 14 additions & 12 deletions telegram-bot-api/src/Telegram/Bot/API/Methods/SendPoll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ data SendPollRequest = SendPollRequest
{ sendPollBusinessConnectionId :: Maybe BusinessConnectionId -- ^ Unique identifier of the business connection on behalf of which the message will be sent.
, sendPollChatId :: SomeChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername).
, sendPollMessageThreadId :: Maybe MessageThreadId -- ^ Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.
, sendPollQuestion :: Text -- ^ Poll question, 1-300 characters
, sendPollOptions :: [Text] -- ^ A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
, sendPollIsAnonymous :: Maybe Bool -- ^ True, if the poll needs to be anonymous, defaults to True
, sendPollType :: Maybe Text -- ^ Poll type, “quiz” or “regular”, defaults to “regular”
, sendPollAllowsMultipleAnswers :: Maybe Bool -- ^ True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
, sendPollCorrectOptionId :: Maybe Int -- ^ 0-based identifier of the correct answer option, required for polls in quiz mode
, sendPollExplanation :: Maybe Text -- ^ Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
, sendPollQuestion :: Text -- ^ Poll question, 1-300 characters.
, sendPollQuestionParseMode :: Maybe ParseMode -- ^ Mode for parsing entities in the question. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. Currently, only custom emoji entities are allowed.
, sendPollQuestionEntities :: Maybe [MessageEntity] -- ^ A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of @question_parse_mode@.
, sendPollOptions :: [InputPollOption] -- ^ A JSON-serialized list of answer options, 2-10 strings 1-100 characters each.
, sendPollIsAnonymous :: Maybe Bool -- ^ True, if the poll needs to be anonymous, defaults to 'True'.
, sendPollType :: Maybe Text -- ^ Poll type, “quiz” or “regular”, defaults to “regular”.
, sendPollAllowsMultipleAnswers :: Maybe Bool -- ^ True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to 'False'.
, sendPollCorrectOptionId :: Maybe Int -- ^ 0-based identifier of the correct answer option, required for polls in quiz mode.
, sendPollExplanation :: Maybe Text -- ^ Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing.
, sendPollExplanationParseMode :: Maybe ParseMode -- ^ Send 'MarkdownV2', 'HTML' or 'Markdown' (legacy), if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
, sendPollExplanationEntities :: Maybe [MessageEntity] -- ^ A JSON-serialized list of special entities that appear in the poll explanation, which can be specified instead of parse_mode
, sendPollOpenPeriod :: Maybe Int -- ^ Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date.
, sendPollCloseDate :: Maybe Int -- ^ Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
, sendPollExplanationEntities :: Maybe [MessageEntity] -- ^ A JSON-serialized list of special entities that appear in the poll explanation, which can be specified instead of @parse_mode@.
, sendPollOpenPeriod :: Maybe Int -- ^ Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with @close_date@.
, sendPollCloseDate :: Maybe Int -- ^ Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with @open_period@.
, sendPollIsClosed :: Maybe Bool -- ^ Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.
, sendPollDisableNotification :: Maybe Bool -- ^ Sends the message silently. Users will receive a notification with no sound.
, sendPollProtectContent :: Maybe Bool -- ^ Protects the contents of the sent message from forwarding and saving
, sendPollReplyToMessageId :: Maybe MessageId -- ^ If the message is a reply, ID of the original message
, sendPollProtectContent :: Maybe Bool -- ^ Protects the contents of the sent message from forwarding and saving.
, sendPollReplyToMessageId :: Maybe MessageId -- ^ If the message is a reply, ID of the original message.
, sendPollReplyParameters :: Maybe ReplyParameters -- ^ Description of the message to reply to.
, sendPollReplyMarkup :: Maybe InlineKeyboardMarkup -- ^ Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
}
Expand Down
10 changes: 8 additions & 2 deletions telegram-bot-api/src/Telegram/Bot/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ module Telegram.Bot.API.Types
, module Telegram.Bot.API.Types.CallbackGame
, module Telegram.Bot.API.Types.CallbackQuery
, module Telegram.Bot.API.Types.Chat
, module Telegram.Bot.API.Types.ChatAdministratorRights
, module Telegram.Bot.API.Types.ChatBoost
, module Telegram.Bot.API.Types.ChatBoostAdded
, module Telegram.Bot.API.Types.ChatBoostRemoved
, module Telegram.Bot.API.Types.ChatBoostSource
, module Telegram.Bot.API.Types.ChatBoostUpdated
, module Telegram.Bot.API.Types.ChatAdministratorRights
, module Telegram.Bot.API.Types.ChatFullInfo
, module Telegram.Bot.API.Types.ChatInviteLink
, module Telegram.Bot.API.Types.ChatJoinRequest
, module Telegram.Bot.API.Types.ChatLocation
Expand All @@ -44,6 +45,7 @@ module Telegram.Bot.API.Types
, module Telegram.Bot.API.Types.ChatPermissions
, module Telegram.Bot.API.Types.ChatPhoto
, module Telegram.Bot.API.Types.ChatShared
, module Telegram.Bot.API.Types.ChatType
, module Telegram.Bot.API.Types.Common
, module Telegram.Bot.API.Types.Contact
, module Telegram.Bot.API.Types.CopyMessageId
Expand All @@ -70,6 +72,7 @@ module Telegram.Bot.API.Types
, module Telegram.Bot.API.Types.InlineKeyboardButton
, module Telegram.Bot.API.Types.InlineKeyboardMarkup
, module Telegram.Bot.API.Types.InputMedia
, module Telegram.Bot.API.Types.InputPollOption
, module Telegram.Bot.API.Types.Invoice
, module Telegram.Bot.API.Types.KeyboardButton
, module Telegram.Bot.API.Types.KeyboardButtonRequestChat
Expand Down Expand Up @@ -146,12 +149,13 @@ import Telegram.Bot.API.Types.BusinessOpeningHoursInterval
import Telegram.Bot.API.Types.CallbackGame
import Telegram.Bot.API.Types.CallbackQuery
import Telegram.Bot.API.Types.Chat
import Telegram.Bot.API.Types.ChatAdministratorRights
import Telegram.Bot.API.Types.ChatBoost
import Telegram.Bot.API.Types.ChatBoostAdded
import Telegram.Bot.API.Types.ChatBoostRemoved
import Telegram.Bot.API.Types.ChatBoostSource
import Telegram.Bot.API.Types.ChatBoostUpdated
import Telegram.Bot.API.Types.ChatAdministratorRights
import Telegram.Bot.API.Types.ChatFullInfo
import Telegram.Bot.API.Types.ChatInviteLink
import Telegram.Bot.API.Types.ChatJoinRequest
import Telegram.Bot.API.Types.ChatLocation
Expand All @@ -160,6 +164,7 @@ import Telegram.Bot.API.Types.ChatMemberUpdated
import Telegram.Bot.API.Types.ChatPermissions
import Telegram.Bot.API.Types.ChatPhoto
import Telegram.Bot.API.Types.ChatShared
import Telegram.Bot.API.Types.ChatType
import Telegram.Bot.API.Types.Common
import Telegram.Bot.API.Types.Contact
import Telegram.Bot.API.Types.CopyMessageId
Expand All @@ -186,6 +191,7 @@ import Telegram.Bot.API.Types.GeneralForumTopicUnhidden
import Telegram.Bot.API.Types.InlineKeyboardButton
import Telegram.Bot.API.Types.InlineKeyboardMarkup
import Telegram.Bot.API.Types.InputMedia
import Telegram.Bot.API.Types.InputPollOption
import Telegram.Bot.API.Types.Invoice
import Telegram.Bot.API.Types.KeyboardButton
import Telegram.Bot.API.Types.KeyboardButtonRequestChat
Expand Down
71 changes: 71 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types/BackgroundFill.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Telegram.Bot.API.Types.BackgroundFill where

import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.=), (.:), withObject)
import Data.Aeson.Types (Parser)
import Data.Text
import GHC.Generics (Generic)

import qualified Data.Text as Text

import Telegram.Bot.API.Types.Common
import Telegram.Bot.API.Internal.Utils

-- ** 'BackgroundFill'

-- | This object describes the way a background is filled based on the selected colors. Currently, it can be one of
--
-- * BackgroundFillSolid
-- * BackgroundFillGradient
-- * BackgroundFillFreeformGradient
--
data BackgroundFill
-- | The background is filled using the selected color.
= BackgroundFillSolid
{ backgroundFillSolidType :: Text -- ^ Type of the background fill, always “solid”.
, backgroundFillSolidColor :: Int -- ^ The color of the background fill in the RGB24 format.
}
-- | The background is a gradient fill.
| BackgroundFillGradient
{ backgroundFillGradientType :: Text -- ^ Type of the background fill, always “gradient”.
, backgroundFillGradientTopColor :: Int -- ^ Top color of the gradient in the RGB24 format.
, backgroundFillGradientBottomColor :: Int -- ^ Bottom color of the gradient in the RGB24 format.
, backgroundFillGradientRotationAngle :: Int -- ^ Clockwise rotation angle of the background fill in degrees; @0-359@.
}
-- | The background is a freeform gradient that rotates after every message in the chat.
| BackgroundFillFreeformGradient
{ backgroundFillFreeformGradientType :: Text -- ^ Type of the background fill, always “freeform_gradient”.
, backgroundFillFreeformGradientColors :: [Int] -- ^ A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format.
}
deriving (Generic, Show)

instance ToJSON BackgroundFill where
toJSON = \case
BackgroundFillSolid _t c -> addJsonFields
(Object mempty)
(addType "solid" ["color" .= c])
BackgroundFillGradient _t tc bc ra -> addJsonFields
(Object mempty)
(addType "gradient" ["top_color" .= tc, "bottom_color" .= bc, "rotation_angle" .= ra])
BackgroundFillFreeformGradient _t cs -> addJsonFields
(Object mempty)
(addType "freeform_gradient" ["colors" .= cs])

instance FromJSON BackgroundFill where
parseJSON = withObject "BackgroundFill" \o ->
(o .: "type" :: Parser Text) >>= \case
"solid" -> BackgroundFillSolid
<$> o .: "type"
<*> o .: "color"
"gradient" ->BackgroundFillGradient
<$> o .: "type"
<*> o .: "top_color"
<*> o .: "bottom_color"
<*> o .: "rotation_angle"
"freeform_gradient" -> BackgroundFillFreeformGradient
<$> o .: "type"
<*> o .: "colors"
t -> fail $ Text.unpack ("Unknown type: " <> t)
97 changes: 97 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types/BackgroundType.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Telegram.Bot.API.Types.BackgroundType where

import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.=), (.:), withObject)
import Data.Aeson.Types (Parser)
import Data.Text (Text)
import GHC.Generics (Generic)

import qualified Data.Text as Text

import Telegram.Bot.API.Types.BackgroundFill
import Telegram.Bot.API.Types.Common
import Telegram.Bot.API.Types.Document
import Telegram.Bot.API.Internal.Utils

-- ** 'BackgroundType'

-- | This object describes the type of a background. Currently, it can be one of
--
-- * BackgroundTypeFill
-- * BackgroundTypeWallpaper
-- * BackgroundTypePattern
-- * BackgroundTypeChatTheme
--
data BackgroundType
-- | The background is automatically filled based on the selected colors.
= BackgroundTypeFill
{ backgroundTypeFillType :: Text -- ^ Type of the background, always “fill”.
, backgroundTypeFillFill :: BackgroundFill -- ^ The background fill.
, backgroundTypeFillDarkThemeDimming :: Int -- ^ Dimming of the background in dark themes, as a percentage; @0-100@.
}
-- | The background is a wallpaper in the JPEG format.
| BackgroundTypeWallpaper
{ backgroundTypeWallpaperType :: Text -- ^ Type of the background, always “wallpaper”.
, backgroundTypeWallpaperDocument :: Document -- ^ Document with the wallpaper.
, backgroundTypeWallpaperDarkThemeDimming :: Int -- ^ Dimming of the background in dark themes, as a percentage; @0-100@.
, backgroundTypeWallpaperIsBlurred :: Maybe Bool -- ^ 'True', if the wallpaper is downscaled to fit in a @450x450@ square and then box-blurred with radius 12.
, backgroundTypeWallpaperIsMoving :: Maybe Bool -- ^ 'True', if the background moves slightly when the device is tilted.
}
-- | The background is a PNG or TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user.
| BackgroundTypePattern
{ backgroundTypePatternType :: Text -- ^ Type of the background, always “pattern”.
, backgroundTypePatternDocument :: Document -- ^ Document with the pattern.
, backgroundTypePatternFill :: BackgroundFill -- ^ The background fill that is combined with the pattern.
, backgroundTypePatternIntensity :: Int -- ^ Intensity of the pattern when it is shown above the filled background; @0-100@.
, backgroundTypePatternIsInverted :: Maybe Bool -- ^ 'True', if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only.
, backgroundTypePatternIsMoving :: Maybe Bool -- ^ 'True', if the background moves slightly when the device is tilted.
}
-- | The background is taken directly from a built-in chat theme.
| BackgroundTypeChatTheme
{ backgroundTypeChatThemeType :: Text -- ^ Type of the background, always “chat_theme”.
, backgroundTypeChatThemeThemeName :: Text -- ^ Name of the chat theme, which is usually an emoji.
}
deriving (Generic, Show)

instance ToJSON BackgroundType where
toJSON = \case
BackgroundTypeFill _t f dtd -> addJsonFields
(Object mempty)
(addType "fill" ["fill" .= f, "dark_theme_dimming" .= dtd])
BackgroundTypeWallpaper _t d dtd ib im -> addJsonFields
(Object mempty)
(addType "wallpaper" ["document" .= d, "dark_theme_dimming" .= dtd, "is_blurred" .= ib, "is_moving" .= im])
BackgroundTypePattern _t d f i ii im -> addJsonFields
(Object mempty)
(addType "pattern" ["document" .= d, "fill" .= f, "intensity" .= i, "is_inverted" .= ii, "is_moving" .= im])
BackgroundTypeChatTheme _t tn -> addJsonFields
(Object mempty)
(addType "chat_theme" ["theme_name" .= tn])

instance FromJSON BackgroundType where
parseJSON = withObject "BackgroundType" \o ->
(o .: "type" :: Parser Text) >>= \case
"fill" -> BackgroundTypeFill
<$> o .: "type"
<*> o .: "fill"
<*> o .: "dark_theme_dimming"
"wallpaper" -> BackgroundTypeWallpaper
<$> o .: "type"
<*> o .: "document"
<*> o .: "dark_theme_dimming"
<*> o .: "is_blurred"
<*> o .: "is_moving"
"pattern" -> BackgroundTypePattern
<$> o .: "type"
<*> o .: "document"
<*> o .: "fill"
<*> o .: "intensity"
<*> o .: "is_inverted"
<*> o .: "is_moving"
"chat_theme" -> BackgroundTypeChatTheme
<$> o .: "type"
<*> o .: "theme_name"
t -> fail $ Text.unpack ("Unknown type: " <> t)
Loading

0 comments on commit d404f7e

Please sign in to comment.