{-# 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.SendVideoNote 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 (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.Lazy as TL
import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests
import Telegram.Bot.API.Types
import Telegram.Bot.API.Internal.TH
data SendVideoNoteRequest = SendVideoNoteRequest
{ SendVideoNoteRequest -> Maybe BusinessConnectionId
sendVideoNoteBusinessConnectionId :: Maybe BusinessConnectionId
, SendVideoNoteRequest -> SomeChatId
sendVideoNoteChatId :: SomeChatId
, SendVideoNoteRequest -> Maybe MessageThreadId
sendVideoNoteMessageThreadId :: Maybe MessageThreadId
, SendVideoNoteRequest -> InputFile
sendVideoNoteVideoNote :: InputFile
, SendVideoNoteRequest -> Maybe Int
sendVideoNoteDuration :: Maybe Int
, SendVideoNoteRequest -> Maybe Int
sendVideoNoteLength :: Maybe Int
, SendVideoNoteRequest -> Maybe InputFile
sendVideoNoteThumbnail :: Maybe InputFile
, SendVideoNoteRequest -> Maybe Bool
sendVideoNoteDisableNotification :: Maybe Bool
, SendVideoNoteRequest -> Maybe Bool
sendVideoNoteProtectContent :: Maybe Bool
, SendVideoNoteRequest -> Maybe Text
sendVideoNoteMessageEffectId :: Maybe Text
, SendVideoNoteRequest -> Maybe MessageId
sendVideoNoteReplyToMessageId :: Maybe MessageId
, SendVideoNoteRequest -> Maybe ReplyParameters
sendVideoNoteReplyParameters :: Maybe ReplyParameters
, SendVideoNoteRequest -> Maybe InlineKeyboardMarkup
sendVideoNoteReplyMarkup :: Maybe InlineKeyboardMarkup
}
deriving (forall x. SendVideoNoteRequest -> Rep SendVideoNoteRequest x)
-> (forall x. Rep SendVideoNoteRequest x -> SendVideoNoteRequest)
-> Generic SendVideoNoteRequest
forall x. Rep SendVideoNoteRequest x -> SendVideoNoteRequest
forall x. SendVideoNoteRequest -> Rep SendVideoNoteRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SendVideoNoteRequest -> Rep SendVideoNoteRequest x
from :: forall x. SendVideoNoteRequest -> Rep SendVideoNoteRequest x
$cto :: forall x. Rep SendVideoNoteRequest x -> SendVideoNoteRequest
to :: forall x. Rep SendVideoNoteRequest x -> SendVideoNoteRequest
Generic
instance ToJSON SendVideoNoteRequest where toJSON :: SendVideoNoteRequest -> Value
toJSON = SendVideoNoteRequest -> Value
forall a (d :: Meta) (f :: * -> *).
(Generic a, GToJSON Zero (Rep a), Rep a ~ D1 d f, Datatype d) =>
a -> Value
gtoJSON
instance ToMultipart Tmp SendVideoNoteRequest where
toMultipart :: SendVideoNoteRequest -> MultipartData Tmp
toMultipart SendVideoNoteRequest{Maybe Bool
Maybe Int
Maybe Text
Maybe BusinessConnectionId
Maybe MessageThreadId
Maybe MessageId
Maybe InlineKeyboardMarkup
Maybe ReplyParameters
Maybe InputFile
SomeChatId
InputFile
sendVideoNoteBusinessConnectionId :: SendVideoNoteRequest -> Maybe BusinessConnectionId
sendVideoNoteChatId :: SendVideoNoteRequest -> SomeChatId
sendVideoNoteMessageThreadId :: SendVideoNoteRequest -> Maybe MessageThreadId
sendVideoNoteVideoNote :: SendVideoNoteRequest -> InputFile
sendVideoNoteDuration :: SendVideoNoteRequest -> Maybe Int
sendVideoNoteLength :: SendVideoNoteRequest -> Maybe Int
sendVideoNoteThumbnail :: SendVideoNoteRequest -> Maybe InputFile
sendVideoNoteDisableNotification :: SendVideoNoteRequest -> Maybe Bool
sendVideoNoteProtectContent :: SendVideoNoteRequest -> Maybe Bool
sendVideoNoteMessageEffectId :: SendVideoNoteRequest -> Maybe Text
sendVideoNoteReplyToMessageId :: SendVideoNoteRequest -> Maybe MessageId
sendVideoNoteReplyParameters :: SendVideoNoteRequest -> Maybe ReplyParameters
sendVideoNoteReplyMarkup :: SendVideoNoteRequest -> Maybe InlineKeyboardMarkup
sendVideoNoteBusinessConnectionId :: Maybe BusinessConnectionId
sendVideoNoteChatId :: SomeChatId
sendVideoNoteMessageThreadId :: Maybe MessageThreadId
sendVideoNoteVideoNote :: InputFile
sendVideoNoteDuration :: Maybe Int
sendVideoNoteLength :: Maybe Int
sendVideoNoteThumbnail :: Maybe InputFile
sendVideoNoteDisableNotification :: Maybe Bool
sendVideoNoteProtectContent :: Maybe Bool
sendVideoNoteMessageEffectId :: Maybe Text
sendVideoNoteReplyToMessageId :: Maybe MessageId
sendVideoNoteReplyParameters :: Maybe ReplyParameters
sendVideoNoteReplyMarkup :: Maybe InlineKeyboardMarkup
..} =
(MultipartData Tmp -> MultipartData Tmp)
-> (InputFile -> MultipartData Tmp -> MultipartData Tmp)
-> Maybe InputFile
-> MultipartData Tmp
-> MultipartData Tmp
forall b a. b -> (a -> b) -> Maybe a -> b
maybe MultipartData Tmp -> MultipartData Tmp
forall a. a -> a
id (Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"thumbnail") Maybe InputFile
sendVideoNoteThumbnail (MultipartData Tmp -> MultipartData Tmp)
-> MultipartData Tmp -> MultipartData Tmp
forall a b. (a -> b) -> a -> b
$
Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"video_note" InputFile
sendVideoNoteVideoNote (MultipartData Tmp -> MultipartData Tmp)
-> MultipartData Tmp -> MultipartData Tmp
forall a b. (a -> b) -> a -> b
$
[Input] -> [FileData Tmp] -> MultipartData Tmp
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields [] where
fields :: [Input]
fields =
[ Text -> Text -> Input
Input Text
"chat_id" (Text -> Input) -> Text -> Input
forall a b. (a -> b) -> a -> b
$ case SomeChatId
sendVideoNoteChatId of
SomeChatId (ChatId Integer
chat_id) -> Integer -> Text
forall a. Show a => a -> Text
showText Integer
chat_id
SomeChatUsername Text
txt -> Text
txt
] [Input] -> [Input] -> [Input]
forall a. Semigroup a => a -> a -> a
<> [Maybe Input] -> [Input]
forall a. [Maybe a] -> [a]
catMaybes
[ Maybe MessageThreadId
sendVideoNoteMessageThreadId Maybe MessageThreadId -> (MessageThreadId -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\MessageThreadId
t -> Text -> Text -> Input
Input Text
"message_thread_id" (MessageThreadId -> Text
forall a. Show a => a -> Text
showText MessageThreadId
t)
, Maybe Bool
sendVideoNoteDisableNotification Maybe Bool -> (Bool -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"disable_notification" (Text -> Text -> Bool -> Text
forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe Bool
sendVideoNoteProtectContent Maybe Bool -> (Bool -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Bool
t -> Text -> Text -> Input
Input Text
"protect_content" (Text -> Text -> Bool -> Text
forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
, Maybe MessageId
sendVideoNoteReplyToMessageId Maybe MessageId -> (MessageId -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\MessageId
t -> Text -> Text -> Input
Input Text
"reply_to_message_id" (LazyText -> Text
TL.toStrict (LazyText -> Text) -> LazyText -> Text
forall a b. (a -> b) -> a -> b
$ MessageId -> LazyText
forall a. ToJSON a => a -> LazyText
encodeToLazyText MessageId
t)
, Maybe ReplyParameters
sendVideoNoteReplyParameters Maybe ReplyParameters -> (ReplyParameters -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\ReplyParameters
t -> Text -> Text -> Input
Input Text
"reply_parameters" (LazyText -> Text
TL.toStrict (LazyText -> Text) -> LazyText -> Text
forall a b. (a -> b) -> a -> b
$ ReplyParameters -> LazyText
forall a. ToJSON a => a -> LazyText
encodeToLazyText ReplyParameters
t)
, Maybe InlineKeyboardMarkup
sendVideoNoteReplyMarkup Maybe InlineKeyboardMarkup
-> (InlineKeyboardMarkup -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\InlineKeyboardMarkup
t -> Text -> Text -> Input
Input Text
"reply_markup" (LazyText -> Text
TL.toStrict (LazyText -> Text) -> LazyText -> Text
forall a b. (a -> b) -> a -> b
$ InlineKeyboardMarkup -> LazyText
forall a. ToJSON a => a -> LazyText
encodeToLazyText InlineKeyboardMarkup
t)
]
type SendVideoNoteContent
= "sendVideoNote"
:> MultipartForm Tmp SendVideoNoteRequest
:> Post '[JSON] (Response Message)
type SendVideoNoteLink
= "sendVideoNote"
:> ReqBody '[JSON] SendVideoNoteRequest
:> Post '[JSON] (Response Message)
sendVideoNote :: SendVideoNoteRequest -> ClientM (Response Message)
sendVideoNote :: SendVideoNoteRequest -> ClientM (Response Message)
sendVideoNote SendVideoNoteRequest
r = case (SendVideoNoteRequest -> InputFile
sendVideoNoteVideoNote SendVideoNoteRequest
r, SendVideoNoteRequest -> Maybe InputFile
sendVideoNoteThumbnail SendVideoNoteRequest
r) of
(InputFile{}, Maybe InputFile
_) -> do
ByteString
boundary <- IO ByteString -> ClientM ByteString
forall a. IO a -> ClientM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
Proxy SendVideoNoteContent -> Client ClientM SendVideoNoteContent
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SendVideoNoteContent) (ByteString
boundary, SendVideoNoteRequest
r)
(InputFile
_, Just InputFile{}) -> do
ByteString
boundary <- IO ByteString -> ClientM ByteString
forall a. IO a -> ClientM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
Proxy SendVideoNoteContent -> Client ClientM SendVideoNoteContent
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SendVideoNoteContent) (ByteString
boundary, SendVideoNoteRequest
r)
(InputFile, Maybe InputFile)
_ -> Proxy SendVideoNoteLink -> Client ClientM SendVideoNoteLink
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @SendVideoNoteLink) SendVideoNoteRequest
r
makeDefault ''SendVideoNoteRequest