Skip to content

Commit

Permalink
Merge pull request #191 from fizruk/fix-updates-with-inlines
Browse files Browse the repository at this point in the history
Fix `inline_message_id` field
  • Loading branch information
swamp-agr authored Oct 20, 2024
2 parents 8887062 + cea4800 commit 135287d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions telegram-bot-api/src/Telegram/Bot/API/Games.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Telegram.Bot.API.Internal.Utils (deriveJSON')
import Telegram.Bot.API.MakingRequests (Response)
import Telegram.Bot.API.Types
( BusinessConnectionId, ChatId, GameHighScore, InlineKeyboardMarkup
, Message, MessageId, MessageThreadId
, InlineMessageId, Message, MessageId, MessageThreadId
, ReplyParameters, UserId
)
import Telegram.Bot.API.Internal.TH
Expand Down Expand Up @@ -49,7 +49,7 @@ data SetGameScoreRequest = SetGameScoreRequest
, setGameScoreDisableEditMessage :: Maybe Bool -- ^ Pass 'True', if the game message should not be automatically edited to include the current scoreboard.
, setGameScoreChatId :: Maybe ChatId -- ^ Required if @inline_message_id@ is not specified. Unique identifier for the target chat
, setGameScoreMessageId :: Maybe MessageId -- ^ Required if @inline_message_id@ is not specified. Identifier of the sent message.
, setGameScoreInlineMessageId :: Maybe MessageId -- ^ Required if @chat_id@ and @message_id@ are not specified. Identifier of the inline message.
, setGameScoreInlineMessageId :: Maybe InlineMessageId -- ^ Required if @chat_id@ and @message_id@ are not specified. Identifier of the inline message.
}
deriving (Generic, Show)

Expand All @@ -64,7 +64,7 @@ data GetGameHighScoresRequest = GetGameHighScoresRequest
{ getGameHighScoresUserId :: UserId -- ^ Target user id.
, getGameHighScoresChatId :: Maybe ChatId -- ^ Required if @inline_message_id@ is not specified. Unique identifier for the target chat.
, getGameHighScoresMessageId :: Maybe MessageId -- ^ Required if @inline_message_id@ is not specified. Identifier of the sent message.
, getGameHighScoresInlineMessageId :: Maybe MessageId -- ^ Required if @chat_id@ and @message_id@ are not specified. Identifier of the inline message.
, getGameHighScoresInlineMessageId :: Maybe InlineMessageId -- ^ Required if @chat_id@ and @message_id@ are not specified. Identifier of the inline message.
}
deriving (Generic, Show)

Expand Down
2 changes: 1 addition & 1 deletion telegram-bot-api/src/Telegram/Bot/API/InlineMode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ data ChosenInlineResult = ChosenInlineResult
{ chosenInlineResultResultId :: InlineQueryResultId -- ^ The unique identifier for the result that was chosen.
, chosenInlineResultFrom :: User -- ^ The user that chose the result.
, chosenInlineResultLocation :: Maybe Location -- ^ Sender location, only for bots that require user location.
, chosenInlineResultInlineMessageId :: Maybe MessageId -- ^ Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
, chosenInlineResultInlineMessageId :: Maybe InlineMessageId -- ^ Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
, chosenInlineResultQuery :: InlineQueryId -- ^ The query that was used to obtain the result.
} deriving (Generic, Show)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Telegram.Bot.API.Methods.EditMessageLiveLocation where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Proxy
import Data.Text
import GHC.Generics (Generic)
import Servant.API
import Servant.Client hiding (Response)
Expand All @@ -22,7 +21,7 @@ import Telegram.Bot.API.Internal.TH
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.
, editMessageLiveLocationInlineMessageId :: Maybe InlineMessageId -- ^ 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Telegram.Bot.API.Internal.TH
data StopMessageLiveLocationRequest = StopMessageLiveLocationRequest
{ stopMessageLiveLocationChatId :: Maybe SomeChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername)
, stopMessageLiveLocationMessageId :: Maybe MessageId -- ^ Required if inline_message_id is not specified. Identifier of the message with live location to stop
, stopMessageLiveLocationInlineMessageId :: Maybe Text -- ^ Required if chat_id and message_id are not specified. Identifier of the inline message
, stopMessageLiveLocationInlineMessageId :: Maybe InlineMessageId -- ^ Required if chat_id and message_id are not specified. Identifier of the inline message
, stopMessageLiveLocationReplyMarkup :: 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.
}
deriving Generic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data CallbackQuery = CallbackQuery
{ callbackQueryId :: CallbackQueryId -- ^ Unique identifier for this query
, callbackQueryFrom :: User -- ^ Sender
, callbackQueryMessage :: Maybe Message -- ^ Message sent by the bot with the callback button that originated the query. Use 'isInaccessible' to understand whether a message was deleted or is otherwise inaccessible to the bot.
, callbackQueryInlineMessageId :: Maybe MessageId -- ^ Identifier of the message sent via the bot in inline mode, that originated the query.
, callbackQueryInlineMessageId :: Maybe InlineMessageId -- ^ Identifier of the message sent via the bot in inline mode, that originated the query.
, callbackQueryChatInstance :: Text -- ^ Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
, callbackQueryData :: Maybe Text -- ^ Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
, callbackQueryGameShortName :: Maybe Text -- ^ Short name of a Game to be returned, serves as the unique identifier for the game
Expand Down
3 changes: 3 additions & 0 deletions telegram-bot-api/src/Telegram/Bot/API/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ newtype MessageThreadId = MessageThreadId Integer
instance ToHttpApiData MessageThreadId where
toUrlPiece a = pack . show @Integer $ coerce a

newtype InlineMessageId = InlineMessageId Text
deriving (Eq, Show, ToJSON, FromJSON, Hashable)

-- | The unique identifier of a media message group a message belongs to.
newtype MediaGroupId = MediaGroupId Text
deriving (Eq, Show, ToJSON, FromJSON)
Expand Down
8 changes: 4 additions & 4 deletions telegram-bot-api/src/Telegram/Bot/API/UpdatingMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ instance FromJSON EditMessageResponse where
data EditMessageTextRequest = EditMessageTextRequest
{ editMessageTextChatId :: Maybe SomeChatId -- ^ Required if 'editMessageTextInlineMessageId' is not specified. Unique identifier for the target chat or username of the target channel (in the format @\@channelusername@).
, editMessageTextMessageId :: Maybe MessageId -- ^ Required if 'editMessageTextInlineMessageId' is not specified. Identifier of the sent message.
, editMessageTextInlineMessageId :: Maybe MessageId -- ^ Required if 'editMessageTextChatId' and 'editMessageTextMessageId' are not specified. Identifier of the sent message.
, editMessageTextInlineMessageId :: Maybe InlineMessageId -- ^ Required if 'editMessageTextChatId' and 'editMessageTextMessageId' are not specified. Identifier of the sent message.
, editMessageTextText :: Text -- ^ Text of the message to be sent.
, editMessageTextParseMode :: 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.
, editMessageEntities :: Maybe [MessageEntity] -- ^ A JSON-serialized list of special entities that appear in message text, which can be specified instead of /parse_mode/.
Expand All @@ -46,7 +46,7 @@ data EditMessageTextRequest = EditMessageTextRequest
data EditMessageCaptionRequest = EditMessageCaptionRequest
{ editMessageCaptionChatId :: Maybe SomeChatId -- ^ Required if 'editMessageCaptionMessageId' is not specified. Unique identifier for the target chat or username of the target channel (in the format @\@channelusername@).
, editMessageCaptionMessageId :: Maybe MessageId -- ^ Required if 'editMessageCaptionInlineMessageId' is not specified. Identifier of the sent message.
, editMessageCaptionInlineMessageId :: Maybe MessageId -- ^ Required if 'editMessageCaptionChatId' and 'editMessageCaptionMessageId' are not specified. Identifier of the sent message.
, editMessageCaptionInlineMessageId :: Maybe InlineMessageId -- ^ Required if 'editMessageCaptionChatId' and 'editMessageCaptionMessageId' are not specified. Identifier of the sent message.
, editMessageCaptionCaption :: Maybe Text -- ^ New caption of the message, 0-1024 characters after entities parsing
, editMessageCaptionParseMode :: Maybe ParseMode -- ^ Mode for parsing entities in the message caption. See formatting options for more details.
, editMessageCaptionCaptionEntities :: Maybe [MessageEntity] -- ^ A JSON-serialized list of special entities that appear in the caption, which can be specified instead of @parse_mode@.
Expand All @@ -58,7 +58,7 @@ data EditMessageCaptionRequest = EditMessageCaptionRequest
data EditMessageMediaRequest = EditMessageMediaRequest
{ editMessageMediaChatId :: Maybe SomeChatId -- ^ Required if 'editMessageMediaMessageId' is not specified. Unique identifier for the target chat or username of the target channel (in the format @\@channelusername@).
, editMessageMediaMessageId :: Maybe MessageId -- ^ Required if 'editMessageMediaInlineMessageId' is not specified. Identifier of the sent message.
, editMessageMediaInlineMessageId :: Maybe MessageId -- ^ Required if 'editMessageMediaChatId' and 'editMessageMediaMessageId' are not specified. Identifier of the sent message.
, editMessageMediaInlineMessageId :: Maybe InlineMessageId -- ^ Required if 'editMessageMediaChatId' and 'editMessageMediaMessageId' are not specified. Identifier of the sent message.
, editMessageMediaMedia :: InputMedia -- ^ A JSON-serialized object for a new media content of the message
, editMessageMediaReplyMarkup :: Maybe SomeReplyMarkup -- ^ 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.
} deriving (Generic)
Expand All @@ -69,7 +69,7 @@ instance ToJSON EditMessageMediaRequest where toJSON = gtoJSON
data EditMessageReplyMarkupRequest = EditMessageReplyMarkupRequest
{ editMessageReplyMarkupChatId :: Maybe SomeChatId -- ^ Required if 'editMessageReplyMarkupMessageId' is not specified. Unique identifier for the target chat or username of the target channel (in the format @\@channelusername@).
, editMessageReplyMarkupMessageId :: Maybe MessageId -- ^ Required if 'editMessageReplyMarkupInlineMessageId' is not specified. Identifier of the sent message.
, editMessageReplyMarkupInlineMessageId :: Maybe MessageId -- ^ Required if 'editMessageReplyMarkupChatId' and 'editMessageReplyMarkupMessageId' are not specified. Identifier of the sent message.
, editMessageReplyMarkupInlineMessageId :: Maybe InlineMessageId -- ^ Required if 'editMessageReplyMarkupChatId' and 'editMessageReplyMarkupMessageId' are not specified. Identifier of the sent message.
, editMessageReplyMarkupReplyMarkup :: Maybe SomeReplyMarkup -- ^ 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.
} deriving (Generic)

Expand Down
4 changes: 2 additions & 2 deletions telegram-bot-api/src/Telegram/Bot/API/WebApps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Servant.Client hiding (Response)

import Telegram.Bot.API.Internal.Utils (deriveJSON')
import Telegram.Bot.API.MakingRequests (Response)
import Telegram.Bot.API.InlineMode (InlineQueryId)
import Telegram.Bot.API.Types.Common (InlineMessageId)
import Telegram.Bot.API.InlineMode.InlineQueryResult (InlineQueryResult)
import Telegram.Bot.API.Internal.TH (makeDefault)

Expand All @@ -33,7 +33,7 @@ data AnswerWebAppQueryRequest = AnswerWebAppQueryRequest

-- | Contains information about an inline message sent by a Web App on behalf of a user.
newtype SentWebAppMessage = SentWebAppMessage
{ sentWebAppMessageInlineMessageId :: Maybe InlineQueryId
{ sentWebAppMessageInlineMessageId :: Maybe InlineMessageId
}
deriving (Generic, Show)

Expand Down
2 changes: 1 addition & 1 deletion telegram-bot-simple/src/Telegram/Bot/Simple/Reply.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ instance IsString EditMessage where

data EditMessageId
= EditChatMessageId SomeChatId MessageId
| EditInlineMessageId MessageId
| EditInlineMessageId InlineMessageId

toEditMessage :: Text -> EditMessage
toEditMessage msg = EditMessage msg Nothing Nothing Nothing
Expand Down

0 comments on commit 135287d

Please sign in to comment.