module Web.Telegram.API.Bot.API
(
getMe
, sendMessage
, forwardMessage
, sendPhoto
, sendAudio
, sendDocument
, sendSticker
, sendVideo
, sendVoice
, sendLocation
, sendChatAction
, getUpdates
, getFile
, getUserProfilePhotos
, setWebhook
, answerInlineQuery
, TelegramBotAPI
, api
, Token (..)
) where
import Control.Applicative
import Control.Monad.Trans.Either
import Data.Aeson
import Data.Aeson.Types
import Data.Maybe
import Data.Proxy
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics
import GHC.TypeLits
import Servant.API
import Servant.Client
import Web.Telegram.API.Bot.Data
import Web.Telegram.API.Bot.Responses
import Web.Telegram.API.Bot.Requests
newtype Token = Token Text
deriving (Show, Eq, Ord)
instance ToText Token where
toText (Token x) = x
instance FromText Token where
fromText x = Just $ Token x
type TelegramToken = Capture ":token" Token
type TelegramBotAPI =
TelegramToken :> "getMe"
:> Get '[JSON] GetMeResponse
:<|> TelegramToken :> "sendMessage"
:> ReqBody '[JSON] SendMessageRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "forwardMessage"
:> ReqBody '[JSON] ForwardMessageRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendPhoto"
:> ReqBody '[JSON] SendPhotoRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendAudio"
:> ReqBody '[JSON] SendAudioRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendDocument"
:> ReqBody '[JSON] SendDocumentRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendSticker"
:> ReqBody '[JSON] SendStickerRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendVideo"
:> ReqBody '[JSON] SendVideoRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendVoice"
:> ReqBody '[JSON] SendVoiceRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendLocation"
:> ReqBody '[JSON] SendLocationRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "sendChatAction"
:> ReqBody '[JSON] SendChatActionRequest
:> Post '[JSON] ChatActionResponse
:<|> TelegramToken :> "getUpdates"
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> QueryParam "timeout" Int
:> Get '[JSON] UpdatesResponse
:<|> TelegramToken :> "getFile"
:> QueryParam "file_id" Text
:> Get '[JSON] FileResponse
:<|> TelegramToken :> "getUserProfilePhotos"
:> QueryParam "user_id" Int
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> Get '[JSON] UserProfilePhotosResponse
:<|> TelegramToken :> "setWebhook"
:> QueryParam "url" Text
:> Get '[JSON]
SetWebhookResponse
:<|> TelegramToken :> "answerInlineQuery"
:> ReqBody '[JSON] AnswerInlineQueryRequest
:> Post '[JSON] InlineQueryResponse
api :: Proxy TelegramBotAPI
api = Proxy
getMe_ :: Token -> EitherT ServantError IO GetMeResponse
sendMessage_ :: Token -> SendMessageRequest -> EitherT ServantError IO MessageResponse
forwardMessage_ :: Token -> ForwardMessageRequest -> EitherT ServantError IO MessageResponse
sendPhoto_ :: Token -> SendPhotoRequest -> EitherT ServantError IO MessageResponse
sendAudio_ :: Token -> SendAudioRequest -> EitherT ServantError IO MessageResponse
sendDocument_ :: Token -> SendDocumentRequest -> EitherT ServantError IO MessageResponse
sendSticker_ :: Token -> SendStickerRequest -> EitherT ServantError IO MessageResponse
sendVideo_ :: Token -> SendVideoRequest -> EitherT ServantError IO MessageResponse
sendVoice_ :: Token -> SendVoiceRequest -> EitherT ServantError IO MessageResponse
sendLocation_ :: Token -> SendLocationRequest -> EitherT ServantError IO MessageResponse
sendChatAction_ :: Token -> SendChatActionRequest -> EitherT ServantError IO ChatActionResponse
getUpdates_ :: Token -> Maybe Int -> Maybe Int -> Maybe Int -> EitherT ServantError IO UpdatesResponse
getFile_ :: Token -> Maybe Text -> EitherT ServantError IO FileResponse
getUserProfilePhotos_ :: Token -> Maybe Int -> Maybe Int -> Maybe Int -> EitherT ServantError IO UserProfilePhotosResponse
setWebhook_ :: Token -> Maybe Text -> EitherT ServantError IO SetWebhookResponse
answerInlineQuery_ :: Token -> AnswerInlineQueryRequest -> EitherT ServantError IO InlineQueryResponse
getMe_
:<|> sendMessage_
:<|> forwardMessage_
:<|> sendPhoto_
:<|> sendAudio_
:<|> sendDocument_
:<|> sendSticker_
:<|> sendVideo_
:<|> sendVoice_
:<|> sendLocation_
:<|> sendChatAction_
:<|> getUpdates_
:<|> getFile_
:<|> getUserProfilePhotos_
:<|> setWebhook_
:<|> answerInlineQuery_ =
client api
(BaseUrl Https "api.telegram.org" 443)
getMe :: Token -> IO (Either ServantError GetMeResponse)
getMe token = runEitherT $ getMe_ token
sendMessage :: Token -> SendMessageRequest -> IO (Either ServantError MessageResponse)
sendMessage = run sendMessage_
forwardMessage :: Token -> ForwardMessageRequest -> IO (Either ServantError MessageResponse)
forwardMessage = run forwardMessage_
sendPhoto :: Token -> SendPhotoRequest -> IO (Either ServantError MessageResponse)
sendPhoto = run sendPhoto_
sendAudio :: Token -> SendAudioRequest -> IO (Either ServantError MessageResponse)
sendAudio = run sendAudio_
sendDocument :: Token -> SendDocumentRequest -> IO (Either ServantError MessageResponse)
sendDocument = run sendDocument_
sendSticker :: Token -> SendStickerRequest -> IO (Either ServantError MessageResponse)
sendSticker = run sendSticker_
sendVideo :: Token -> SendVideoRequest -> IO (Either ServantError MessageResponse)
sendVideo = run sendVideo_
sendVoice :: Token -> SendVoiceRequest -> IO (Either ServantError MessageResponse)
sendVoice = run sendVoice_
sendLocation :: Token -> SendLocationRequest -> IO (Either ServantError MessageResponse)
sendLocation = run sendLocation_
sendChatAction :: Token -> SendChatActionRequest -> IO (Either ServantError ChatActionResponse)
sendChatAction = run sendChatAction_
getUpdates :: Token -> Maybe Int -> Maybe Int -> Maybe Int -> IO (Either ServantError UpdatesResponse)
getUpdates token offset limit timeout = runEitherT $ getUpdates_ token offset limit timeout
getFile :: Token -> Text -> IO (Either ServantError FileResponse)
getFile token file_id = runEitherT $ getFile_ token $ Just file_id
getUserProfilePhotos :: Token -> Int -> Maybe Int -> Maybe Int -> IO (Either ServantError UserProfilePhotosResponse)
getUserProfilePhotos token user_id offset limit = runEitherT $ getUserProfilePhotos_ token (Just user_id) offset limit
setWebhook :: Token
-> Maybe Text
-> IO (Either ServantError SetWebhookResponse)
setWebhook token url = runEitherT $ setWebhook_ token url
answerInlineQuery :: Token -> AnswerInlineQueryRequest -> IO (Either ServantError InlineQueryResponse)
answerInlineQuery = run answerInlineQuery_
run :: (Token -> a -> EitherT ServantError IO b) -> Token -> a -> IO (Either ServantError b)
run e t r = runEitherT $ e t r