Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Web/Telegram/API/Bot/API/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Web.Telegram.API.Bot.API.Messages
, uploadDocumentM
, sendDocument
, sendDocumentM
, deleteMessage
, deleteMessageM
, uploadSticker
, uploadStickerM
, sendSticker
Expand Down Expand Up @@ -90,6 +92,9 @@ type TelegramBotMessagesAPI =
:<|> TelegramToken :> "sendDocument"
:> ReqBody '[JSON] (SendDocumentRequest Text)
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "deleteMessage"
:> ReqBody '[JSON] DeleteMessageRequest
:> Post '[JSON] (Response Bool)
:<|> TelegramToken :> "sendSticker"
:> MultipartFormDataReqBody (SendStickerRequest FileUpload)
:> Post '[JSON] MessageResponse
Expand Down Expand Up @@ -145,6 +150,7 @@ uploadAudio_ :: Token -> SendAudioRequest FileUpload -> ClientM Me
sendAudio_ :: Token -> SendAudioRequest Text -> ClientM MessageResponse
uploadDocument_ :: Token -> SendDocumentRequest FileUpload -> ClientM MessageResponse
sendDocument_ :: Token -> SendDocumentRequest Text -> ClientM MessageResponse
deleteMessage_ :: Token -> DeleteMessageRequest -> ClientM (Response Bool)
uploadSticker_ :: Token -> SendStickerRequest FileUpload -> ClientM MessageResponse
sendSticker_ :: Token -> SendStickerRequest Text -> ClientM MessageResponse
uploadVideo_ :: Token -> SendVideoRequest FileUpload -> ClientM MessageResponse
Expand All @@ -167,6 +173,7 @@ sendMessage_
:<|> sendAudio_
:<|> uploadDocument_
:<|> sendDocument_
:<|> deleteMessage_
:<|> uploadSticker_
:<|> sendSticker_
:<|> uploadVideo_
Expand Down Expand Up @@ -251,6 +258,22 @@ sendDocument = runM sendDocumentM
sendDocumentM :: SendDocumentRequest Text -> TelegramClient MessageResponse
sendDocumentM = run_ sendDocument_

-- |Use this method to delete a message, including service messages, with the following limitations:
-- - A message can only be deleted if it was sent less than 48 hours ago.
-- - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
-- - Bots can delete outgoing messages in private chats, groups, and supergroups.
-- - Bots can delete incoming messages in private chats.
-- - Bots granted can_post_messages permissions can delete outgoing messages in channels.
-- - If the bot is an administrator of a group, it can delete any message there.
-- - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
-- Returns True on success.
deleteMessage :: Token -> DeleteMessageRequest -> Manager -> IO (Either ClientError (Response Bool))
deleteMessage = runM deleteMessageM

-- | See 'deleteMessage'
deleteMessageM :: DeleteMessageRequest -> TelegramClient (Response Bool)
deleteMessageM = run_ deleteMessage_

-- | Use this method to upload and send .webp stickers. On success, the sent 'Message' is returned.
uploadSticker :: Token -> SendStickerRequest FileUpload -> Manager -> IO (Either ClientError MessageResponse)
uploadSticker = runM uploadStickerM
Expand Down
19 changes: 19 additions & 0 deletions src/Web/Telegram/API/Bot/Requests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Web.Telegram.API.Bot.Requests
, SendPhotoRequest (..)
, SendAudioRequest (..)
, SendDocumentRequest (..)
, DeleteMessageRequest (..)
, SendStickerRequest (..)
, SendVideoRequest (..)
, SendVoiceRequest (..)
Expand Down Expand Up @@ -56,6 +57,7 @@ module Web.Telegram.API.Bot.Requests
, uploadAudioRequest
, sendDocumentRequest
, uploadDocumentRequest
, deleteMessageRequest
, sendStickerRequest
, uploadStickerRequest
, sendVideoRequest
Expand Down Expand Up @@ -396,6 +398,23 @@ sendDocumentRequest chatId document = SendDocumentRequest chatId document Nothin
uploadDocumentRequest :: ChatId -> FileUpload -> SendDocumentRequest FileUpload
uploadDocumentRequest chatId document = SendDocumentRequest chatId document Nothing Nothing Nothing Nothing

-- | This object represents request for 'deleteMessage'
data DeleteMessageRequest = DeleteMessageRequest
{
_delete_chat_id :: ChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format @@channelusername@)
, _delete_message_id :: Int -- ^ Identifier of the message to delete
} deriving (Show, Generic)

instance ToJSON DeleteMessageRequest where
toJSON = toJsonDrop 2

instance FromJSON DeleteMessageRequest where
parseJSON = parseJsonDrop 2

deleteMessageRequest :: ChatId -> Int -> DeleteMessageRequest
deleteMessageRequest chatId messageId = DeleteMessageRequest chatId messageId


-- | This object represents request for 'sendVideo'
data SendVideoRequest payload = SendVideoRequest
{
Expand Down
2 changes: 1 addition & 1 deletion telegram-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library
, http-api-data
, http-client
, servant
, servant-client == 0.16
, servant-client == 0.16.*
, servant-client-core
, mtl
, text
Expand Down