Work in progress, there is an application for testing design of this library: https://github.com/iokasimov/elections-bot
This library provides ORM-like toolkit to deal with methods of Telegram Bot API - types and classes were designed in terms of Objects
and their Properties
.
-
Update
: object that webhook consumes, can be either an incomingMessage
,Callback
query orMoving
in/out some group chat. -
Message
: every object containsOrigin
andContent
, can be eitherDirect
,Forwarded
orReplied
. -
Content
: can be eitherCommand
,Text
,File
,Poll
,Contact
,Location
orVenue
. -
File
: Can be eitherAudio
,Document
,Photo
,Video
orVoice
. -
Origin
: indicates where is message from, containsSender
. -
Callback
: this is what webhook consumes on pressing inline keyboard's button. -
Group
: can be eitherBasic
orSuper
, contains chat ID and title. -
Moving
: indicates whichSender
leaved some chat or whichSender
s joined, also containsGroup
. -
Sender
: can be either aBot
or aHuman
. -
Member
: shows the status of a bot or user in group chat, containsSender
.
-
Accessible
: provides lens for objects within other objects. -
Identifiable
: provides identification of objects to use it for requests. -
Persistable
: providespersist
methods that returns you value of some type on success. The "on success" definition is rather vague, for example: if you try to edit object and it remains the same, nothing will returns. Usepersist_
to not decode API answer (because if decoding fails the next applicative or monadic action will not happen).
Forward
: onlyMessage
.Reply
: everything that you canSend
.Send
:Text
,Keyboard
,Audio
,Document
,Video
,Voice
,Photo
,Location
,Live Location
,Poll
.Delete
:Message
.Edit
:Text
,Keyboard
,Live Location
.Stop
:Live Location
,Poll
.
See payload and returning value in Persistable
instances.
Also, you can Forward
, Reply
and Send
objects Silently
.
Also, there are special persistent actions for chat members:
Kick
: kick user from group, user can not return unless unbanned firstRestrict
: change what some member in group can do.Promote
: change what some admin in group can do.
let text = "Just click any button..."
let button1 = Button "Press me!" $ Callback "1"
let button2 = Button "Or press me!" $ Callback "2"
let button3 = Button "No, press me!" $ Callback "3"
let keyboard = Inline [button1, button2, button3]
void . persist . Send chat_id $ text :&: keyboard
webhook (Query _ (Datatext cbq_id _ _ bn)) = do
let text = "The button you pressed is: " <> bn
persist $ Trigger @Notification cbq_id text
webhook (Incoming _ msg) = do
let chat_id = ident $ access @Origin msg
persist (Delete @Message chat_id $ ident msg)