{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Telegram.Bot.API.Methods.SendVideo where
import Control.Monad.IO.Class (liftIO)
import Data.Aeson (ToJSON (..))
import Data.Aeson.Text (encodeToLazyText)
import Data.Bool
import Data.Maybe (catMaybes)
import Data.Functor ((<&>))
import Data.Proxy
import Data.Text
import GHC.Generics (Generic)
import Servant.API
import Servant.Multipart.API
import Servant.Multipart.Client
import Servant.Client hiding (Response)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Types
import Telegram.Bot.API.Types.ParseMode
data SendVideoRequest = SendVideoRequest
{ SendVideoRequest -> SomeChatId
sendVideoChatId :: SomeChatId
, SendVideoRequest -> Maybe MessageThreadId
sendVideoMessageThreadId :: Maybe MessageThreadId
, SendVideoRequest -> InputFile
sendVideoVideo :: InputFile
, SendVideoRequest -> Maybe Int
sendVideoDuration :: Maybe Int
, SendVideoRequest -> Maybe Int
sendVideoWidth :: Maybe Int
, SendVideoRequest -> Maybe Int
sendVideoHeight :: Maybe Int
, SendVideoRequest -> Maybe InputFile
sendVideoThumb :: Maybe InputFile
, SendVideoRequest -> Maybe Text
sendVideoCaption :: Maybe Text
, SendVideoRequest -> Maybe ParseMode
sendVideoParseMode :: Maybe ParseMode
, SendVideoRequest -> Maybe [MessageEntity]
sendVideoCaptionEntities :: Maybe [MessageEntity]
, SendVideoRequest -> Maybe Bool
sendVideoHasSpoiler :: Maybe Bool
, SendVideoRequest -> Maybe Bool
sendVideoSupportsStreaming :: Maybe Bool
, SendVideoRequest -> Maybe Bool
sendVideoDisableNotification :: Maybe Bool
, SendVideoRequest -> Maybe Bool
sendVideoProtectContent :: Maybe Bool
, SendVideoRequest -> Maybe MessageId
sendVideoReplyToMessageId :: Maybe MessageId
, SendVideoRequest -> Maybe Bool
sendVideoAllowSendingWithoutReply :: Maybe Bool
, SendVideoRequest -> Maybe InlineKeyboardMarkup
sendVideoReplyMarkup :: Maybe InlineKeyboardMarkup
}
deriving forall x. Rep SendVideoRequest x -> SendVideoRequest
forall x. SendVideoRequest -> Rep SendVideoRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendVideoRequest x -> SendVideoRequest
$cfrom :: forall x. SendVideoRequest -> Rep SendVideoRequest x
Generic
instance ToJSON SendVideoRequest where toJSON :: SendVideoRequest -> Value
toJSON = forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance ToMultipart Tmp SendVideoRequest where
toMultipart :: SendVideoRequest -> MultipartData Tmp
toMultipart SendVideoRequest{Maybe Bool
Maybe Int
Maybe [MessageEntity]
Maybe Text
Maybe MessageThreadId
Maybe MessageId
Maybe InlineKeyboardMarkup
Maybe ParseMode
Maybe InputFile
SomeChatId
InputFile
sendVideoReplyMarkup :: Maybe InlineKeyboardMarkup
sendVideoAllowSendingWithoutReply :: Maybe Bool
sendVideoReplyToMessageId :: Maybe MessageId
sendVideoProtectContent :: Maybe Bool
sendVideoDisableNotification :: Maybe Bool
sendVideoSupportsStreaming :: Maybe Bool
sendVideoHasSpoiler :: Maybe Bool
sendVideoCaptionEntities :: Maybe [MessageEntity]
sendVideoParseMode :: Maybe ParseMode
sendVideoCaption :: Maybe Text
sendVideoThumb :: Maybe InputFile
sendVideoHeight :: Maybe Int
sendVideoWidth :: Maybe Int
sendVideoDuration :: Maybe Int
sendVideoVideo :: InputFile
sendVideoMessageThreadId :: Maybe MessageThreadId
sendVideoChatId :: SomeChatId
sendVideoReplyMarkup :: SendVideoRequest -> Maybe InlineKeyboardMarkup
sendVideoAllowSendingWithoutReply :: SendVideoRequest -> Maybe Bool
sendVideoReplyToMessageId :: SendVideoRequest -> Maybe MessageId
sendVideoProtectContent :: SendVideoRequest -> Maybe Bool
sendVideoDisableNotification :: SendVideoRequest -> Maybe Bool
sendVideoSupportsStreaming :: SendVideoRequest -> Maybe Bool
sendVideoHasSpoiler :: SendVideoRequest -> Maybe Bool
sendVideoCaptionEntities :: SendVideoRequest -> Maybe [MessageEntity]
sendVideoParseMode :: SendVideoRequest -> Maybe ParseMode
sendVideoCaption :: SendVideoRequest -> Maybe Text
sendVideoThumb :: SendVideoRequest -> Maybe InputFile
sendVideoHeight :: SendVideoRequest -> Maybe Int
sendVideoWidth :: SendVideoRequest -> Maybe Int
sendVideoDuration :: SendVideoRequest -> Maybe Int
sendVideoVideo :: SendVideoRequest -> InputFile
sendVideoMessageThreadId :: SendVideoRequest -> Maybe MessageThreadId
sendVideoChatId :: SendVideoRequest -> SomeChatId
..} =
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"thumb") Maybe InputFile
sendVideoThumb forall a b. (a -> b) -> a -> b
$
Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"video" InputFile
sendVideoVideo forall a b. (a -> b) -> a -> b
$
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields [] where
fields :: [Input]
fields =
[ Text -> Text -> Input
Input Text
"chat_id" forall a b. (a -> b) -> a -> b
$ case SomeChatId
sendVideoChatId of
SomeChatId (ChatId Integer
chat_id) -> String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Integer
chat_id
SomeChatUsername Text
txt -> Text
txt
] forall a. Semigroup a => a -> a -> a
<> forall a. [Maybe a] -> [a]
catMaybes
[ Maybe MessageThreadId
sendVideoMessageThreadId forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\MessageThreadId
t -> Text -> Text -> Input
Input Text
"message_thread_id" (String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show MessageThreadId
t)
, Maybe Text
sendVideoCaption forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Text
t -> Text -> Text -> Input
Input Text
"caption" Text
t
, Maybe ParseMode
sendVideoParseMode forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\ParseMode
t -> Text -> Text -> Input
Input Text
"parse_mode" (Text -> Text
TL.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text -> Text
TL.replace Text
"\"" Text
"" forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText ParseMode
t)
, Maybe [MessageEntity]
sendVideoCaptionEntities forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\[MessageEntity]
t -> Text -> Text -> Input
Input Text
"caption_entities" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText [MessageEntity]
t)
, Maybe Bool
sendVideoHasSpoiler forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"has_spoiler" (forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe Int
sendVideoDuration forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Int
t -> Text -> Text -> Input
Input Text
"duration" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText Int
t)
, Maybe Int
sendVideoWidth forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Int
t -> Text -> Text -> Input
Input Text
"width" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText Int
t)
, Maybe Int
sendVideoHeight forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Int
t -> Text -> Text -> Input
Input Text
"height" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText Int
t)
, Maybe Bool
sendVideoDisableNotification forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"disable_notification" (forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe Bool
sendVideoSupportsStreaming forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"supports_streaming" (forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe Bool
sendVideoProtectContent forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"protect_content" (forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe MessageId
sendVideoReplyToMessageId forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\MessageId
t -> Text -> Text -> Input
Input Text
"reply_to_message_id" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText MessageId
t)
, Maybe Bool
sendVideoAllowSendingWithoutReply forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"allow_sending_without_reply" (forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe InlineKeyboardMarkup
sendVideoReplyMarkup forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\InlineKeyboardMarkup
t -> Text -> Text -> Input
Input Text
"reply_markup" (Text -> Text
TL.toStrict forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Text
encodeToLazyText InlineKeyboardMarkup
t)
]
type SendVideoContent
= "sendVideo"
:> MultipartForm Tmp SendVideoRequest
:> Post '[JSON] (Response Message)
type SendVideoLink
= "sendVideo"
:> ReqBody '[JSON] SendVideoRequest
:> Post '[JSON] (Response Message)
sendVideo :: SendVideoRequest -> ClientM (Response Message)
sendVideo :: SendVideoRequest -> ClientM (Response Message)
sendVideo SendVideoRequest
r = case (SendVideoRequest -> InputFile
sendVideoVideo SendVideoRequest
r, SendVideoRequest -> Maybe InputFile
sendVideoThumb SendVideoRequest
r) of
(InputFile{}, Maybe InputFile
_) -> do
ByteString
boundary <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendVideoContent) (ByteString
boundary, SendVideoRequest
r)
(InputFile
_, Just InputFile{}) -> do
ByteString
boundary <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendVideoContent) (ByteString
boundary, SendVideoRequest
r)
(InputFile, Maybe InputFile)
_ -> forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendVideoLink) SendVideoRequest
r