High-level bindings to the Aitu Bot API based on mtl style.
We are support mtl-style way to using Aitu Bot API. Is a based on AituBotClient
which is just ReaderT
monad.
Documentation: https://btsdigital.github.io/bot-api-contract/
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.HTTP.Client
import Network.HTTP.Client.TLS (tlsManagerSettings)
import qualified Data.ByteString.Lazy.Char8 as BC
import Aitu.Bot
main :: IO ()
main = do
let token = "<YOUR_BOT_TOKEN>"
manager <- newManager tlsManagerSettings
response <- runAituBotClient token manager $ do
getMe
case response of
Left (code, errMsg) -> BC.putStrLn errMsg
Right me -> print me
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.HTTP.Client
import Network.HTTP.Client.TLS (tlsManagerSettings)
import qualified Data.ByteString.Lazy.Char8 as BC
import Aitu.Bot
main :: IO ()
main = do
let token = "<YOUR_BOT_TOKEN>"
manager <- newManager tlsManagerSettings
response <- runAituBotClient token manager $ do
uploadFile "cat.png" "images/cat.png"
case response of
Left (code, errMsg) -> BC.putStrLn errMsg
Right me -> print me
Simple Form with Button, that open url by click
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
module FormButton where
import Aitu.Bot
import Aitu.Bot.Types
import Aitu.Bot.Forms
import Aitu.Bot.Commands
import Aitu.Bot.Widgets
import qualified Aitu.Bot.Forms.Content.Content
as C
open :: Peer -> AituBotClient ()
open peer = do
let
form = mkBackdropForm Backdrop
{ formId = "form1"
, header = Header { headerType = TOOLBAR
, title = "FormButton Example"
, options = defaultHeaderOptions
, formAction = Nothing
}
, content = [ C.Content $ Button
"Open ya.ru"
"button_1"
DefaultButton
(FormAction OpenUrlAction
(DataTemplate "http://ya.ru")
)
Nothing
]
, options = Just defaultOptions { fullscreen = Just True }
, bottomBar = Nothing
}
sendForm peer form
see more examples here
Contributions are welcome!
- Fork repository
- Do your changes
- Create pull request
- Wait for CI build and review
You can use stack
to build library
$ stack build
also run tests
Unit Tests
$ stack test
Integration Tests
stack test --test-arguments "--integration -t TOKEN -c CHAT_ID -n BOT_USER_NAME -- HSPEC_ARGS"
or alternative
$ AITU_BOT_TOKEN=TOKEN AITU_CHAT_ID=CHAT_ID make test-integration
where
* TOKEN is a your bot's token
* CHAT_ID your user id for emulate communication between you and bot.
- getMe
- sendMessage
- editMessage
- sendContactMessage
- sendUIState
- forwardMessage
- deteteMessage
- kickFromGroup
- changeGroupTitle
- changeGroupDescription
- changeGroupAvatar
- deleteGroupAvatar
- sendContainerMessage
- editContainerMessage
- retrieveUpdate
- setWebhook
- deleteWebhook
- getWebhookInfo
- uploadMedia
- downloadMedia
- Message
- MessageEdited
- MessageIdAssigned
- MessageForwardMetadata
- QuickButtonSelected
- InlineCommandSelected
- FormSubmitted
- FormMessageSent
- FormClosed
- InvitedToGroup
- KickedFromGroup
- InvitedToChannel
- KickedFromChannel
- NewChannelSubscriber
- ChannelAdminAdded
- ChannelAdminDeleted
- ChannelPermissionsGranted
- ChannelPermissionsRevoked
- Form
- Header
- Options
- FlexOptions
- FormAction
- Indent
- ValidationRule
- Content
- Typed Resource Library
- Applicative Form Builder