\WolfDispatcher
Universal Telegram bot hooks processing extendable class
Synopsis
class WolfDispatcher
{
- // constants
- const LOG_PATH = 'exports/';
- const HOOK_PID_PATH = 'exports/';
- // members
- 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 = 0;
- protected integer $messageId = 0;
- protected string $chatType = '';
- protected string $callbackQueryMethod = '';
- protected string $photoHandleMethod = '';
- protected string $chatMemberAppearMethod = '';
- protected string $chatMemberLeftMethod = '';
- protected bool $debugFlag = false;
- protected array $calledActions = ;
- protected string $botImplementation = '';
- protected bool $hookAutoSetup = false;
- protected array $allowedUpdates = ;
- protected integer $maxConnections = 100;
- // methods
- 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()
Constants
| Name | Value |
|---|---|
| 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 - $botImplementation
—
string
Contains current bot instance class name as is - $botToken
—
string
Contains current instance bot token - $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 - $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 - $debugFlag
—
bool
Dispatcher debugging flag - $groupChatCommands
—
array
Group chats commands array which overrides normal actions only for group chats - $hookAutoSetup
—
bool
Web-hook automatic installation flag - $ignoredChatIds
—
array
Array of chatIds which is denied for any actions performing - $maxConnections
—
int
Contains default webhook maxConnections value - $messageId
—
int
Current conversation latest messageId - $photoHandleMethod
—
string
Method name which will be executed on any image receive - $receivedData
—
array
Input data storage - $telegram
—
Telegram interraction layer object placeholder - $textReacts
—
array
Contains text reactions=>actions mappings
Methods
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
- __construct() — Creates new dispatcher instance
- 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.