{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE LambdaCase #-}

module Telegram.Bot.API.Stickers where

import Control.Monad.IO.Class
import Data.Aeson
#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.Key (fromText)
#endif
import Data.Aeson.Text
import Data.Bool
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Proxy
import GHC.Generics (Generic)
import Servant.API
import Servant.Client hiding (Response)
import Servant.Multipart.API
import Servant.Multipart.Client

import Telegram.Bot.API.Internal.Utils
import Telegram.Bot.API.MakingRequests (Response)
import Telegram.Bot.API.Types
import Data.Maybe (catMaybes, maybeToList)
import Data.Functor


-- | Type of uploaded sticker file. Static or animated.
data StickerType
  = PngSticker -- ^ PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
  | TgsSticker -- ^ TGS animation with the sticker, uploaded using multipart/form-data. See <https:\/\/core.telegram.org\/animated_stickers#technical-requirements> for technical requirements.
  | WebmSticker -- ^ WEBM video with the sticker, uploaded using multipart/form-data. See <https:\/\/core.telegram.org\/stickers#video-sticker-requirements> for technical requirements.

stickerLabel :: StickerType -> T.Text
stickerLabel :: StickerType -> Text
stickerLabel = \case
  StickerType
PngSticker -> Text
"png_sticker"
  StickerType
TgsSticker -> Text
"tgs_sticker"
  StickerType
WebmSticker -> Text
"webm_sticker"

-- | Sticker file with static/animated label.
data StickerFile = StickerFile {StickerFile -> InputFile
stickerFileSticker :: InputFile, StickerFile -> StickerType
stickerFileLabel :: StickerType}

-- | Request parameters for 'sendSticker'.
data SendStickerRequest = SendStickerRequest
  { SendStickerRequest -> SomeChatId
sendStickerChatId                   :: SomeChatId -- ^ Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  , SendStickerRequest -> InputFile
sendStickerSticker                  :: InputFile -- ^ Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP file from the Internet, or upload a new one using multipart/form-data. 
  , SendStickerRequest -> Maybe Bool
sendStickerDisableNotification      :: Maybe Bool -- ^ Sends the message silently. Users will receive a notification with no sound.
  , SendStickerRequest -> Maybe Bool
sendStickerProtectContent           :: Maybe Bool -- ^ Protects the contents of the sent message from forwarding and saving.
  , SendStickerRequest -> Maybe MessageId
sendStickerReplyToMessageId         :: Maybe MessageId -- ^	If the message is a reply, ID of the original message
  , SendStickerRequest -> Maybe Bool
sendStickerAllowSendingWithoutReply :: Maybe Bool -- ^ Pass True, if the message should be sent even if the specified replied-to message is not found
  , SendStickerRequest -> Maybe InlineKeyboardMarkup
sendStickerReplyMarkup              :: Maybe InlineKeyboardMarkup -- ^ Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
  }
  deriving (forall x. SendStickerRequest -> Rep SendStickerRequest x)
-> (forall x. Rep SendStickerRequest x -> SendStickerRequest)
-> Generic SendStickerRequest
forall x. Rep SendStickerRequest x -> SendStickerRequest
forall x. SendStickerRequest -> Rep SendStickerRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendStickerRequest x -> SendStickerRequest
$cfrom :: forall x. SendStickerRequest -> Rep SendStickerRequest x
Generic

instance ToJSON SendStickerRequest where toJSON :: SendStickerRequest -> Value
toJSON = SendStickerRequest -> 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 SendStickerRequest where
  toMultipart :: SendStickerRequest -> MultipartData Tmp
toMultipart SendStickerRequest{Maybe Bool
Maybe InlineKeyboardMarkup
Maybe MessageId
SomeChatId
InputFile
sendStickerReplyMarkup :: Maybe InlineKeyboardMarkup
sendStickerAllowSendingWithoutReply :: Maybe Bool
sendStickerReplyToMessageId :: Maybe MessageId
sendStickerProtectContent :: Maybe Bool
sendStickerDisableNotification :: Maybe Bool
sendStickerSticker :: InputFile
sendStickerChatId :: SomeChatId
sendStickerReplyMarkup :: SendStickerRequest -> Maybe InlineKeyboardMarkup
sendStickerAllowSendingWithoutReply :: SendStickerRequest -> Maybe Bool
sendStickerReplyToMessageId :: SendStickerRequest -> Maybe MessageId
sendStickerProtectContent :: SendStickerRequest -> Maybe Bool
sendStickerDisableNotification :: SendStickerRequest -> Maybe Bool
sendStickerSticker :: SendStickerRequest -> InputFile
sendStickerChatId :: SendStickerRequest -> SomeChatId
..} = 
    Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"sticker" InputFile
sendStickerSticker ([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
sendStickerChatId of
          SomeChatId (ChatId Integer
chat_id) -> String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a. Show a => a -> String
show 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 Bool
sendStickerDisableNotification 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 MessageId
sendStickerReplyToMessageId 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" (Text -> Text
TL.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ MessageId -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText MessageId
t)
      , Maybe Bool
sendStickerAllowSendingWithoutReply 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
"allow_sending_without_reply" (Text -> Text -> Bool -> Text
forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
      , Maybe InlineKeyboardMarkup
sendStickerReplyMarkup 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" (Text -> Text
TL.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ InlineKeyboardMarkup -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText InlineKeyboardMarkup
t)
      ]

type SendStickerContent
  = "sendSticker"
  :> MultipartForm Tmp SendStickerRequest
  :> Post '[JSON] (Response Message)

type SendStickerLink
  = "sendSticker"
  :> ReqBody '[JSON] SendStickerRequest
  :> Post '[JSON] (Response Message)

-- | Use this method to send static .WEBP or animated .TGS stickers. 
--   On success, the sent Message is returned.
sendSticker :: SendStickerRequest -> ClientM (Response Message)
sendSticker :: SendStickerRequest -> ClientM (Response Message)
sendSticker SendStickerRequest
r =
  case SendStickerRequest -> InputFile
sendStickerSticker SendStickerRequest
r of
    InputFile{} -> do
      ByteString
boundary <- IO ByteString -> ClientM ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
      Proxy SendStickerContent
-> (ByteString, SendStickerRequest) -> ClientM (Response Message)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SendStickerContent
forall k (t :: k). Proxy t
Proxy @SendStickerContent) (ByteString
boundary, SendStickerRequest
r)
    InputFile
_ -> Proxy SendStickerLink
-> SendStickerRequest -> ClientM (Response Message)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SendStickerLink
forall k (t :: k). Proxy t
Proxy @SendStickerLink) SendStickerRequest
r


-- | Request parameters for 'uploadStickerFile'.
data UploadStickerFileRequest = UploadStickerFileRequest
  { UploadStickerFileRequest -> UserId
uploadStickerFileUserId :: UserId -- ^ User identifier of sticker file owner
  , UploadStickerFileRequest -> InputFile
uploadStickerFilePngSticker :: InputFile -- ^ PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. 
  } deriving (forall x.
 UploadStickerFileRequest -> Rep UploadStickerFileRequest x)
-> (forall x.
    Rep UploadStickerFileRequest x -> UploadStickerFileRequest)
-> Generic UploadStickerFileRequest
forall x.
Rep UploadStickerFileRequest x -> UploadStickerFileRequest
forall x.
UploadStickerFileRequest -> Rep UploadStickerFileRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UploadStickerFileRequest x -> UploadStickerFileRequest
$cfrom :: forall x.
UploadStickerFileRequest -> Rep UploadStickerFileRequest x
Generic

instance ToJSON UploadStickerFileRequest where toJSON :: UploadStickerFileRequest -> Value
toJSON = UploadStickerFileRequest -> 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 UploadStickerFileRequest where
  toMultipart :: UploadStickerFileRequest -> MultipartData Tmp
toMultipart UploadStickerFileRequest{InputFile
UserId
uploadStickerFilePngSticker :: InputFile
uploadStickerFileUserId :: UserId
uploadStickerFilePngSticker :: UploadStickerFileRequest -> InputFile
uploadStickerFileUserId :: UploadStickerFileRequest -> UserId
..} = 
    Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"png_sticker" InputFile
uploadStickerFilePngSticker ([Input] -> [FileData Tmp] -> MultipartData Tmp
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields []) where
    fields :: [Input]
fields = [ Text -> Text -> Input
Input Text
"user_id" (Text -> Input) -> Text -> Input
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> (UserId -> String) -> UserId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserId -> String
forall a. Show a => a -> String
show (UserId -> Text) -> UserId -> Text
forall a b. (a -> b) -> a -> b
$ UserId
uploadStickerFileUserId ]

type UploadStickerFileContent
  = "uploadStickerFile"
  :> MultipartForm Tmp UploadStickerFileRequest
  :> Post '[JSON] (Response File)

type UploadStickerFileLink
  = "uploadStickerFile"
  :> ReqBody '[JSON] UploadStickerFileRequest
  :> Post '[JSON] (Response File)

-- | Use this method to upload a .PNG file 
--   with a sticker for later use in createNewStickerSet 
--   and addStickerToSet methods (can be used multiple times). 
--   Returns the uploaded File on success.
uploadStickerFile :: UploadStickerFileRequest -> ClientM (Response File)
uploadStickerFile :: UploadStickerFileRequest -> ClientM (Response File)
uploadStickerFile UploadStickerFileRequest
r =
  case UploadStickerFileRequest -> InputFile
uploadStickerFilePngSticker UploadStickerFileRequest
r of
    InputFile{} -> do
      ByteString
boundary <- IO ByteString -> ClientM ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
      Proxy UploadStickerFileContent
-> (ByteString, UploadStickerFileRequest)
-> ClientM (Response File)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy UploadStickerFileContent
forall k (t :: k). Proxy t
Proxy @UploadStickerFileContent) (ByteString
boundary, UploadStickerFileRequest
r)
    InputFile
_ -> Proxy UploadStickerFileLink
-> UploadStickerFileRequest -> ClientM (Response File)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy UploadStickerFileLink
forall k (t :: k). Proxy t
Proxy @UploadStickerFileLink) UploadStickerFileRequest
r


-- | Request parameters for 'createNewStickerSet'.
data CreateNewStickerSetRequest = CreateNewStickerSetRequest
  { CreateNewStickerSetRequest -> UserId
createNewStickerSetUserId :: UserId -- ^ User identifier of created sticker set owner
  , CreateNewStickerSetRequest -> Text
createNewStickerSetName :: T.Text -- ^ Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
  , CreateNewStickerSetRequest -> Text
createNewStickerSetTitle :: T.Text -- ^ Sticker set title, 1-64 characters
  , CreateNewStickerSetRequest -> StickerFile
createNewStickerSetSticker :: StickerFile -- ^ Sticker file to upload
  , CreateNewStickerSetRequest -> Text
createNewStickerSetEmojis :: T.Text -- ^ One or more emoji corresponding to the sticker
  , CreateNewStickerSetRequest -> Maybe Bool
createNewStickerSetContainsMasks :: Maybe Bool -- ^ Pass True, if a set of mask stickers should be created
  , CreateNewStickerSetRequest -> Maybe MaskPosition
createNewStickerSetMaskPosition :: Maybe MaskPosition -- ^ A JSON-serialized object for position where the mask should be placed on faces
  } deriving (forall x.
 CreateNewStickerSetRequest -> Rep CreateNewStickerSetRequest x)
-> (forall x.
    Rep CreateNewStickerSetRequest x -> CreateNewStickerSetRequest)
-> Generic CreateNewStickerSetRequest
forall x.
Rep CreateNewStickerSetRequest x -> CreateNewStickerSetRequest
forall x.
CreateNewStickerSetRequest -> Rep CreateNewStickerSetRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateNewStickerSetRequest x -> CreateNewStickerSetRequest
$cfrom :: forall x.
CreateNewStickerSetRequest -> Rep CreateNewStickerSetRequest x
Generic

instance ToJSON CreateNewStickerSetRequest where 
  toJSON :: CreateNewStickerSetRequest -> Value
toJSON CreateNewStickerSetRequest{Maybe Bool
Maybe MaskPosition
Text
UserId
StickerFile
createNewStickerSetMaskPosition :: Maybe MaskPosition
createNewStickerSetContainsMasks :: Maybe Bool
createNewStickerSetEmojis :: Text
createNewStickerSetSticker :: StickerFile
createNewStickerSetTitle :: Text
createNewStickerSetName :: Text
createNewStickerSetUserId :: UserId
createNewStickerSetMaskPosition :: CreateNewStickerSetRequest -> Maybe MaskPosition
createNewStickerSetContainsMasks :: CreateNewStickerSetRequest -> Maybe Bool
createNewStickerSetEmojis :: CreateNewStickerSetRequest -> Text
createNewStickerSetSticker :: CreateNewStickerSetRequest -> StickerFile
createNewStickerSetTitle :: CreateNewStickerSetRequest -> Text
createNewStickerSetName :: CreateNewStickerSetRequest -> Text
createNewStickerSetUserId :: CreateNewStickerSetRequest -> UserId
..} = [Pair] -> Value
object
    [ Key
"user_id" Key -> UserId -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UserId
createNewStickerSetUserId
    , Key
"name" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
createNewStickerSetName
    , Key
"title" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
createNewStickerSetTitle
#if MIN_VERSION_aeson(2,0,0)
    , Text -> Key
fromText (StickerType -> Text
stickerLabel StickerType
stickerFileLabel) Key -> InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= InputFile
stickerFileSticker
#else
    , stickerLabel stickerFileLabel .= stickerFileSticker
#endif
    , Key
"emojis" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
createNewStickerSetEmojis
    , Key
"contains_mask" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Bool
createNewStickerSetContainsMasks
    , Key
"mask_position" Key -> Maybe MaskPosition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaskPosition
createNewStickerSetMaskPosition
    ]
    where
      StickerFile{InputFile
StickerType
stickerFileSticker :: InputFile
stickerFileLabel :: StickerType
stickerFileLabel :: StickerFile -> StickerType
stickerFileSticker :: StickerFile -> InputFile
..} = StickerFile
createNewStickerSetSticker

instance ToMultipart Tmp CreateNewStickerSetRequest where
  toMultipart :: CreateNewStickerSetRequest -> MultipartData Tmp
toMultipart CreateNewStickerSetRequest{Maybe Bool
Maybe MaskPosition
Text
UserId
StickerFile
createNewStickerSetMaskPosition :: Maybe MaskPosition
createNewStickerSetContainsMasks :: Maybe Bool
createNewStickerSetEmojis :: Text
createNewStickerSetSticker :: StickerFile
createNewStickerSetTitle :: Text
createNewStickerSetName :: Text
createNewStickerSetUserId :: UserId
createNewStickerSetMaskPosition :: CreateNewStickerSetRequest -> Maybe MaskPosition
createNewStickerSetContainsMasks :: CreateNewStickerSetRequest -> Maybe Bool
createNewStickerSetEmojis :: CreateNewStickerSetRequest -> Text
createNewStickerSetSticker :: CreateNewStickerSetRequest -> StickerFile
createNewStickerSetTitle :: CreateNewStickerSetRequest -> Text
createNewStickerSetName :: CreateNewStickerSetRequest -> Text
createNewStickerSetUserId :: CreateNewStickerSetRequest -> UserId
..} = 
    Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile (StickerType -> Text
stickerLabel StickerType
stickerFileLabel) InputFile
stickerFileSticker ([Input] -> [FileData Tmp] -> MultipartData Tmp
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields []) where
    fields :: [Input]
fields =
      [ Text -> Text -> Input
Input Text
"user_id" (Text -> Input) -> Text -> Input
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> (UserId -> String) -> UserId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserId -> String
forall a. Show a => a -> String
show (UserId -> Text) -> UserId -> Text
forall a b. (a -> b) -> a -> b
$ UserId
createNewStickerSetUserId
      , Text -> Text -> Input
Input Text
"name" Text
createNewStickerSetName
      , Text -> Text -> Input
Input Text
"title" Text
createNewStickerSetTitle
      , Text -> Text -> Input
Input Text
"emojis" Text
createNewStickerSetEmojis
      ] [Input] -> [Input] -> [Input]
forall a. Semigroup a => a -> a -> a
<> [Maybe Input] -> [Input]
forall a. [Maybe a] -> [a]
catMaybes
      [ Maybe Bool
createNewStickerSetContainsMasks 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
"contains_masks" (Text -> Text -> Bool -> Text
forall a. a -> a -> Bool -> a
bool Text
"false" Text
"true" Bool
t)
      , Maybe MaskPosition
createNewStickerSetMaskPosition Maybe MaskPosition -> (MaskPosition -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
        \MaskPosition
t -> Text -> Text -> Input
Input Text
"mask_position" (Text -> Text
TL.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ MaskPosition -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText MaskPosition
t)
      ]
    StickerFile {InputFile
StickerType
stickerFileSticker :: InputFile
stickerFileLabel :: StickerType
stickerFileLabel :: StickerFile -> StickerType
stickerFileSticker :: StickerFile -> InputFile
..} = StickerFile
createNewStickerSetSticker

type CreateNewStickerSetContent
  = "createNewStickerSet"
  :> MultipartForm Tmp CreateNewStickerSetRequest
  :> Post '[JSON] (Response Bool)

type CreateNewStickerSetLink
  = "createNewStickerSet"
  :> ReqBody '[JSON] CreateNewStickerSetRequest
  :> Post '[JSON] (Response Bool)

-- | Use this method to create a new sticker 
--   set owned by a user. The bot will be able 
--   to edit the sticker set thus created. You 
--   must use exactly one of the fields png_sticker or tgs_sticker. 
--   Returns True on success.
createNewStickerSet :: CreateNewStickerSetRequest -> ClientM (Response Bool)
createNewStickerSet :: CreateNewStickerSetRequest -> ClientM (Response Bool)
createNewStickerSet CreateNewStickerSetRequest
r =
  case StickerFile -> InputFile
stickerFileSticker (StickerFile -> InputFile) -> StickerFile -> InputFile
forall a b. (a -> b) -> a -> b
$ CreateNewStickerSetRequest -> StickerFile
createNewStickerSetSticker CreateNewStickerSetRequest
r of
    InputFile{} -> do
      ByteString
boundary <- IO ByteString -> ClientM ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
      Proxy CreateNewStickerSetContent
-> (ByteString, CreateNewStickerSetRequest)
-> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy CreateNewStickerSetContent
forall k (t :: k). Proxy t
Proxy @CreateNewStickerSetContent) (ByteString
boundary, CreateNewStickerSetRequest
r)
    InputFile
_ -> Proxy CreateNewStickerSetLink
-> CreateNewStickerSetRequest -> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy CreateNewStickerSetLink
forall k (t :: k). Proxy t
Proxy @CreateNewStickerSetLink) CreateNewStickerSetRequest
r

-- | Request parameters for 'addStickerToSet'.
data AddStickerToSetRequest = AddStickerToSetRequest
  { AddStickerToSetRequest -> UserId
addStickerToSetUserId :: UserId -- ^ User identifier of sticker set owner
  , AddStickerToSetRequest -> Text
addStickerToSetName :: T.Text -- ^ Sticker set name
  , AddStickerToSetRequest -> StickerFile
addStickerToSetSticker :: StickerFile -- ^ Sticker file to upload 
  , AddStickerToSetRequest -> Text
addStickerToSetEmojis :: T.Text -- ^ One or more emoji corresponding to the sticker
  , AddStickerToSetRequest -> Maybe MaskPosition
addStickerToSetMaskPosition :: Maybe MaskPosition -- ^ A JSON-serialized object for position where the mask should be placed on faces
  } deriving (forall x. AddStickerToSetRequest -> Rep AddStickerToSetRequest x)
-> (forall x.
    Rep AddStickerToSetRequest x -> AddStickerToSetRequest)
-> Generic AddStickerToSetRequest
forall x. Rep AddStickerToSetRequest x -> AddStickerToSetRequest
forall x. AddStickerToSetRequest -> Rep AddStickerToSetRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddStickerToSetRequest x -> AddStickerToSetRequest
$cfrom :: forall x. AddStickerToSetRequest -> Rep AddStickerToSetRequest x
Generic

instance ToJSON AddStickerToSetRequest where
  toJSON :: AddStickerToSetRequest -> Value
toJSON AddStickerToSetRequest{Maybe MaskPosition
Text
UserId
StickerFile
addStickerToSetMaskPosition :: Maybe MaskPosition
addStickerToSetEmojis :: Text
addStickerToSetSticker :: StickerFile
addStickerToSetName :: Text
addStickerToSetUserId :: UserId
addStickerToSetMaskPosition :: AddStickerToSetRequest -> Maybe MaskPosition
addStickerToSetEmojis :: AddStickerToSetRequest -> Text
addStickerToSetSticker :: AddStickerToSetRequest -> StickerFile
addStickerToSetName :: AddStickerToSetRequest -> Text
addStickerToSetUserId :: AddStickerToSetRequest -> UserId
..} = [Pair] -> Value
object
    [ Key
"user_id" Key -> UserId -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UserId
addStickerToSetUserId
    , Key
"name" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
addStickerToSetName
#if MIN_VERSION_aeson(2,0,0)
    , Text -> Key
fromText (StickerType -> Text
stickerLabel StickerType
stickerFileLabel) Key -> InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= InputFile
stickerFileSticker
#else
    , stickerLabel stickerFileLabel .= stickerFileSticker
#endif
    , Key
"emojis" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
addStickerToSetEmojis
    , Key
"mask_position" Key -> Maybe MaskPosition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe MaskPosition
addStickerToSetMaskPosition
    ]
    where
      StickerFile{InputFile
StickerType
stickerFileSticker :: InputFile
stickerFileLabel :: StickerType
stickerFileLabel :: StickerFile -> StickerType
stickerFileSticker :: StickerFile -> InputFile
..} = StickerFile
addStickerToSetSticker

instance ToMultipart Tmp AddStickerToSetRequest where
  toMultipart :: AddStickerToSetRequest -> MultipartData Tmp
toMultipart AddStickerToSetRequest{Maybe MaskPosition
Text
UserId
StickerFile
addStickerToSetMaskPosition :: Maybe MaskPosition
addStickerToSetEmojis :: Text
addStickerToSetSticker :: StickerFile
addStickerToSetName :: Text
addStickerToSetUserId :: UserId
addStickerToSetMaskPosition :: AddStickerToSetRequest -> Maybe MaskPosition
addStickerToSetEmojis :: AddStickerToSetRequest -> Text
addStickerToSetSticker :: AddStickerToSetRequest -> StickerFile
addStickerToSetName :: AddStickerToSetRequest -> Text
addStickerToSetUserId :: AddStickerToSetRequest -> UserId
..} = 
    Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile (StickerType -> Text
stickerLabel StickerType
stickerFileLabel) InputFile
stickerFileSticker ([Input] -> [FileData Tmp] -> MultipartData Tmp
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields []) where
    fields :: [Input]
fields =
      [ Text -> Text -> Input
Input Text
"user_id" (Text -> Input) -> Text -> Input
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> (UserId -> String) -> UserId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserId -> String
forall a. Show a => a -> String
show (UserId -> Text) -> UserId -> Text
forall a b. (a -> b) -> a -> b
$ UserId
addStickerToSetUserId
      , Text -> Text -> Input
Input Text
"name" Text
addStickerToSetName
      , Text -> Text -> Input
Input Text
"emojis" Text
addStickerToSetEmojis
      ] [Input] -> [Input] -> [Input]
forall a. Semigroup a => a -> a -> a
<> Maybe Input -> [Input]
forall a. Maybe a -> [a]
maybeToList
      ( Maybe MaskPosition
addStickerToSetMaskPosition Maybe MaskPosition -> (MaskPosition -> Input) -> Maybe Input
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&>
        \MaskPosition
t -> Text -> Text -> Input
Input Text
"mask_position" (Text -> Text
TL.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ MaskPosition -> Text
forall a. ToJSON a => a -> Text
encodeToLazyText MaskPosition
t)
      )
    StickerFile {InputFile
StickerType
stickerFileSticker :: InputFile
stickerFileLabel :: StickerType
stickerFileLabel :: StickerFile -> StickerType
stickerFileSticker :: StickerFile -> InputFile
..} = StickerFile
addStickerToSetSticker

type AddStickerToSetContent
  = "addStickerToSet"
  :> MultipartForm Tmp AddStickerToSetRequest
  :> Post '[JSON] (Response Bool)

type AddStickerToSetLink
  = "addStickerToSet"
  :> ReqBody '[JSON] AddStickerToSetRequest
  :> Post '[JSON] (Response Bool)

-- | Use this method to add a new sticker to a set 
--   created by the bot. You must use exactly one of 
--   the fields png_sticker or tgs_sticker. Animated 
--   stickers can be added to animated sticker sets and 
--   only to them. Animated sticker sets can have up to 50 
--   stickers. Static sticker sets can have up to 120 stickers. 
--   Returns True on success.
addStickerToSet :: AddStickerToSetRequest -> ClientM (Response Bool)
addStickerToSet :: AddStickerToSetRequest -> ClientM (Response Bool)
addStickerToSet AddStickerToSetRequest
r =
  case StickerFile -> InputFile
stickerFileSticker (StickerFile -> InputFile) -> StickerFile -> InputFile
forall a b. (a -> b) -> a -> b
$ AddStickerToSetRequest -> StickerFile
addStickerToSetSticker AddStickerToSetRequest
r of
    InputFile{} -> do
      ByteString
boundary <- IO ByteString -> ClientM ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
      Proxy AddStickerToSetContent
-> (ByteString, AddStickerToSetRequest) -> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy AddStickerToSetContent
forall k (t :: k). Proxy t
Proxy @AddStickerToSetContent) (ByteString
boundary, AddStickerToSetRequest
r)
    InputFile
_ -> Proxy AddStickerToSetLink
-> AddStickerToSetRequest -> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy AddStickerToSetLink
forall k (t :: k). Proxy t
Proxy @AddStickerToSetLink) AddStickerToSetRequest
r


type GetStickerSet
  = "getStickerSet"
  :> RequiredQueryParam "name" T.Text
  :> Get '[JSON] (Response StickerSet)

-- | Use this method to get a sticker set. On success, a StickerSet object is returned.
getStickerSet :: T.Text -- ^ Name of the sticker set
  -> ClientM (Response StickerSet)
getStickerSet :: Text -> ClientM (Response StickerSet)
getStickerSet = Proxy GetStickerSet -> Client ClientM GetStickerSet
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy GetStickerSet
forall k (t :: k). Proxy t
Proxy @GetStickerSet)

type SetStickerPositionInSet
  = "setStickerPositionInSet"
  :> RequiredQueryParam "sticker" T.Text
  :> RequiredQueryParam "position" Integer
  :> Post '[JSON] (Response Bool)

-- | Use this method to move a sticker in a set created by the bot to a specific position. 
--   Returns True on success.
setStickerPositionInSet :: T.Text -- ^ File identifier of the sticker
  -> Integer -- ^ New sticker position in the set, zero-based
  -> ClientM (Response Bool)
setStickerPositionInSet :: Text -> Integer -> ClientM (Response Bool)
setStickerPositionInSet = Proxy SetStickerPositionInSet
-> Client ClientM SetStickerPositionInSet
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SetStickerPositionInSet
forall k (t :: k). Proxy t
Proxy @SetStickerPositionInSet)


type DeleteStickerFromSet
  = "deleteStickerFromSet"
  :> RequiredQueryParam "sticker" T.Text
  :> Post '[JSON] (Response Bool)

-- | Use this method to delete a sticker from a set created by the bot. 
--   Returns True on success.
deleteStickerFromSet :: T.Text -- ^ File identifier of the sticker
  -> ClientM (Response Bool)
deleteStickerFromSet :: Text -> ClientM (Response Bool)
deleteStickerFromSet = Proxy DeleteStickerFromSet -> Client ClientM DeleteStickerFromSet
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy DeleteStickerFromSet
forall k (t :: k). Proxy t
Proxy @DeleteStickerFromSet)

-- | Request parameters for 'setStickerSetThumb'.
data SetStickerSetThumbRequest = SetStickerSetThumbRequest
  { SetStickerSetThumbRequest -> Text
setStickerSetThumbName :: T.Text -- ^ Sticker set name
  , SetStickerSetThumbRequest -> UserId
setStickerSetThumbUserId :: UserId -- ^ User identifier of the sticker set owner
  , SetStickerSetThumbRequest -> InputFile
setStickerSetThumbThumb :: InputFile -- ^ A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see <https:\/\/core.telegram.org\/animated_stickers#technical-requirements> for animated sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated sticker set thumbnail can't be uploaded via HTTP URL.
  } deriving (forall x.
 SetStickerSetThumbRequest -> Rep SetStickerSetThumbRequest x)
-> (forall x.
    Rep SetStickerSetThumbRequest x -> SetStickerSetThumbRequest)
-> Generic SetStickerSetThumbRequest
forall x.
Rep SetStickerSetThumbRequest x -> SetStickerSetThumbRequest
forall x.
SetStickerSetThumbRequest -> Rep SetStickerSetThumbRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SetStickerSetThumbRequest x -> SetStickerSetThumbRequest
$cfrom :: forall x.
SetStickerSetThumbRequest -> Rep SetStickerSetThumbRequest x
Generic

instance ToJSON SetStickerSetThumbRequest where toJSON :: SetStickerSetThumbRequest -> Value
toJSON = SetStickerSetThumbRequest -> 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 SetStickerSetThumbRequest where
  toMultipart :: SetStickerSetThumbRequest -> MultipartData Tmp
toMultipart SetStickerSetThumbRequest{Text
InputFile
UserId
setStickerSetThumbThumb :: InputFile
setStickerSetThumbUserId :: UserId
setStickerSetThumbName :: Text
setStickerSetThumbThumb :: SetStickerSetThumbRequest -> InputFile
setStickerSetThumbUserId :: SetStickerSetThumbRequest -> UserId
setStickerSetThumbName :: SetStickerSetThumbRequest -> Text
..} = 
    Text -> InputFile -> MultipartData Tmp -> MultipartData Tmp
makeFile Text
"png_sticker" InputFile
setStickerSetThumbThumb ([Input] -> [FileData Tmp] -> MultipartData Tmp
forall tag. [Input] -> [FileData tag] -> MultipartData tag
MultipartData [Input]
fields []) where
    fields :: [Input]
fields =
      [ Text -> Text -> Input
Input Text
"user_id" (Text -> Input) -> Text -> Input
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> (UserId -> String) -> UserId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UserId -> String
forall a. Show a => a -> String
show (UserId -> Text) -> UserId -> Text
forall a b. (a -> b) -> a -> b
$ UserId
setStickerSetThumbUserId
      , Text -> Text -> Input
Input Text
"name" Text
setStickerSetThumbName
      ]

type SetStickerSetThumbContent
  = "setStickerSetThumb"
  :> MultipartForm Tmp SetStickerSetThumbRequest
  :> Post '[JSON] (Response Bool)

type SetStickerSetThumbLink
  = "setStickerSetThumb"
  :> ReqBody '[JSON] SetStickerSetThumbRequest
  :> Post '[JSON] (Response Bool)

-- | Use this method to set the thumbnail of a sticker set. 
--   Animated thumbnails can be set for animated sticker sets only. 
--   Returns True on success.
setStickerSetThumb :: SetStickerSetThumbRequest -> ClientM (Response Bool)
setStickerSetThumb :: SetStickerSetThumbRequest -> ClientM (Response Bool)
setStickerSetThumb SetStickerSetThumbRequest
r =
  case SetStickerSetThumbRequest -> InputFile
setStickerSetThumbThumb SetStickerSetThumbRequest
r of
    InputFile{} -> do
      ByteString
boundary <- IO ByteString -> ClientM ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
genBoundary
      Proxy SetStickerSetThumbContent
-> (ByteString, SetStickerSetThumbRequest)
-> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SetStickerSetThumbContent
forall k (t :: k). Proxy t
Proxy @SetStickerSetThumbContent) (ByteString
boundary, SetStickerSetThumbRequest
r)
    InputFile
_ -> Proxy SetStickerSetThumbLink
-> SetStickerSetThumbRequest -> ClientM (Response Bool)
forall api.
HasClient ClientM api =>
Proxy api -> Client ClientM api
client (Proxy SetStickerSetThumbLink
forall k (t :: k). Proxy t
Proxy @SetStickerSetThumbLink) SetStickerSetThumbRequest
r