\ClapTrapBot
CL4P-TP implementation
Synopsis
class ClapTrapBot
extends WolfDispatcher
{
- // constants
- const TABLE_AUTH = 'ct_auth';
- const KEY_AUTH_TMP = 'CT_AUTH_TMP';
- const KEY_CONTEXT = 'CT_CONTEXT';
- const KEY_THROTTLE = 'CT_THROTTLE';
- const OPTION_PKBD_COUNT = 'CLAPTRAPBOT_PKBD_ROW';
- const OPTION_FEATURES = 'CLAPTRAPBOT_FEATURES';
- const OPTION_SYSTEM_CURRENCY = 'TEMPLATE_CURRENCY';
- const OPTION_THROTTLE_LIMIT = 'CLAPTRAPBOT_THROTTLE_LIMIT';
- const OPTION_THROTTLE_BAN_TIME = 'CLAPTRAPBOT_THROTTLE_BAN_TIME';
- const OPTION_PAY_LIMIT = 'CLAPTRAPBOT_MY_PAYMENTS_LIMIT';
- const OPTION_TAG_ID = 'CLAPTRAPBOT_USERS_TAGID';
- const OPTION_TOKEN = 'CLAPTRAPBOT_TOKEN';
- const OPTION_AUTH_STRING = 'CLAPTRAPBOT_AUTH_STRING';
- const OPTION_HOOK_URL = 'CLAPTRAPBOT_HOOK_URL';
- const OPTION_HELPDESK = 'CLAPTRAPBOT_HELPDESK_INTEGRATION';
- const PROUTE_VALIDATE = 'ctbvalidator';
- const VALIDATION_RESULT = 'HA! I was MADE to open doors!';
- // Inherited constants from WolfDispatcher
- const LOG_PATH = 'exports/';
- const HOOK_PID_PATH = 'exports/';
- // members
- protected array $altCfg = ;
- protected bool $loggedIn = false;
- protected string $myLogin = '';
- protected string $myPassword = '';
- protected string $chatId = '';
- protected string $apiUrl = '';
- protected $authDb = '';
- protected $cache = '';
- protected integer $cacheTimeout = 3600;
- protected array $icons = ;
- protected string $context = '';
- protected integer $primaryKbdInRow = 2;
- protected array $featuresEnabled = ;
- protected array $featuresAvailable = ;
- protected array $primaryKbdLoggedIn = ;
- protected array $primaryKbdLoggedOut = ;
- protected array $commandsEnabled = ;
- protected bool $loginActionCalled = false;
- protected string $systemCurrency = '';
- protected integer $throttleLimit = 0;
- protected integer $throttleBanTime = 0;
- protected integer $myPaymentsLimit = 4;
- protected integer $ticketTextLimit = 1000;
- protected integer $userTagId = 0;
- protected integer $helpdeskIntegrationFlag = 0;
- // Inherited members from WolfDispatcher
- protected string $botToken;
- protected array $commands;
- protected array $groupChatCommands;
- protected array $adminCommands;
- protected array $textReacts;
- protected array $ignoredChatIds;
- protected array $adminChatIds;
- protected array $allowedChatIds;
- protected $telegram;
- protected array $receivedData;
- protected integer $chatId;
- protected integer $messageId;
- protected string $chatType;
- protected string $callbackQueryMethod;
- protected string $photoHandleMethod;
- protected string $chatMemberAppearMethod;
- protected string $chatMemberLeftMethod;
- protected bool $debugFlag;
- protected array $calledActions;
- protected string $botImplementation;
- protected bool $hookAutoSetup;
- protected array $allowedUpdates;
- protected integer $maxConnections;
- // methods
- public void __construct()
- protected void loadConfigs()
- protected void setOptions()
- protected void initDb()
- protected void initCache()
- protected void setFeaturesAvailable()
- protected void setIcons()
- protected bool isFeatureEnabled()
- protected void setCommands()
- protected bool checkAuth()
- protected array getApiData()
- protected void loadAuthData()
- public array getAuthDataAll()
- public array getAuthDataRaw()
- protected void saveAuthData()
- protected void setContext()
- protected mixed getContext()
- protected array sendToUser()
- protected int getThrottleBanTime()
- protected bool checkThrottle()
- protected void setUserTag()
- public array listen()
- public void handleEmptyAction()
- protected array getCreditData()
- public string directSendToChatId()
- protected void actionLogIn()
- protected void actionLogout()
- protected void actionKeyboard()
- protected void actionBack()
- protected string profileRow()
- protected void actionProfile()
- protected void actionCredit()
- protected void actionOpenpayz()
- protected void actionMyPayments()
- protected void actionAnnouncements()
- protected void actionCATV()
- protected bool isThreadId()
- protected string renderTicketThread()
- protected void actionSupport()
- protected int getTicketReplyId()
- protected void actionCreateSupportTicket()
- protected void actionTesting()
- // Inherited methods from WolfDispatcher
- public void __construct()
- protected void setBotName()
- public void setDebug()
- protected void initTelegram()
- public void setActions()
- public void setGroupActions()
- public void setAdminActions()
- public void setAdminChatId()
- public void setTextReactions()
- public void setCallbackQueryHandler()
- public void setPhotoHandler()
- public void setOnChatMemberActions()
- public void setAllowedUpdates()
- public void setMaxConnections()
- public void setAllowedChatIds()
- public void setIgnoredChatIds()
- protected string getTextAction()
- protected void runAction()
- protected void reactInput()
- protected void handleEmptyAction()
- protected void handleEmptyText()
- protected void handleAnyWay()
- protected void handlePhotoReceived()
- protected void handleCallbackQuery()
- protected void writeDebugLog()
- public array listen()
- protected array|bool isCallbackQueryReceived()
- protected bool isPhotoReceived()
- protected array|bool isNewChatMemberAppear()
- protected array|bool isChatMemberLeft()
- protected array|bool isGroupMemberAppear()
- protected array|false isGroupMemberLeft()
- protected array|false isGroupMemberBanned()
- protected mixed isGroupMemberUnbanned()
- protected bool isAdmin()
- protected array message()
- protected mixed getPhoto()
- protected string|void savePhoto()
- protected string|bool reply()
- protected string|bool replyTo()
- protected array sendMedia()
- protected array removeChatMessage()
- protected array editMessageText()
- protected array pinChatMessage()
- protected array unpinChatMessage()
- protected array banGroupMember()
- protected array unbanGroupMember()
- protected array rearrangeButtons()
- protected void castKeyboard()
- protected void confirmCallbackQuery()
- public void hookAutosetup()
- public string installWebHook()
Hierarchy
Extends
Constants
| Name | Value |
|---|---|
| TABLE_AUTH | 'ct_auth' |
| KEY_AUTH_TMP | 'CT_AUTH_TMP' |
| KEY_CONTEXT | 'CT_CONTEXT' |
| KEY_THROTTLE | 'CT_THROTTLE' |
| OPTION_PKBD_COUNT | 'CLAPTRAPBOT_PKBD_ROW' |
| OPTION_FEATURES | 'CLAPTRAPBOT_FEATURES' |
| OPTION_SYSTEM_CURRENCY | 'TEMPLATE_CURRENCY' |
| OPTION_THROTTLE_LIMIT | 'CLAPTRAPBOT_THROTTLE_LIMIT' |
| OPTION_THROTTLE_BAN_TIME | 'CLAPTRAPBOT_THROTTLE_BAN_TIME' |
| OPTION_PAY_LIMIT | 'CLAPTRAPBOT_MY_PAYMENTS_LIMIT' |
| OPTION_TAG_ID | 'CLAPTRAPBOT_USERS_TAGID' |
| OPTION_TOKEN | 'CLAPTRAPBOT_TOKEN' |
| OPTION_AUTH_STRING | 'CLAPTRAPBOT_AUTH_STRING' |
| OPTION_HOOK_URL | 'CLAPTRAPBOT_HOOK_URL' |
| OPTION_HELPDESK | 'CLAPTRAPBOT_HELPDESK_INTEGRATION' |
| PROUTE_VALIDATE | 'ctbvalidator' |
| VALIDATION_RESULT | 'HA! I was MADE to open doors!' |
| LOG_PATH | 'exports/' |
| HOOK_PID_PATH | 'exports/' |
Members
protected
- $adminChatIds
—
array
Contains administrator users chatIds as chatId=>index - $adminCommands
—
array
Chats commands array which required user set in adminChatIds struct to be executed. - $allowedChatIds
—
array
Array of chatIds which is allowed for actions execution. Ignored if empty. - $allowedUpdates
—
array
Hook allowed updates array - $altCfg
—
array
Contains system alter config as key=>value - $apiUrl
—
string
Remote Ubilling userstats URL - $authDb
—
Auth database abstraction layer - $botImplementation
—
string
Contains current bot instance class name as is - $botToken
—
string
Contains current instance bot token - $cache
—
System caching object instance - $cacheTimeout
—
int
Current instance caching timeout - $callbackQueryMethod
—
string
Method name which will be executed on any callback query receive - $calledActions
—
string
Contains all called actions/methods - $chatId
—
int
Current conversation client chatId - $chatId
—
int
Current conversation client chatId - $chatMemberAppearMethod
—
string
Method name which will be executed if any new chat member appears - $chatMemberLeftMethod
—
string
Method name which will be executed if any new chat member left chat - $chatType
—
string
Current converstation chat type, like private,group - $commands
—
array
Contains text commands=>actions mappings - $commandsEnabled
—
array
Contains enabled commands list - $context
—
string
Contains current conversation context - $debugFlag
—
bool
Dispatcher debugging flag - $featuresAvailable
—
array
Contains available features struct - $featuresEnabled
—
array
Contains enabled features list - $groupChatCommands
—
array
Group chats commands array which overrides normal actions only for group chats - $helpdeskIntegrationFlag
—
int
Contains helpdesk integration flag - $hookAutoSetup
—
bool
Web-hook automatic installation flag - $icons
—
array
Contains available emoji icons as name=>icon - $ignoredChatIds
—
array
Array of chatIds which is denied for any actions performing - $loggedIn
—
bool
Current instance authorization state - $loginActionCalled
—
bool
Flag to prevent actionLogIn from executing multiple times in one request - $maxConnections
—
int
Contains default webhook maxConnections value - $messageId
—
int
Current conversation latest messageId - $myLogin
—
string
Current conversation user login - $myPassword
—
string
Current conversation user password md5 hash - $myPaymentsLimit
—
int
Contains limit of payments to show in mypayments list by default - $photoHandleMethod
—
string
Method name which will be executed on any image receive - $primaryKbdInRow
—
int
Contains primary keyboard buttons optional count in row - $primaryKbdLoggedIn
—
array
Contains primary keyboard buttons set for authorized user - $primaryKbdLoggedOut
—
array
Contains primary keyboard buttons set for logged out user - $receivedData
—
array
Input data storage - $systemCurrency
—
string
Contains system currency - $telegram
—
Telegram interraction layer object placeholder - $textReacts
—
array
Contains text reactions=>actions mappings - $throttleBanTime
—
int
Contains throttle ban time in seconds - $throttleLimit
—
int
Contains limit of requests per minute (APM) - $ticketTextLimit
—
int
Contains limit of ticket text length - $userTagId
—
int
Contains existing tag type ID to mark authorized users
Methods
protected
- actionAnnouncements() — Renders announcements list
- actionBack() — Clears current conversation context and returns to main menu
- actionCATV() — Renders CaTV user profile
- actionCreateSupportTicket() — Handles support ticket creation or reply
- actionCredit() — Requests credit for user or check possibility of credit
- actionKeyboard() — Pushes some keyboard to uses based on current context
- actionLogIn() — Setups some user auth data and stores it into cache/database
- actionLogout() — Cleanups user auth data by setting active flag to 0
- actionMyPayments() — Renders user payments list
- actionOpenpayz() — Renders payment methods available for user
- actionProfile() — Renders user profile data
- actionSupport() — Handles support action
- actionTesting()
- checkAuth() — Checks is some login/password auth valid or not?
- checkThrottle() — Checks if user is throttled by APM limit
- getApiData() — Pushes some request to Ubilling userstats XMLAgent API and returns response
- getContext() — Gets current conversation context
- getCreditData() — Requsts or checks possibility of user credits via XMLAgent API
- getThrottleBanTime() — Gets remaining ban time in seconds for current user
- getTicketReplyId() — Returns ticket thread ID from context or lates opened thread ID or 0 if not found
- initCache() — Inits system caching object instance
- initDb() — Inits auth database abstraction layer
- isFeatureEnabled() — Checks if feature is enabled
- isThreadId() — Checks is given ticket ID existing thread ID?
- loadAuthData() — Loads auth data from cache or database for current chatId
- loadConfigs() — Preloads all of required configs
- profileRow() — Renders single profile row
- renderTicketThread() — Renders support request thread by its ID only if its not reply
- saveAuthData() — Saves auth data to database with active flag and clears cache
- sendToUser() — Just sends some string content to current conversation
- setCommands() — Sets all of available commands for current instance
- setContext() — Sets current conversation context
- setFeaturesAvailable() — Sets all of available features for current instance
- setIcons() — Sets available emoji icons as name=>icon
- setOptions() — Sets all of required options from config values
- setUserTag() — Sets user tag for current user on authorization or logout
public
- __construct() — STAIRS?! NOOOOOOOOOOOOOOOOO!
- directSendToChatId() — Sends message to some chat id via Telegram API
- getAuthDataAll() — Returns all users auth data from database as login=>authData
- getAuthDataRaw() — Returns all users auth data from database as raw array as id=>authData
- handleEmptyAction() — Magic middleware to handle raw-text inputs from user
- listen() — Just hook input data listener
Inherited from WolfDispatcher
protected
- banGroupMember() — Bans a member from a specified group.
- castKeyboard() — Sends some keyboard to current chat
- confirmCallbackQuery() — Confirms a current callback query with some text and optional show alert flag
- editMessageText() — Edits a message by its ID in a specified chat.
- getPhoto() — Returns received image file content
- getTextAction() — Getting current input text action name if it exists
- handleAnyWay() — Dummy method which will be executed on receive any non empty data on listener
- handleCallbackQuery() — Dummy method which will be executed on receive any callback query
- handleEmptyAction() — Dummy method which will be executed on receive empty text actions on listener
- handleEmptyText() — Dummy method which will be executed on receive empty text actions on listener
- handlePhotoReceived() — Dummy method which will be executed on receive any image file
- initTelegram() — Inits protected telegram instance
- isAdmin() — Checks is current user chatId listed as administrator?
- isCallbackQueryReceived() — Checks is any callback query received?
- isChatMemberLeft() — Checks is any chat member lefts chat? Returns his chatId on this event.
- isGroupMemberAppear() — Checks if a new chat member has appeared in a group chat.
- isGroupMemberBanned() — Checks if a group member has been kicked/banned from the chat.
- isGroupMemberLeft() — Checks if a group member has left the chat by the own will
- isGroupMemberUnbanned() — Checks if a group member has been unbanned.
- isNewChatMemberAppear() — Checks is new chat member appeared in chat? Returns his data on this event.
- isPhotoReceived() — Checks is any image received?
- message() — Returns current received message as receivedData struct
- pinChatMessage() — Pins a message by its ID in a specified chat.
- reactInput() — Run some actions on non empty input data received
- rearrangeButtons() — Rearranges flat buttons array into 2D array with specified buttons per row
- removeChatMessage() — Removes a chat message by its ID from a specified chat.
- reply() — Sends fast reply to current chat member
- replyTo() — Sends fast reply to current chat member for latest message or some specified messageId
- runAction() — Performs run of some action into current dispatcher instance
- savePhoto() — Saves received photo to the specified path on filesystem. Returns filepath on success.
- sendMedia() — Universal method for sending different types of media and files to chat.
- setBotName() — Sets current bot instance implementation property
- unbanGroupMember() — Unbans a member from a group.
- unpinChatMessage() — Unpins a message by its ID in a specified chat or unpins all messages if messageId is empty.
- writeDebugLog() — Writes debug data to separate per-class log if debugging flag enabled.
public
- hookAutosetup() — Enables or disables web-hook automatic installation
- installWebHook() — Automatically registers new web-hook URL for bot if isnt registered yet.
- listen() — Listens for some events
- setActions() — Sets new dispatcher actions dataset
- setAdminActions() — Sets admin commands data set. This actions requires user to be isAdmin() for execution
- setAdminChatId() — Sets administrative user chatIDs
- setAllowedChatIds() — Sets allowed chat IDs for this instance
- setAllowedUpdates() — Sets allowed hook updates list. Example: array('update_id', 'message', 'chat_member')
- setCallbackQueryHandler() — Sets method name which will be executed on any callback query received
- setDebug() — Instance debugging flag setter. Debug log: exports/botname_debug.log
- setGroupActions() — Sets group commands data set If not empty data set its overrides all default actions for not private chats
- setIgnoredChatIds() — Sets denied chat IDs for this instance
- setMaxConnections() — Sets hook max connections limit
- setOnChatMemberActions() — Sets method names which will be executed if some member appears or left chat
- setPhotoHandler() — Sets method name which will be executed on any image input
- setTextReactions() — Sets new dispatcher text reactions dataset. Basic setActions dataset overrides this.