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 token request = runEitherT $ sendMessage_ token request
forwardMessage :: Token -> ForwardMessageRequest -> IO (Either ServantError MessageResponse)
forwardMessage token request = runEitherT $ forwardMessage_ token request
sendPhoto :: Token -> SendPhotoRequest -> IO (Either ServantError MessageResponse)
sendPhoto token request = runEitherT $ sendPhoto_ token request
sendAudio :: Token -> SendAudioRequest -> IO (Either ServantError MessageResponse)
sendAudio token request = runEitherT $ sendAudio_ token request
sendDocument :: Token -> SendDocumentRequest -> IO (Either ServantError MessageResponse)
sendDocument token request = runEitherT $ sendDocument_ token request
sendSticker :: Token -> SendStickerRequest -> IO (Either ServantError MessageResponse)
sendSticker token request = runEitherT $ sendSticker_ token request
sendVideo :: Token -> SendVideoRequest -> IO (Either ServantError MessageResponse)
sendVideo token request = runEitherT $ sendVideo_ token request
sendVoice :: Token -> SendVoiceRequest -> IO (Either ServantError MessageResponse)
sendVoice token request = runEitherT $ sendVoice_ token request
sendLocation :: Token -> SendLocationRequest -> IO (Either ServantError MessageResponse)
sendLocation token request = runEitherT $ sendLocation_ token request
sendChatAction :: Token -> SendChatActionRequest -> IO (Either ServantError ChatActionResponse)
sendChatAction token request = runEitherT $ sendChatAction_ token request
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 token request = runEitherT $ answerInlineQuery_ token request