API v2

CL-TELEGRAM-BOT2/ACTION

Classes

ACTION

Functions

function
obj func &rest args

Useful in cl-telegram-bot2/generics:process-state generic-function methods in case if state has additional handler stored in the slot and this slot can be either state or action or a list of actions and states.

This function is recursive, because processing of an action could return another action and we should call FUNC until a new state or NIL will be returned.

CL-TELEGRAM-BOT2/ACTIONS/DELETE-MESSAGES

Classes

DELETE-MESSAGES

Delete all messages created in the current current state.

Readers

Functions

function
&key (sent t) (received t)

CL-TELEGRAM-BOT2/ACTIONS/EDIT-MESSAGE-MEDIA

Classes

EDIT-MESSAGE-MEDIA

Readers

reader
(:caption)
reader
(:inline-keyboard)

Functions

function
path-or-func-name &key caption inline-keyboard

CL-TELEGRAM-BOT2/ACTIONS/SEND-INVOICE

Classes

SEND-INVOICE

Readers

reader
(:commands = nil)
reader
(:currency)
reader
(:description)
reader
(:on-success)
reader
(:payload)
reader
(:prices)
reader
(:provider-token)
reader
(:title)

Functions

function
title description payload provider-token currency prices &key on-success commands

Types

Type of prices arguments for send-invoice class.

(SOFT-LIST-OF HASH-TABLE)

CL-TELEGRAM-BOT2/ACTIONS/SEND-PHOTO

Classes

SEND-PHOTO

Readers

reader
(:caption)
reader
(:inline-keyboard)

Functions

function
path-or-func-name &key caption inline-keyboard

CL-TELEGRAM-BOT2/ACTIONS/SEND-TEXT

Classes

SEND-TEXT

Readers

reader
(:parse-mode = nil)

Supported values are: "Markdown", "MarkdownV2" or "HTML". Read more about formatting options in the Telegram documentaion: https://core.telegram.org/bots/api#formatting-options

reader
(:reply-markup = nil)
reader
(:text)

Functions

function
text-or-func-name &key reply-markup parse-mode

CL-TELEGRAM-BOT2/BOT

Classes

BOT

Readers

reader
(:API-URI = "https://api.telegram.org/")

This slot will be filled with cl-telegram-bot/user:user object on first access using a call to cl-telegram-bot/user:get-me function.

reader
(:debug-mode = nil)

When debug mode is T, then interactive debugger will be called on each error.

reader
(:file-endpoint = nil)

HTTPS file-endpoint

HTTPS endpoint

reader
(:INITIAL-STATE = (REQUIRED-ARGUMENT ":INITIAL-STATE is required argument."))

Command processing code will use this cache to update commands list on the server when a new method for cl-telegram-bot/entities/command:on-command generic-function is defined.

This slot is for internal use.

reader
(:token = nil)

Bot token given by BotFather

Accessors

accessor
(:API-URI = "https://api.telegram.org/")
accessor
(:debug-mode = nil)

When debug mode is T, then interactive debugger will be called on each error.

accessor
(:file-endpoint = nil)

HTTPS file-endpoint

Command processing code will use this cache to update commands list on the server when a new method for cl-telegram-bot/entities/command:on-command generic-function is defined.

This slot is for internal use.

accessor
(:token = nil)

Bot token given by BotFather

Macros

macro
name base-classes &optional slots &rest options

Use this macro to define a class of your Telegram bot.

Each bot has a state machine inside. The simplest bot has only one state:

(defbot test-bot ()
  ()
  (:initial-state
   (state (send-text "Hello world!"))))

This bot will green each who activates it.

To learn more about bot states and actions see States and Actions section.

CL-TELEGRAM-BOT2/CALLBACK

Classes

CALLBACK

Representation of callback handlers to be triggered on given callback data.

Readers

reader
(:HANDLERS = (REQUIRED-ARGUMENT "HANDLERS is required argument for CALLBACK class."))
reader
(:MATCHER = (REQUIRED-ARGUMENT "DATA is required argument for CALLBACK class."))

Functions

function
string-or-matcher handlers

CL-TELEGRAM-BOT2/DEBUG/DIAGRAM

Classes

RENDER-WORKFLOW-DIAGRAM

Functions

CL-TELEGRAM-BOT2/DEBUG/DIAGRAM/GENERICS

Generics

Returns state's slots or groups of slots as a list.

Renders a map item for a given handler.

It should use render-mapslot-value-with-link or render-mapslot-value functions for proper rendering of PlantUML.

Renders a map with a list of handlers for some event.

Returns a name for a state slot for such objects as callbacks or commands.

Renders object as an entity on PlantUML diagram.

CL-TELEGRAM-BOT2/DEBUG/DIAGRAM/GROUP

Classes

GROUP

Readers

Functions

function
name objects

CL-TELEGRAM-BOT2/DEBUG/DIAGRAM/SLOT

Classes

SLOT

Readers

Functions

function
name value

CL-TELEGRAM-BOT2/DEBUG/DIAGRAM/UTILS

Functions

Returns a state with given ID.

Works only during PlantUML diagram rendering.

Returns an alias of obj to be used in PlantUML diagram as a reference.

Call this function after you've finished rendering of the PlantUML object.

Macros

macro
(obj-id) &body body

Executes block of code after the PlantUML entity with obj-id alias has been rendered. Useful for ensuring that both objects are known to the PlantUML renderer when rendering a link between objects.

CL-TELEGRAM-BOT2/ERRORS

Classes

TELEGRAM-ERROR

Readers

reader
(:DESCRIPTION = '(REQUIRED-ARGUMENT "DESCRIPTION is required argument for TELEGRAM-ERROR class."))

CL-TELEGRAM-BOT2/GENERICS

Generics

Pre-checkout-query object will be passed as this single arguement and function should return a boolean. When the function return True, user may proceed to the payment.

Pre-checkout queries are not bound the the chat, so current-chat and current-state are not available during processing. This is why methods of this generic function should be defined on bot class.

You can use CL-TELEGRAM-BOT2/API:PRE-CHECKOUT-QUERY-INVOICE-PAYLOAD function to extract payload from the query and find associated invoice.

This method is called when some state exits and returns a result using cl-telegram-bot2/term/back:back function.

This method is called when chat actor's state is changed to a given STATE.

Such hook can be used to send some prompt to the user.

This method is called when chat actor's state is returned from a given STATE back to the previous state.

The method is called only when state is removed from the stack. When a new state is added to the stack, this method will not be called for a previous state.

Such hook can be used to hide a keyboard or to delete temporary messages.

This method is called by when processing a single update. It is called multiple times on different parts of an update. Whole pipeline looks like that:

For each update we call:

process-update(bot, update)
new_state = process-state(bot, current_state, update)

This generic-function will be called inside an actor.

Default method resposible for extracting the current state from the stack and calling process-state generic-function to get a new state.

CL-TELEGRAM-BOT2/HIGH

High level API for implementing Telegram bots.

Classes

CHAT-STATE

Functions

function
text &rest rest &key business-connection-id message-thread-id parse-mode entities link-preview-options disable-notification protect-content allow-paid-broadcast message-effect-id reply-parameters reply-markup
function
photo &rest rest &key business-connection-id message-thread-id caption parse-mode caption-entities show-caption-above-media has-spoiler disable-notification protect-content allow-paid-broadcast message-effect-id reply-parameters reply-markup

Macros

Returns as the first value a list of messages created by reply function called during BODY execution. Values returned by the BODY code are returned as the second, third and following arguments.

Also, messages are collected when these actions are called:

  • cl-telegram-bot2/actions/send-text:send-text (1 2)

  • cl-telegram-bot2/actions/send-photo:send-photo (1 2)

CL-TELEGRAM-BOT2/HIGH/CALLBACKS

Functions

Extracts callback query data from the UPDATE object.

CL-TELEGRAM-BOT2/HIGH/KEYBOARD

Classes

CALL-CALLBACK

Readers

reader
(:callback-data)

COPY-TEXT

Readers

reader
(:text-to-copy)

OPEN-GAME

OPEN-LOGIN-URL

Readers

reader
(:bot-username = nil)
reader
(:forward-text = nil)
reader
(:login-url)
reader
(:request-write-access = nil)

OPEN-URL

Readers

reader
(:url)

OPEN-WEB-APP

Readers

PAY-BUTTON

REQUEST-CHAT

Readers

reader
(:bot-administration-rights = nil)
reader
(:bot-is-member = nil)
reader
(:chat-has-username = nil)
reader
(:chat-is-channel = nil)
reader
(:chat-is-created = nil)
reader
(:chat-is-forum = nil)
reader
(:request-photo = nil)
reader
(:request-title = nil)
reader
(:request-username = nil)
reader
(:user-administration-rights = nil)
reader
(:REQUEST-ID = (REQUIRED-ARGUMENT "Argument :request-id is required."))

REQUEST-CONTACT

REQUEST-LOCATION

REQUEST-POLL

Readers

reader
(:poll-type = nil)

If "quiz" is passed, the user will be allowed to create only polls in the quiz mode. If "regular" is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.

API: https://core.telegram.org/bots/api#keyboardbuttonpolltype

REQUEST-USERS

Readers

reader
(:max-quantity = 1)
reader
(:request-name = nil)
reader
(:request-photo = nil)
reader
(:request-username = nil)
reader
(:user-is-bot = nil)
reader
(:user-is-premium = nil)
reader
(:REQUEST-ID = (REQUIRED-ARGUMENT "Argument :request-id is required."))

SWITCH-INLINE-QUERY-CHOOSEN-CHAT

Readers

reader
(:allow-bot-chats)
reader
(:allow-channel-chats)
reader
(:allow-group-chats)
reader
(:allow-user-chats)
reader
(:query)

SWITCH-INLINE-QUERY-CURRENT-CHAT

Readers

reader
(:inline-query)

SWITCH-INLINE-QUERY

Readers

reader
(:inline-query)

TEXT-BUTTON

Functions

function
title callback-data
function
button-title text-to-copy

Makes a call-callback (1 2) button from a (title . data) cons.

Returns object of CL-TELEGRAM-BOT2/API:INLINE-KEYBOARD-MARKUP class.

API docs: https://core.telegram.org/bots/api#replykeyboardmarkup

function
buttons &rest rest &key is-persistent resize-keyboard one-time-keyboard input-field-placeholder selective

Returns object of CL-TELEGRAM-BOT2/API:REPLY-KEYBOARD-MARKUP class.

API docs: https://core.telegram.org/bots/api#replykeyboardmarkup

function
button-title
function
button-title login-url &rest rest &key forward-text bot-username request-write-access
function
title web-app-url
function
button-title
function
title request-id &rest rest &key chat-is-channel chat-is-forum chat-has-username chat-is-created user-administration-rights bot-administration-rights bot-is-member request-title request-username request-photo
function
title &rest rest &key poll-type
function
title request-id &rest rest &key user-is-bot user-is-premium max-quantity request-name request-username request-photo
function
title inline-query
function
title &rest rest &key query allow-user-chats allow-bot-chats allow-group-chats allow-channel-chats

CL-TELEGRAM-BOT2/HIGH/PERMISSIONS

Types

API docs: https://core.telegram.org/bots/api#chatadministratorrights

(MEMBER :IS-ANONYMOUS :CAN-MANAGE-CHAT :CAN-DELETE-MESSAGES
        :CAN-MANAGE-VIDEO-CHATS :CAN-RESTRICT-MEMBERS :CAN-PROMOTE-MEMBERS
        :CAN-CHANGE-INFO :CAN-INVITE-USERS :CAN-POST-STORIES :CAN-EDIT-STORIES
        :CAN-DELETE-STORIES :CAN-POST-MESSAGES :CAN-EDIT-MESSAGES
        :CAN-PIN-MESSAGES :CAN-MANAGE-TOPICS)
(SOFT-LIST-OF CHAT-ADMINISTRATION-PERMISSION)

CL-TELEGRAM-BOT2/MATCH

Classes

MATCHER

Generics

Should return T if OBJ match to the matcher. The simples matcher compares two strings.

CL-TELEGRAM-BOT2/MATCHERS/REGEX

Classes

REGEX-MATCHER

Readers

Functions

CL-TELEGRAM-BOT2/MATCHERS/STRING

Classes

STRING-MATCHER

Readers

reader
(:case-insensitive)

Functions

function
string &key case-insensitive

CL-TELEGRAM-BOT2/SENT-MESSAGES

Functions

If some state class processes update and don't call CALL-NEXT-METHOD, then it have to call this function to register received message id.

If you don't do this, then received messages deletion will not work for this state.

Macros

macro
(state-var) &body body

Use this macro to capture messages end during process-state generic-function handling in case if your state inherits from base-state but does not call CALL-NEXT-METHOD.

CL-TELEGRAM-BOT2/SERVER

Functions

function
BOT &KEY DEBUG (DELAY-BETWEEN-RETRIES 10) (THREAD-NAME "telegram-bot")

Start processing new updates from the Telegram API.

Pass bot instance as the first argument and maybe some other optional arguments.

If DEBUG argument is T, then bot will ignore updates which it can't to process without errors. Otherwise, an interactive debugger will popup.

CL-TELEGRAM-BOT2/SPEC

Classes

TELEGRAM-OBJECT

CL-TELEGRAM-BOT2/STATE

Classes

STATE

Readers

reader
(:on-activation = nil)
reader
(:on-callback-query = nil)
reader
(:on-deletion = nil)

Result of these handlers is ignored, but they can be used for side-effects.

Generic-function cl-telegram-bot2/generics:on-state-deletion will be called on these handlers.

reader
(:on-result = nil)
reader
(:on-update = nil)
reader
(:on-web-app-data = nil)

Functions

function
on-activation &key id commands on-update on-deletion on-result on-callback-query on-web-app-data

Validates if argument is valid for passing as :ON-DELETION argument to the state constructor.

It also normalizes an argument and return it as a list of workflow blocks.

Types

Type of ON-CALLBACK-QUERY argument of the state class.

(SOFT-LIST-OF CALLBACK)

CL-TELEGRAM-BOT2/STATE-WITH-COMMANDS

Classes

BASE-COMMAND

Readers

reader
(:description = nil)

A command description like "/start" or "/help".

reader
(:HANDLER = (REQUIRED-ARGUMENT ":HANDLER is required argument."))

An fbound symbol of two arguments (command-argument update-obj) or a workflow object to return from process-state generic-function.

reader
(:NAME = (REQUIRED-ARGUMENT ":COMMAND is required argument."))

A command name like "/start" or "/help".

COMMAND

This type of command is available only in the state where it is defined.

GLOBAL-COMMAND

This command will be available during in all bot states.

STATE-WITH-COMMANDS-MIXIN

Readers

reader
(:commands = nil)

Functions

function
name handler &key description
function
name handler &key description

Types

(OR SYMBOL WORKFLOW-BLOCK WORKFLOW-BLOCKS)

CL-TELEGRAM-BOT2/STATES/ASK-FOR-CHOICE

Classes

ASK-FOR-CHOICE

Readers

reader
(:buttons = nil)
reader
(:delete-messages = t)

Delete message with the keyboard and all warning messages when the choice was made or a new state was added to the stack.

reader
(:delete-wrong-user-messages = t)

Delete usual user messages which he might send by a mistake.

reader
(:on-success = nil)
reader
(:on-wrong-user-message = nil)
reader
(:prompt)
reader
(:to = \*default-var-name\*)

Accessors

Functions

function
PROMPT BUTTONS &KEY (TO \*DEFAULT-VAR-NAME\*) VARS (DELETE-MESSAGES T) (DELETE-WRONG-USER-MESSAGES T) ON-SUCCESS (ON-WRONG-USER-MESSAGE (SEND-TEXT "Please push one of the buttons."))

CL-TELEGRAM-BOT2/STATES/ASK-FOR-NUMBER

Classes

ASK-FOR-NUMBER

Readers

reader
(:on-success = nil)
reader
(:on-validation-error = nil)
reader
(:prompt)
reader
(:to = \*default-var-name\*)

Functions

function
prompt &key (to \*default-var-name\*) on-success on-validation-error on-deletion

CL-TELEGRAM-BOT2/STATES/ASK-FOR-TEXT

Classes

ASK-FOR-TEXT

Readers

reader
(:on-success = nil)
reader
(:on-validation-error = nil)
reader
(:prompt)
reader
(:prompt-keyboard)
reader
(:to = \*default-var-name\*)

Functions

function
prompt &key prompt-keyboard (to \*default-var-name\*) (regex ".\*") on-success on-validation-error on-deletion on-callback-query vars

CL-TELEGRAM-BOT2/STATES/BASE

Classes

BASE-STATE

Readers

reader
(:id = nil)
reader
(:vars = (dict))

Accessors

Generics

Functions

function
var-name

CL-TELEGRAM-BOT2/STATES/WAIT-FOR-PAYMENT

Classes

WAIT-FOR-PAYMENT

Readers

reader
(:on-success = nil)

On success could be an fbound symbol which function returns a list of workflow blocks or a list of workflow blocks.

Functions

function
&key on-success commands

CL-TELEGRAM-BOT2/TERM/BACK

Classes

BACK-TO-ID

Readers

reader
(:ID = (REQUIRED-ARGUMENT "Parent id is required argument."))

BACK-TO-NTH-PARENT

Readers

reader
(:N = (REQUIRED-ARGUMENT "Parent number required argument."))

BACK-TO

Readers

reader
(:STATE-CLASS = (REQUIRED-ARGUMENT "State class is required argument."))

BACK

Readers

reader
(:result = nil)

Functions

function
&optional result
function
state-class &optional result
function
id &optional result
function
n &optional result

CL-TELEGRAM-BOT2/TYPES

Types

(OR CL-TELEGRAM-BOT2/API:REPLY-KEYBOARD-MARKUP
    CL-TELEGRAM-BOT2/API:REPLY-KEYBOARD-REMOVE
    CL-TELEGRAM-BOT2/API:INLINE-KEYBOARD-MARKUP
    CL-TELEGRAM-BOT2/API:FORCE-REPLY)

CL-TELEGRAM-BOT2/UTILS

Generics

Does a general deep-copy on the given object and sub-pieces. Returns atoms, numbers and chars. Runs copy-tree on lists, and copy-seq on other sequences. Runs copy-structure on pathnames, hash tables and other structure-objects

Functions

function
funcallable
function
value &rest args

If value is a fbound SYMBOL, then calls as a function and then returns a result.

If value is a fbound SYMBOL, then calls as a function with given ARG or without it depending on function arity.

function
obj &key indent

Types

This type denotes symbols bound to the functions. Such symbol could be funcalled.

(AND SYMBOL (SATISFIES FBOUNDP))

CL-TELEGRAM-BOT2/VARS

Variables

This variable holds an alist associating special variable symbols to forms to evaluate.

State processing might be done by different threads that is why you might want to keep some context around.

Don't modify this variable, just cons onto it. Preceeding values will take a priority.

CL-TELEGRAM-BOT2/WORKFLOW

Types

(AND SYMBOL (SATISFIES FBOUNDP))
(OR FUNCALLABLE-SYMBOL BASE-STATE ACTION BACK)
(SOFT-LIST-OF WORKFLOW-BLOCK)