{-# 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 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
data SendVideoNoteRequest = SendVideoNoteRequest
{ 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
sendVideoNoteThumb :: Maybe InputFile
, SendVideoNoteRequest -> Maybe Bool
sendVideoNoteDisableNotification :: Maybe Bool
, SendVideoNoteRequest -> Maybe Bool
sendVideoNoteProtectContent :: Maybe Bool
, SendVideoNoteRequest -> Maybe MessageId
sendVideoNoteReplyToMessageId :: Maybe MessageId
, SendVideoNoteRequest -> Maybe Bool
sendVideoNoteAllowSendingWithoutReply :: Maybe Bool
, SendVideoNoteRequest -> Maybe InlineKeyboardMarkup
sendVideoNoteReplyMarkup :: Maybe InlineKeyboardMarkup
}
deriving 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
$cto :: forall x. Rep SendVideoNoteRequest x -> SendVideoNoteRequest
$cfrom :: forall x. SendVideoNoteRequest -> Rep SendVideoNoteRequest x
Generic
instance ToJSON SendVideoNoteRequest where toJSON :: SendVideoNoteRequest -> 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 SendVideoNoteRequest where
toMultipart :: SendVideoNoteRequest -> MultipartData Tmp
toMultipart SendVideoNoteRequest{Maybe Bool
Maybe Int
Maybe MessageThreadId
Maybe MessageId
Maybe InlineKeyboardMarkup
Maybe InputFile
SomeChatId
InputFile
sendVideoNoteReplyMarkup :: Maybe InlineKeyboardMarkup
sendVideoNoteAllowSendingWithoutReply :: Maybe Bool
sendVideoNoteReplyToMessageId :: Maybe MessageId
sendVideoNoteProtectContent :: Maybe Bool
sendVideoNoteDisableNotification :: Maybe Bool
sendVideoNoteThumb :: Maybe InputFile
sendVideoNoteLength :: Maybe Int
sendVideoNoteDuration :: Maybe Int
sendVideoNoteVideoNote :: InputFile
sendVideoNoteMessageThreadId :: Maybe MessageThreadId
sendVideoNoteChatId :: SomeChatId
sendVideoNoteReplyMarkup :: SendVideoNoteRequest -> Maybe InlineKeyboardMarkup
sendVideoNoteAllowSendingWithoutReply :: SendVideoNoteRequest -> Maybe Bool
sendVideoNoteReplyToMessageId :: SendVideoNoteRequest -> Maybe MessageId
sendVideoNoteProtectContent :: SendVideoNoteRequest -> Maybe Bool
sendVideoNoteDisableNotification :: SendVideoNoteRequest -> Maybe Bool
sendVideoNoteThumb :: SendVideoNoteRequest -> Maybe InputFile
sendVideoNoteLength :: SendVideoNoteRequest -> Maybe Int
sendVideoNoteDuration :: SendVideoNoteRequest -> Maybe Int
sendVideoNoteVideoNote :: SendVideoNoteRequest -> InputFile
sendVideoNoteMessageThreadId :: SendVideoNoteRequest -> Maybe MessageThreadId
sendVideoNoteChatId :: SendVideoNoteRequest -> 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
sendVideoNoteThumb forall a b. (a -> b) -> a -> b
$
Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"video_note" InputFile
sendVideoNoteVideoNote 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
sendVideoNoteChatId 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
sendVideoNoteMessageThreadId 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 Bool
sendVideoNoteDisableNotification 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
sendVideoNoteProtectContent 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
sendVideoNoteReplyToMessageId 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
sendVideoNoteAllowSendingWithoutReply 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
sendVideoNoteReplyMarkup 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 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
sendVideoNoteThumb SendVideoNoteRequest
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 @SendVideoNoteContent) (ByteString
boundary, SendVideoNoteRequest
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 @SendVideoNoteContent) (ByteString
boundary, SendVideoNoteRequest
r)
(InputFile, Maybe InputFile)
_ -> forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendVideoNoteLink) SendVideoNoteRequest
r