module Web.Telegram.API.Bot.API.Updates
(
getUpdates
, getUpdatesM
, getUpdatesM'
, setWebhook
, setWebhookM
, setWebhookWithCertificate
, setWebhookWithCertificateM
, deleteWebhook
, deleteWebhookM
, getWebhookInfo
, getWebhookInfoM
, TelegramBotUpdatesAPI
, updatesApi
) where
import Data.Maybe
import Data.Proxy
import Data.Text (Text, empty)
import Network.HTTP.Client (Manager)
import Servant.API
import Servant.Client
import Servant.Client.MultipartFormData
import Web.Telegram.API.Bot.API.Core
import Web.Telegram.API.Bot.Requests
import Web.Telegram.API.Bot.Responses
type TelegramBotUpdatesAPI =
TelegramToken :> "getUpdates"
:> ReqBody '[JSON] GetUpdatesRequest
:> Get '[JSON] UpdatesResponse
:<|> TelegramToken :> "setWebhook"
:> ReqBody '[JSON] SetWebhookRequest
:> Get '[JSON] SetWebhookResponse
:<|> TelegramToken :> "setWebhook"
:> MultipartFormDataReqBody SetWebhookRequest
:> Post '[JSON] SetWebhookResponse
:<|> TelegramToken :> "deleteWebhook"
:> Post '[JSON] (Response Bool)
:<|> TelegramToken :> "getWebhookInfo"
:> Get '[JSON] GetWebhookInfoResponse
updatesApi :: Proxy TelegramBotUpdatesAPI
updatesApi = Proxy
getUpdates_ :: Token -> GetUpdatesRequest -> ClientM UpdatesResponse
setWebhook_ :: Token -> SetWebhookRequest -> ClientM SetWebhookResponse
setWebhookWithCert_ :: Token -> SetWebhookRequest -> ClientM SetWebhookResponse
deleteWebhook_ :: Token -> ClientM (Response Bool)
getWebhookInfo_ :: Token -> ClientM GetWebhookInfoResponse
getUpdates_
:<|> setWebhook_
:<|> setWebhookWithCert_
:<|> deleteWebhook_
:<|> getWebhookInfo_ = client updatesApi
getUpdates
:: Token
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Manager
-> IO (Either ServantError UpdatesResponse)
getUpdates token offset limit timeout = runClient (getUpdatesM request) token
where request = GetUpdatesRequest offset limit timeout Nothing
getUpdatesM' :: TelegramClient UpdatesResponse
getUpdatesM' = getUpdatesM getUpdatesRequest
getUpdatesM :: GetUpdatesRequest -> TelegramClient UpdatesResponse
getUpdatesM = run_ getUpdates_
setWebhook :: Token
-> Maybe Text
-> Manager
-> IO (Either ServantError SetWebhookResponse)
setWebhook token url = runClient (setWebhookM request) token
where request = setWebhookRequest' $ fromMaybe empty url
setWebhookM :: SetWebhookRequest -> TelegramClient SetWebhookResponse
setWebhookM = run_ setWebhook_
setWebhookWithCertificate :: Token -> SetWebhookRequest -> Manager -> IO (Either ServantError SetWebhookResponse)
setWebhookWithCertificate = runM setWebhookWithCertificateM
setWebhookWithCertificateM :: SetWebhookRequest -> TelegramClient SetWebhookResponse
setWebhookWithCertificateM = run_ setWebhookWithCert_
deleteWebhook :: Token -> Manager -> IO (Either ServantError (Response Bool))
deleteWebhook = runClient deleteWebhookM
deleteWebhookM :: TelegramClient (Response Bool)
deleteWebhookM = asking deleteWebhook_
getWebhookInfo :: Token -> Manager -> IO (Either ServantError GetWebhookInfoResponse)
getWebhookInfo = runClient getWebhookInfoM
getWebhookInfoM :: TelegramClient GetWebhookInfoResponse
getWebhookInfoM = asking getWebhookInfo_