{-# 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.SendVoice 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 SendVoiceRequest = SendVoiceRequest
{ SendVoiceRequest -> SomeChatId
sendVoiceChatId :: SomeChatId
, SendVoiceRequest -> Maybe MessageThreadId
sendVoiceMessageThreadId :: Maybe MessageThreadId
, SendVoiceRequest -> InputFile
sendVoiceVoice :: InputFile
, SendVoiceRequest -> Maybe Text
sendVoiceCaption :: Maybe Text
, SendVoiceRequest -> Maybe ParseMode
sendVoiceParseMode :: Maybe ParseMode
, SendVoiceRequest -> Maybe [MessageEntity]
sendVoiceCaptionEntities :: Maybe [MessageEntity]
, SendVoiceRequest -> Maybe Int
sendVoiceDuration :: Maybe Int
, SendVoiceRequest -> Maybe Bool
sendVoiceDisableNotification :: Maybe Bool
, SendVoiceRequest -> Maybe Bool
sendVoiceProtectContent :: Maybe Bool
, SendVoiceRequest -> Maybe MessageId
sendVoiceReplyToMessageId :: Maybe MessageId
, SendVoiceRequest -> Maybe Bool
sendVoiceAllowSendingWithoutReply :: Maybe Bool
, SendVoiceRequest -> Maybe InlineKeyboardMarkup
sendVoiceReplyMarkup :: Maybe InlineKeyboardMarkup
}
deriving forall x. Rep SendVoiceRequest x -> SendVoiceRequest
forall x. SendVoiceRequest -> Rep SendVoiceRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendVoiceRequest x -> SendVoiceRequest
$cfrom :: forall x. SendVoiceRequest -> Rep SendVoiceRequest x
Generic
instance ToJSON SendVoiceRequest where toJSON :: SendVoiceRequest -> 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 SendVoiceRequest where
toMultipart :: SendVoiceRequest -> MultipartData Tmp
toMultipart SendVoiceRequest{Maybe Bool
Maybe Int
Maybe [MessageEntity]
Maybe Text
Maybe MessageThreadId
Maybe MessageId
Maybe InlineKeyboardMarkup
Maybe ParseMode
SomeChatId
InputFile
sendVoiceReplyMarkup :: Maybe InlineKeyboardMarkup
sendVoiceAllowSendingWithoutReply :: Maybe Bool
sendVoiceReplyToMessageId :: Maybe MessageId
sendVoiceProtectContent :: Maybe Bool
sendVoiceDisableNotification :: Maybe Bool
sendVoiceDuration :: Maybe Int
sendVoiceCaptionEntities :: Maybe [MessageEntity]
sendVoiceParseMode :: Maybe ParseMode
sendVoiceCaption :: Maybe Text
sendVoiceVoice :: InputFile
sendVoiceMessageThreadId :: Maybe MessageThreadId
sendVoiceChatId :: SomeChatId
sendVoiceReplyMarkup :: SendVoiceRequest -> Maybe InlineKeyboardMarkup
sendVoiceAllowSendingWithoutReply :: SendVoiceRequest -> Maybe Bool
sendVoiceReplyToMessageId :: SendVoiceRequest -> Maybe MessageId
sendVoiceProtectContent :: SendVoiceRequest -> Maybe Bool
sendVoiceDisableNotification :: SendVoiceRequest -> Maybe Bool
sendVoiceDuration :: SendVoiceRequest -> Maybe Int
sendVoiceCaptionEntities :: SendVoiceRequest -> Maybe [MessageEntity]
sendVoiceParseMode :: SendVoiceRequest -> Maybe ParseMode
sendVoiceCaption :: SendVoiceRequest -> Maybe Text
sendVoiceVoice :: SendVoiceRequest -> InputFile
sendVoiceMessageThreadId :: SendVoiceRequest -> Maybe MessageThreadId
sendVoiceChatId :: SendVoiceRequest -> SomeChatId
..} =
Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"voice" InputFile
sendVoiceVoice 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
sendVoiceChatId 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
sendVoiceMessageThreadId 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
sendVoiceCaption forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
\Text
t -> Text -> Text -> Input
Input Text
"caption" Text
t
, Maybe ParseMode
sendVoiceParseMode 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]
sendVoiceCaptionEntities 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 Int
sendVoiceDuration 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 Bool
sendVoiceProtectContent 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 Bool
sendVoiceDisableNotification 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 MessageId
sendVoiceReplyToMessageId 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
sendVoiceAllowSendingWithoutReply 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
sendVoiceReplyMarkup 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 SendVoiceContent
= "sendVoice"
:> MultipartForm Tmp SendVoiceRequest
:> Post '[JSON] (Response Message)
type SendVoiceLink
= "sendVoice"
:> ReqBody '[JSON] SendVoiceRequest
:> Post '[JSON] (Response Message)
sendVoice :: SendVoiceRequest -> ClientM (Response Message)
sendVoice :: SendVoiceRequest -> ClientM (Response Message)
sendVoice SendVoiceRequest
r = case SendVoiceRequest -> InputFile
sendVoiceVoice SendVoiceRequest
r of
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 @SendVoiceContent) (ByteString
boundary, SendVoiceRequest
r)
InputFile
_ -> forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (forall {k} (t :: k). Proxy t
Proxy @SendVoiceLink) SendVoiceRequest
r