module Web.Telegram.API.Bot.Requests
(
ChatId (..)
, SendMessageRequest (..)
, ForwardMessageRequest (..)
, FileUpload (..)
, FileUploadContent (..)
, SetWebhookRequest (..)
, GetUpdatesRequest (..)
, SendPhotoRequest (..)
, SendAudioRequest (..)
, SendDocumentRequest (..)
, SendStickerRequest (..)
, SendVideoRequest (..)
, SendVoiceRequest (..)
, SendVideoNoteRequest (..)
, SendMediaGroupRequest (..)
, SendLocationRequest (..)
, SendVenueRequest (..)
, SendContactRequest (..)
, SendChatActionRequest (..)
, SendGameRequest (..)
, ChatAction (..)
, AnswerInlineQueryRequest (..)
, AnswerCallbackQueryRequest (..)
, ReplyKeyboard (..)
, EditMessageTextRequest (..)
, EditMessageCaptionRequest (..)
, EditMessageReplyMarkupRequest (..)
, SendInvoiceRequest (..)
, AnswerShippingQueryRequest (..)
, AnswerPreCheckoutQueryRequest (..)
, RestrictChatMemberRequest (..)
, PromoteChatMemberRequest (..)
, SetChatPhotoRequest (..)
, UploadStickerFileRequest (..)
, CreateNewStickerSetRequest (..)
, AddStickerToSetRequest (..)
, EditMessageLiveLocationRequest (..)
, StopMessageLiveLocationRequest (..)
, localFileUpload
, setWebhookRequest
, setWebhookRequest'
, getUpdatesRequest
, sendMessageRequest
, forwardMessageRequest
, sendPhotoRequest
, uploadPhotoRequest
, sendAudioRequest
, uploadAudioRequest
, sendDocumentRequest
, uploadDocumentRequest
, sendStickerRequest
, uploadStickerRequest
, sendVideoRequest
, uploadVideoRequest
, sendVoiceRequest
, uploadVoiceRequest
, sendVideoNoteRequest
, uploadVideoNoteRequest
, sendMediaGroupRequest
, sendLocationRequest
, sendVenueRequest
, sendContactRequest
, sendChatActionRequest
, sendGameRequest
, answerInlineQueryRequest
, answerCallbackQueryRequest
, inlineKeyboardMarkup
, replyKeyboardMarkup
, replyKeyboardHide
, forceReply
, editMessageTextRequest
, editInlineMessageTextRequest
, editMessageCaptionRequest
, editInlineMessageCaptionRequest
, editMessageReplyMarkupRequest
, editInlineMessageReplyMarkupRequest
, sendInvoiceRequest
, okShippingQueryRequest
, errorShippingQueryRequest
, okAnswerPrecheckoutQueryRequest
, errorAnswerPrecheckoutQueryRequest
, restrictChatMemberRequest
, promoteChatMemberRequest
) where
import Data.Aeson
import Data.Aeson.Types (typeMismatch)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Int (Int64)
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import GHC.Generics
import Network.HTTP.Client.MultipartFormData
import Network.Mime
import Servant.Client.MultipartFormData (ToMultipartFormData (..))
import Web.Telegram.API.Bot.Data (CurrencyCode,
InlineKeyboardButton,
InlineKeyboardMarkup,
InlineQueryResult,
InputMedia,
KeyboardButton,
LabeledPrice,
MaskPosition, ParseMode,
ShippingOption)
import Web.Telegram.API.Bot.JsonExt
data FileUploadContent =
FileUploadFile FilePath
| FileUploadBS BS.ByteString
| FileUploadLBS LBS.ByteString
data FileUpload = FileUpload
{
fileUpload_type :: Maybe MimeType
, fileUpload_content :: FileUploadContent
}
localFileUpload :: FilePath -> FileUpload
localFileUpload path = FileUpload
{ fileUpload_type = Nothing
, fileUpload_content = FileUploadFile path
}
fileUploadToPart :: Text -> FileUpload -> Part
fileUploadToPart inputName fileUpload =
let part =
case fileUpload_content fileUpload of
FileUploadFile path -> partFileSource inputName path
FileUploadBS bs -> partBS inputName bs
FileUploadLBS lbs -> partLBS inputName lbs
in part { partContentType = fileUpload_type fileUpload }
utf8Part :: Text -> Text -> Part
utf8Part inputName = partBS inputName . T.encodeUtf8
data SetWebhookRequest = SetWebhookRequest
{
webhook_url :: Text
, webhook_certificate :: FileUpload
, webhook_max_connections :: Maybe Int
}
| SetWebhookWithoutCertRequest
{
webhook_url :: Text
, webhook_max_connections :: Maybe Int
, webhook_allowed_updates :: Maybe [Text]
} deriving (Generic)
instance ToJSON SetWebhookRequest where
toJSON SetWebhookRequest{} = undefined
toJSON (SetWebhookWithoutCertRequest url maxConnections allowedUpdates) = object $
("url" .= url) : catMaybes [
("max_connections" .=) <$> maxConnections,
("allowed_updates" .=) <$> allowedUpdates]
instance ToMultipartFormData SetWebhookRequest where
toMultipartFormData req =
[ utf8Part "url" $ webhook_url req
, fileUploadToPart "certificate" $ webhook_certificate req ] ++
catMaybes
[ utf8Part "max_connections" . tshow <$> webhook_max_connections req
]
setWebhookRequest :: Text -> FileUpload -> SetWebhookRequest
setWebhookRequest url certificate = SetWebhookRequest url certificate Nothing
setWebhookRequest' :: Text -> SetWebhookRequest
setWebhookRequest' url = SetWebhookWithoutCertRequest url Nothing Nothing
data GetUpdatesRequest = GetUpdatesRequest
{
updates_offset :: Maybe Int
, updates_limit :: Maybe Int
, updates_timeout :: Maybe Int
, updates_allowed_updates :: Maybe [Text]
} deriving (Show, Generic)
instance ToJSON GetUpdatesRequest where
toJSON = toJsonDrop 8
instance FromJSON GetUpdatesRequest where
parseJSON = parseJsonDrop 8
getUpdatesRequest :: GetUpdatesRequest
getUpdatesRequest = GetUpdatesRequest Nothing Nothing Nothing Nothing
data ChatId = ChatId Int64 | ChatChannel Text
deriving (Show)
instance ToJSON ChatId where
toJSON (ChatId integer) = toJSON integer
toJSON (ChatChannel text) = String text
instance FromJSON ChatId where
parseJSON value@Number{} = ChatId <$> parseJSON value
parseJSON (String text) = pure $ ChatChannel text
parseJSON wat = typeMismatch "Int64 or String" wat
chatIdToPart :: ChatId -> Text
chatIdToPart (ChatId integer) = tshow integer
chatIdToPart (ChatChannel text) = text
data SendMessageRequest = SendMessageRequest
{
message_chat_id :: ChatId
, message_text :: Text
, message_parse_mode :: Maybe ParseMode
, message_disable_web_page_preview :: Maybe Bool
, message_disable_notification :: Maybe Bool
, message_reply_to_message_id :: Maybe Int
, message_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON SendMessageRequest where
toJSON = toJsonDrop 8
instance FromJSON SendMessageRequest where
parseJSON = parseJsonDrop 8
sendMessageRequest :: ChatId -> Text -> SendMessageRequest
sendMessageRequest chatId text = SendMessageRequest chatId text Nothing Nothing Nothing Nothing Nothing
data ForwardMessageRequest = ForwardMessageRequest
{
forward_chat_id :: ChatId
, forward_from_chat_id :: ChatId
, forward_disable_notification :: Maybe Bool
, forward_message_id :: Int
} deriving (Show, Generic)
instance ToJSON ForwardMessageRequest where
toJSON = toJsonDrop 8
instance FromJSON ForwardMessageRequest where
parseJSON = parseJsonDrop 8
forwardMessageRequest :: ChatId -> ChatId -> Int -> ForwardMessageRequest
forwardMessageRequest chatId fromChatId forwardMessageId = ForwardMessageRequest chatId fromChatId Nothing forwardMessageId
data SendPhotoRequest payload = SendPhotoRequest
{
photo_chat_id :: ChatId
, photo_photo :: payload
, photo_caption :: Maybe Text
, photo_disable_notification :: Maybe Bool
, photo_reply_to_message_id :: Maybe Int
, photo_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendPhotoRequest Text) where
toJSON = toJsonDrop 6
instance FromJSON (SendPhotoRequest Text) where
parseJSON = parseJsonDrop 6
sendPhotoRequest :: ChatId -> Text -> SendPhotoRequest Text
sendPhotoRequest chatId photo = SendPhotoRequest chatId photo Nothing Nothing Nothing Nothing
uploadPhotoRequest :: ChatId -> FileUpload -> SendPhotoRequest FileUpload
uploadPhotoRequest chatId photo = SendPhotoRequest chatId photo Nothing Nothing Nothing Nothing
instance ToMultipartFormData (SendPhotoRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ photo_chat_id req) ] ++
catMaybes
[ utf8Part "caption" <$> photo_caption req
, partLBS "disable_notification" . encode <$> photo_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> photo_reply_to_message_id req
, partLBS "reply_markup" . encode <$> photo_reply_markup req
] ++
[ fileUploadToPart "photo" (photo_photo req) ]
data SendAudioRequest payload = SendAudioRequest
{
_audio_chat_id :: ChatId
, _audio_audio :: payload
, _audio_caption :: Maybe Text
, _audio_duration :: Maybe Int
, _audio_performer :: Maybe Text
, _audio_title :: Maybe Text
, _audio_disable_notification :: Maybe Bool
, _audio_reply_to_message_id :: Maybe Int
, _audio_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendAudioRequest Text) where
toJSON = toJsonDrop 7
instance FromJSON (SendAudioRequest Text) where
parseJSON = parseJsonDrop 7
instance ToMultipartFormData (SendAudioRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ _audio_chat_id req) ] ++
catMaybes
[ utf8Part "duration" . tshow <$> _audio_duration req
, utf8Part "performer" <$> _audio_performer req
, utf8Part "title" <$> _audio_title req
, partLBS "disable_notification" . encode <$> _audio_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> _audio_reply_to_message_id req
, partLBS "reply_markup" . encode <$> _audio_reply_markup req
] ++
[ fileUploadToPart "audio" (_audio_audio req) ]
sendAudioRequest :: ChatId -> Text -> SendAudioRequest Text
sendAudioRequest chatId audio = SendAudioRequest chatId audio Nothing Nothing Nothing Nothing Nothing Nothing Nothing
uploadAudioRequest :: ChatId -> FileUpload -> SendAudioRequest FileUpload
uploadAudioRequest chatId audio = SendAudioRequest chatId audio Nothing Nothing Nothing Nothing Nothing Nothing Nothing
data SendStickerRequest payload = SendStickerRequest
{
sticker_chat_id :: ChatId
, sticker_sticker :: payload
, sticker_disable_notification :: Maybe Bool
, sticker_reply_to_message_id :: Maybe Int
, sticker_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendStickerRequest Text) where
toJSON = toJsonDrop 8
instance FromJSON (SendStickerRequest Text) where
parseJSON = parseJsonDrop 8
instance ToMultipartFormData (SendStickerRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ sticker_chat_id req) ] ++
catMaybes
[ partLBS "disable_notification" . encode <$> sticker_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> sticker_reply_to_message_id req
, partLBS "reply_markup" . encode <$> sticker_reply_markup req
] ++
[ fileUploadToPart "sticker" (sticker_sticker req) ]
sendStickerRequest :: ChatId -> Text -> SendStickerRequest Text
sendStickerRequest chatId sticker = SendStickerRequest chatId sticker Nothing Nothing Nothing
uploadStickerRequest :: ChatId -> FileUpload -> SendStickerRequest FileUpload
uploadStickerRequest chatId sticker = SendStickerRequest chatId sticker Nothing Nothing Nothing
data SendDocumentRequest payload = SendDocumentRequest
{
document_chat_id :: ChatId
, document_document :: payload
, document_caption :: Maybe Text
, document_disable_notification :: Maybe Bool
, document_reply_to_message_id :: Maybe Int
, document_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendDocumentRequest Text) where
toJSON = toJsonDrop 9
instance FromJSON (SendDocumentRequest Text) where
parseJSON = parseJsonDrop 9
instance ToMultipartFormData (SendDocumentRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ document_chat_id req) ] ++
catMaybes
[ utf8Part "caption" <$> document_caption req
, partLBS "disable_notification" . encode <$> document_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> document_reply_to_message_id req
, partLBS "reply_markup" . encode <$> document_reply_markup req
] ++
[ fileUploadToPart "document" (document_document req) ]
sendDocumentRequest :: ChatId -> Text -> SendDocumentRequest Text
sendDocumentRequest chatId document = SendDocumentRequest chatId document Nothing Nothing Nothing Nothing
uploadDocumentRequest :: ChatId -> FileUpload -> SendDocumentRequest FileUpload
uploadDocumentRequest chatId document = SendDocumentRequest chatId document Nothing Nothing Nothing Nothing
data SendVideoRequest payload = SendVideoRequest
{
_video_chat_id :: ChatId
, _video_video :: payload
, _video_duration :: Maybe Int
, _video_caption :: Maybe Text
, _video_disable_notification :: Maybe Bool
, _video_reply_to_message_id :: Maybe Int
, _video_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendVideoRequest Text) where
toJSON = toJsonDrop 7
instance FromJSON (SendVideoRequest Text) where
parseJSON = parseJsonDrop 7
instance ToMultipartFormData (SendVideoRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ _video_chat_id req) ] ++
catMaybes
[ partLBS "duration" . encode <$> _video_duration req
, utf8Part "caption" <$> _video_caption req
, partLBS "disable_notification" . encode <$> _video_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> _video_reply_to_message_id req
, partLBS "reply_markup" . encode <$> _video_reply_markup req
] ++
[ fileUploadToPart "video" (_video_video req) ]
sendVideoRequest :: ChatId -> Text -> SendVideoRequest Text
sendVideoRequest chatId video = SendVideoRequest chatId video Nothing Nothing Nothing Nothing Nothing
uploadVideoRequest :: ChatId -> FileUpload -> SendVideoRequest FileUpload
uploadVideoRequest chatId video = SendVideoRequest chatId video Nothing Nothing Nothing Nothing Nothing
data SendVoiceRequest payload = SendVoiceRequest
{
_voice_chat_id :: ChatId
, _voice_voice :: payload
, _voice_caption :: Maybe Text
, _voice_duration :: Maybe Int
, _voice_disable_notification :: Maybe Bool
, _voice_reply_to_message_id :: Maybe Int
, _voice_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendVoiceRequest Text) where
toJSON = toJsonDrop 7
instance FromJSON (SendVoiceRequest Text) where
parseJSON = parseJsonDrop 7
instance ToMultipartFormData (SendVoiceRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ _voice_chat_id req) ] ++
catMaybes
[ partLBS "duration" . encode <$> _voice_duration req
, partLBS "disable_notification" . encode <$> _voice_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> _voice_reply_to_message_id req
, partLBS "reply_markup" . encode <$> _voice_reply_markup req
] ++
[ fileUploadToPart "voice" (_voice_voice req) ]
sendVoiceRequest :: ChatId -> Text -> SendVoiceRequest Text
sendVoiceRequest chatId voice = SendVoiceRequest chatId voice Nothing Nothing Nothing Nothing Nothing
uploadVoiceRequest :: ChatId -> FileUpload -> SendVoiceRequest FileUpload
uploadVoiceRequest chatId voice = SendVoiceRequest chatId voice Nothing Nothing Nothing Nothing Nothing
data SendVideoNoteRequest payload = SendVideoNoteRequest
{
_vid_note_chat_id :: ChatId
, _vid_note_video_note :: payload
, _vid_note_duration :: Maybe Int
, _vid_note_length :: Maybe Int
, _vid_note_disable_notification :: Maybe Bool
, _vid_note_reply_to_message_id :: Maybe Int
, _vid_note_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON (SendVideoNoteRequest Text) where
toJSON = toJsonDrop 9
instance FromJSON (SendVideoNoteRequest Text) where
parseJSON = parseJsonDrop 9
instance ToMultipartFormData (SendVideoNoteRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ _vid_note_chat_id req) ] ++
catMaybes
[ partLBS "duration" . encode <$> _vid_note_duration req
, partLBS "length" . encode <$> _vid_note_length req
, partLBS "disable_notification" . encode <$> _vid_note_disable_notification req
, utf8Part "reply_to_message_id" . tshow <$> _vid_note_reply_to_message_id req
, partLBS "reply_markup" . encode <$> _vid_note_reply_markup req
] ++
[ fileUploadToPart "video_note" (_vid_note_video_note req) ]
sendVideoNoteRequest :: ChatId -> Text -> SendVideoNoteRequest Text
sendVideoNoteRequest chatId videoNote = SendVideoNoteRequest chatId videoNote Nothing Nothing Nothing Nothing Nothing
uploadVideoNoteRequest :: ChatId -> FileUpload -> SendVideoNoteRequest FileUpload
uploadVideoNoteRequest chatId videoNote = SendVideoNoteRequest chatId videoNote Nothing Nothing Nothing Nothing Nothing
data SendLocationRequest = SendLocationRequest
{
location_chat_id :: ChatId
, location_latitude :: Float
, location_longitude :: Float
, location_live_period :: Maybe Int
, location_disable_notification :: Maybe Bool
, location_reply_to_message_id :: Maybe Int
, location_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON SendLocationRequest where
toJSON = toJsonDrop 9
instance FromJSON SendLocationRequest where
parseJSON = parseJsonDrop 9
sendLocationRequest :: ChatId -> Float -> Float -> SendLocationRequest
sendLocationRequest chatId latitude longitude = SendLocationRequest chatId latitude longitude Nothing Nothing Nothing Nothing
data SendMediaGroupRequest = SendMediaGroupRequest
{
media_group_chat_id :: ChatId
, media_group_media :: [InputMedia]
, media_group_disable_notification :: Maybe Bool
, media_group_reply_to_message_id :: Maybe Int
} deriving(Show, Generic)
instance ToJSON SendMediaGroupRequest where
toJSON = toJsonDrop 12
instance FromJSON SendMediaGroupRequest where
parseJSON = parseJsonDrop 12
sendMediaGroupRequest :: ChatId -> [InputMedia] -> SendMediaGroupRequest
sendMediaGroupRequest chatId inputMediaArray = SendMediaGroupRequest chatId inputMediaArray Nothing Nothing
data SendVenueRequest = SendVenueRequest
{
_venue_chat_id :: ChatId
, _venue_latitude :: Float
, _venue_longitude :: Float
, _venue_title :: Text
, _venue_address :: Text
, _venue_foursquare_id :: Maybe Text
, _venue_disable_notification :: Maybe Bool
, _venue_reply_to_message_id :: Maybe Int
, _venue_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON SendVenueRequest where
toJSON = toJsonDrop 7
instance FromJSON SendVenueRequest where
parseJSON = parseJsonDrop 7
sendVenueRequest :: ChatId -> Float -> Float -> Text -> Text -> SendVenueRequest
sendVenueRequest chatId latitude longitude title address = SendVenueRequest chatId latitude longitude title address Nothing Nothing Nothing Nothing
data SendContactRequest = SendContactRequest
{
_contact_chat_id :: ChatId
, _contact_phone_number :: Text
, _contact_first_name :: Text
, _contact_last_name :: Maybe Text
, _contact_disable_notification :: Maybe Bool
, _contact_reply_to_message_id :: Maybe Int
, _contact_reply_markup :: Maybe ReplyKeyboard
} deriving (Show, Generic)
instance ToJSON SendContactRequest where
toJSON = toJsonDrop 9
instance FromJSON SendContactRequest where
parseJSON = parseJsonDrop 9
sendContactRequest :: ChatId -> Text -> Text -> SendContactRequest
sendContactRequest chatId phoneNumber firstName = SendContactRequest chatId phoneNumber firstName Nothing Nothing Nothing Nothing
data ChatAction = Typing
| UploadPhoto
| RecordVideo
| UploadVideo
| RecordAudio
| UploadAudio
| UploadDocument
| FindLocation
| RecordVideoNote
| UploadVideoNote deriving (Show, Generic)
instance ToJSON ChatAction where
toJSON Typing = "typing"
toJSON UploadPhoto = "upload_photo"
toJSON RecordVideo = "record_video"
toJSON UploadVideo = "upload_video"
toJSON RecordAudio = "record_audio"
toJSON UploadAudio = "upload_audio"
toJSON UploadDocument = "upload_document"
toJSON FindLocation = "find_location"
toJSON RecordVideoNote = "record_video_note"
toJSON UploadVideoNote = "upload_video_note"
instance FromJSON ChatAction where
parseJSON "typing" = pure Typing
parseJSON "upload_photo" = pure UploadPhoto
parseJSON "record_video" = pure RecordVideo
parseJSON "upload_video" = pure UploadVideo
parseJSON "record_audio" = pure RecordAudio
parseJSON "upload_audio" = pure UploadAudio
parseJSON "upload_document" = pure UploadDocument
parseJSON "find_location" = pure FindLocation
parseJSON "record_video_note" = pure RecordVideoNote
parseJSON "upload_video_note" = pure UploadVideoNote
parseJSON _ = fail "Failed to parse ChatAction"
data SendChatActionRequest = SendChatActionRequest
{
action_chat_id :: ChatId
, action_action :: ChatAction
} deriving (Show, Generic)
instance ToJSON SendChatActionRequest where
toJSON = toJsonDrop 7
instance FromJSON SendChatActionRequest where
parseJSON = parseJsonDrop 7
sendChatActionRequest :: ChatId -> ChatAction -> SendChatActionRequest
sendChatActionRequest = SendChatActionRequest
data SendGameRequest = SendGameRequest
{
game_chat_id :: Integer
, game_game_short_name :: Text
, game_disable_notification :: Maybe Bool
, game_reply_to_message_id :: Maybe Int
, game_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON SendGameRequest where
toJSON = toJsonDrop 5
instance FromJSON SendGameRequest where
parseJSON = parseJsonDrop 5
sendGameRequest :: Integer -> Text -> SendGameRequest
sendGameRequest chatId shortName = SendGameRequest chatId shortName Nothing Nothing Nothing
data AnswerInlineQueryRequest = AnswerInlineQueryRequest
{
query_inline_query_id :: Text
, query_results :: [InlineQueryResult]
, query_cache_time :: Maybe Int
, query_is_personal :: Maybe Bool
, query_next_offset :: Maybe Text
, query_switch_pm_text :: Maybe Text
, query_switch_pm_parameter :: Maybe Text
} deriving (Show, Generic)
instance ToJSON AnswerInlineQueryRequest where
toJSON = toJsonDrop 6
instance FromJSON AnswerInlineQueryRequest where
parseJSON = parseJsonDrop 6
answerInlineQueryRequest :: Text -> [InlineQueryResult] -> AnswerInlineQueryRequest
answerInlineQueryRequest queryId results = AnswerInlineQueryRequest queryId results Nothing Nothing Nothing Nothing Nothing
data AnswerCallbackQueryRequest = AnswerCallbackQueryRequest
{
cq_callback_query_id :: Text
, cq_text :: Maybe Text
, cq_show_alert :: Maybe Bool
, cq_url :: Maybe Text
, cq_cache_time :: Maybe Int
} deriving (Show, Generic)
instance ToJSON AnswerCallbackQueryRequest where
toJSON = toJsonDrop 3
instance FromJSON AnswerCallbackQueryRequest where
parseJSON = parseJsonDrop 3
answerCallbackQueryRequest :: Text -> AnswerCallbackQueryRequest
answerCallbackQueryRequest queryId = AnswerCallbackQueryRequest queryId Nothing Nothing Nothing Nothing
data ReplyKeyboard =
ReplyInlineKeyboardMarkup
{
reply_inline_keyboard :: [[InlineKeyboardButton]]
}
| ReplyKeyboardMarkup
{
reply_keyboard :: [[KeyboardButton]]
, reply_resize_keyboard :: Maybe Bool
, reply_one_time_keyboard :: Maybe Bool
, reply_selective :: Maybe Bool
}
| ReplyKeyboardHide
{
reply_hide_keyboard :: Bool
, reply_selective :: Maybe Bool
}
| ReplyKeyboardRemove
{
reply_remove_keyboard :: Bool
, reply_selective :: Maybe Bool
}
| ForceReply
{
reply_force_reply :: Bool
, reply_selective :: Maybe Bool
} deriving (Show, Generic)
instance ToJSON ReplyKeyboard where
toJSON = toJsonDrop 6
instance FromJSON ReplyKeyboard where
parseJSON = parseJsonDrop 6
inlineKeyboardMarkup :: [[InlineKeyboardButton]] -> ReplyKeyboard
inlineKeyboardMarkup = ReplyInlineKeyboardMarkup
replyKeyboardMarkup :: [[KeyboardButton]] -> ReplyKeyboard
replyKeyboardMarkup keyboard = ReplyKeyboardMarkup keyboard Nothing Nothing Nothing
replyKeyboardHide :: ReplyKeyboard
replyKeyboardHide = ReplyKeyboardHide True Nothing
forceReply :: ReplyKeyboard
forceReply = ForceReply True Nothing
data EditMessageTextRequest = EditMessageTextRequest
{
emt_chat_id :: Maybe ChatId
, emt_message_id :: Maybe Int
, emt_inline_message_id :: Maybe Text
, emt_text :: Text
, emt_parse_mode :: Maybe ParseMode
, emt_disable_web_page_preview :: Maybe Bool
, emt_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON EditMessageTextRequest where
toJSON = toJsonDrop 4
instance FromJSON EditMessageTextRequest where
parseJSON = parseJsonDrop 4
editMessageTextRequest :: ChatId -> Int -> Text -> EditMessageTextRequest
editMessageTextRequest chatId messageId text = EditMessageTextRequest (Just chatId) (Just messageId) Nothing text Nothing Nothing Nothing
editInlineMessageTextRequest :: Text -> Text -> EditMessageTextRequest
editInlineMessageTextRequest inlineMessageId text = EditMessageTextRequest Nothing Nothing (Just inlineMessageId) text Nothing Nothing Nothing
data EditMessageCaptionRequest = EditMessageCaptionRequest
{
emc_chat_id :: Maybe ChatId
, emc_message_id :: Maybe Int
, emc_inline_message_id :: Maybe Text
, emc_caption :: Maybe Text
, emc_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON EditMessageCaptionRequest where
toJSON = toJsonDrop 4
instance FromJSON EditMessageCaptionRequest where
parseJSON = parseJsonDrop 4
editMessageCaptionRequest :: ChatId -> Int -> Maybe Text -> EditMessageCaptionRequest
editMessageCaptionRequest chatId messageId caption = EditMessageCaptionRequest (Just chatId) (Just messageId) Nothing caption Nothing
editInlineMessageCaptionRequest :: Text -> Maybe Text -> EditMessageCaptionRequest
editInlineMessageCaptionRequest inlineMessageId caption = EditMessageCaptionRequest Nothing Nothing (Just inlineMessageId) caption Nothing
data EditMessageReplyMarkupRequest = EditMessageReplyMarkupRequest
{
emrm_chat_id :: Maybe ChatId
, emrm_message_id :: Maybe Int
, emrm_inline_message_id :: Maybe Text
, emrm_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON EditMessageReplyMarkupRequest where
toJSON = toJsonDrop 5
instance FromJSON EditMessageReplyMarkupRequest where
parseJSON = parseJsonDrop 5
editMessageReplyMarkupRequest :: ChatId -> Int -> Maybe InlineKeyboardMarkup -> EditMessageReplyMarkupRequest
editMessageReplyMarkupRequest chatId messageId keyboard = EditMessageReplyMarkupRequest (Just chatId) (Just messageId) Nothing keyboard
editInlineMessageReplyMarkupRequest :: Text -> Maybe InlineKeyboardMarkup -> EditMessageReplyMarkupRequest
editInlineMessageReplyMarkupRequest inlineMessageId keyboard = EditMessageReplyMarkupRequest Nothing Nothing (Just inlineMessageId) keyboard
data SendInvoiceRequest = SendInvoiceRequest
{
snd_inv_chat_id :: Int64
, snd_inv_title :: Text
, snd_inv_description :: Text
, snd_inv_payload :: Text
, snd_inv_provider_token :: Text
, snd_inv_start_parameter :: Text
, snd_inv_currency :: CurrencyCode
, snd_inv_prices :: [LabeledPrice]
, snd_inv_provider_data :: Maybe Text
, snd_inv_photo_url :: Maybe Text
, snd_inv_photo_size :: Maybe Int
, snd_inv_photo_width :: Maybe Int
, snd_inv_photo_height :: Maybe Int
, snd_inv_need_name :: Maybe Bool
, snd_inv_need_phone_number :: Maybe Bool
, snd_inv_need_email :: Maybe Bool
, snd_inv_need_shipping_address :: Maybe Bool
, snd_inv_is_flexible :: Maybe Bool
, snd_inv_disable_notification :: Maybe Bool
, snd_inv_reply_to_message :: Maybe Int
, snd_inv_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON SendInvoiceRequest where
toJSON = toJsonDrop 8
instance FromJSON SendInvoiceRequest where
parseJSON = parseJsonDrop 8
sendInvoiceRequest :: Int64
-> Text
-> Text
-> Text
-> Text
-> Text
-> CurrencyCode
-> [LabeledPrice]
-> SendInvoiceRequest
sendInvoiceRequest chatId title description payload providerToken startParameter currency prices
= SendInvoiceRequest chatId title description payload providerToken startParameter currency prices Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
data AnswerShippingQueryRequest
= AnswerShippingQueryRequest
{
asq_shipping_query_id :: Text
, asq_ok :: Bool
, asq_shipping_options :: Maybe [ShippingOption]
, asq_error_message :: Maybe Text
} deriving (Show, Generic)
instance ToJSON AnswerShippingQueryRequest where
toJSON = toJsonDrop 4
instance FromJSON AnswerShippingQueryRequest where
parseJSON = parseJsonDrop 4
okShippingQueryRequest :: Text -> [ShippingOption] -> AnswerShippingQueryRequest
okShippingQueryRequest queryId options = AnswerShippingQueryRequest queryId True (Just options) Nothing
errorShippingQueryRequest :: Text -> Text -> AnswerShippingQueryRequest
errorShippingQueryRequest queryId errorMsg = AnswerShippingQueryRequest queryId False Nothing (Just errorMsg)
data AnswerPreCheckoutQueryRequest
= AnswerPreCheckoutQueryRequest
{
apc_pre_checkout_query_id :: Text
, apc_ok :: Bool
, apc_error_message :: Maybe Text
} deriving (Show, Generic)
instance ToJSON AnswerPreCheckoutQueryRequest where
toJSON = toJsonDrop 4
instance FromJSON AnswerPreCheckoutQueryRequest where
parseJSON = parseJsonDrop 4
okAnswerPrecheckoutQueryRequest :: Text -> AnswerPreCheckoutQueryRequest
okAnswerPrecheckoutQueryRequest queryId = AnswerPreCheckoutQueryRequest queryId True Nothing
errorAnswerPrecheckoutQueryRequest :: Text -> Text -> AnswerPreCheckoutQueryRequest
errorAnswerPrecheckoutQueryRequest queryId errorMessage = AnswerPreCheckoutQueryRequest queryId False $ Just errorMessage
data RestrictChatMemberRequest = RestrictChatMemberRequest
{
rcm_chat_id :: ChatId
, rcm_user_id :: Int
, rcm_until_date :: Maybe Int
, rcm_can_send_messages :: Maybe Bool
, rcm_can_send_media_messages :: Maybe Bool
, rcm_can_send_other_messages :: Maybe Bool
, rcm_can_add_web_page_previews :: Maybe Bool
} deriving (Show, Generic)
instance ToJSON RestrictChatMemberRequest where
toJSON = toJsonDrop 4
instance FromJSON RestrictChatMemberRequest where
parseJSON = parseJsonDrop 4
restrictChatMemberRequest :: ChatId -> Int -> RestrictChatMemberRequest
restrictChatMemberRequest chatId userId = RestrictChatMemberRequest chatId userId Nothing Nothing Nothing Nothing Nothing
data PromoteChatMemberRequest = PromoteChatMemberRequest
{
pcmr_chat_id :: ChatId
, pcmr_user_id :: Int
, pcmr_can_change_info :: Maybe Bool
, pcmr_can_post_messages :: Maybe Bool
, pcmr_can_edit_messages :: Maybe Bool
, pcmr_can_delete_messages :: Maybe Bool
, pcmr_can_invite_users :: Maybe Bool
, pcmr_can_restrict_members :: Maybe Bool
, pcmr_can_pin_messages :: Maybe Bool
, pcmr_can_promote_members :: Maybe Bool
} deriving (Show, Generic)
instance ToJSON PromoteChatMemberRequest where
toJSON = toJsonDrop 5
instance FromJSON PromoteChatMemberRequest where
parseJSON = parseJsonDrop 5
promoteChatMemberRequest :: ChatId -> Int -> PromoteChatMemberRequest
promoteChatMemberRequest chatId userId = PromoteChatMemberRequest chatId userId Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
data SetChatPhotoRequest = SetChatPhotoRequest
{
scp_chat_id :: ChatId
, scp_photo :: FileUpload
}
instance ToMultipartFormData SetChatPhotoRequest where
toMultipartFormData req =
[ utf8Part "chat_id" (chatIdToPart $ scp_chat_id req)
, fileUploadToPart "photo" (scp_photo req) ]
data UploadStickerFileRequest = UploadStickerFileRequest
{
upload_sticker_user_id :: Int
, upload_sticker_png_sticker :: FileUpload
}
instance ToMultipartFormData UploadStickerFileRequest where
toMultipartFormData req =
[ utf8Part "user_id" (tshow $ upload_sticker_user_id req)
, fileUploadToPart "png_sticker" (upload_sticker_png_sticker req) ]
data CreateNewStickerSetRequest payload = CreateNewStickerSetRequest
{
new_sticker_set_user_id :: Int
, new_sticker_set_name :: Text
, new_sticker_set_title :: Text
, new_sticker_set_png_sticker :: payload
, new_sticker_set_emojis :: Text
, new_sticker_set_contains_masks :: Maybe Bool
, new_sticker_set_mask_position :: Maybe MaskPosition
} deriving (Show, Generic)
instance ToJSON (CreateNewStickerSetRequest Text) where
toJSON = toJsonDrop 16
instance FromJSON (CreateNewStickerSetRequest Text) where
parseJSON = parseJsonDrop 16
instance ToMultipartFormData (CreateNewStickerSetRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "user_id" (tshow $ new_sticker_set_user_id req)
, utf8Part "name" $ new_sticker_set_name req
, utf8Part "title" $ new_sticker_set_title req
, utf8Part "emojis" $ new_sticker_set_emojis req
, fileUploadToPart "png_sticker" (new_sticker_set_png_sticker req) ] ++
catMaybes
[ partLBS "contains_masks" . encode <$> new_sticker_set_contains_masks req
, partLBS "mask_position" . encode <$> new_sticker_set_mask_position req ]
data AddStickerToSetRequest payload = AddStickerToSetRequest
{
add_sticker_to_set_user_id :: Int
, add_sticker_to_set_name :: Text
, add_sticker_to_set_png_sticker :: payload
, add_sticker_to_set_emojis :: Text
, add_sticker_to_set_mask_position :: Maybe MaskPosition
} deriving (Show, Generic)
instance ToJSON (AddStickerToSetRequest Text) where
toJSON = toJsonDrop 19
instance FromJSON (AddStickerToSetRequest Text) where
parseJSON = parseJsonDrop 19
instance ToMultipartFormData (AddStickerToSetRequest FileUpload) where
toMultipartFormData req =
[ utf8Part "user_id" (tshow $ add_sticker_to_set_user_id req)
, utf8Part "name" $ add_sticker_to_set_name req
, utf8Part "emojis" $ add_sticker_to_set_emojis req
, fileUploadToPart "png_sticker" (add_sticker_to_set_png_sticker req) ] ++
catMaybes
[ partLBS "mask_position" . encode <$> add_sticker_to_set_mask_position req
]
data EditMessageLiveLocationRequest =
EditMessageLiveLocationRequest
{
edit_live_loc_chat_id :: Text
, edit_live_loc_latitude :: Float
, edit_live_loc_longitude :: Float
, edit_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
}
| EditMessageLiveLocationMessageRequest
{
edit_live_loc_message_id :: Int
, edit_live_loc_latitude :: Float
, edit_live_loc_longitude :: Float
, edit_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
}
| EditMessageLiveLocationInlineMessageRequest
{
edit_live_loc_inline_message_id :: Text
, edit_live_loc_latitude :: Float
, edit_live_loc_longitude :: Float
, edit_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON EditMessageLiveLocationRequest where
toJSON = toJsonDrop 14
instance FromJSON EditMessageLiveLocationRequest where
parseJSON = parseJsonDrop 14
data StopMessageLiveLocationRequest =
StopMessageLiveLocationRequest
{
stop_live_loc_chat_id :: Text
, stop_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
}
| StopMessageLiveLocationMessageRequest
{
stop_live_loc_message_id :: Int
, stop_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
}
| StopMessageLiveLocationInlineMessageRequest
{
stop_live_loc_inline_message_id :: Text
, stop_live_loc_reply_markup :: Maybe InlineKeyboardMarkup
} deriving (Show, Generic)
instance ToJSON StopMessageLiveLocationRequest where
toJSON = toJsonDrop 14
instance FromJSON StopMessageLiveLocationRequest where
parseJSON = parseJsonDrop 14
tshow :: Show a => a -> Text
tshow = T.pack . show