\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 $photoHandleMethod = '';
- protected string $chatMemberAppearMethod = '';
- protected string $chatMemberLeftMethod = '';
- protected bool $debugFlag = false;
- protected array $calledActions = ;
- protected string $botImplementation = '';
- protected bool $hookAutoSetup = false;
- // 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 setPhotoHandler()
- public void setOnChatMemberActions()
- 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 writeDebugLog()
- public array listen()
- protected bool isPhotoReceived()
- protected array/bool isNewChatMemberAppear()
- protected array/bool isChatMemberLeft()
- protected bool isAdmin()
- protected array message()
- protected mixed getPhoto()
- protected string/void savePhoto()
- protected string/bool reply()
- protected string/bool replyTo()
- protected void castKeyboard()
- public void hookAutosetup()
- protected void 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. - $botImplementation
—
string
Contains current bot instance class name as is - $botToken
—
string
Contains current instance bot token - $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 - $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
- castKeyboard() — Sends some keyboard to current 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
- 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
- installWebHook() — Automatically registers new web-hook URL for bot if isnt registered yet.
- isAdmin() — Checks is current user chatId listed as administrator?
- isChatMemberLeft() — Checks is any chat member lefts chat? Returns his chatId on this event.
- 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
- reactInput() — Run some actions on non empty input data received
- 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.
- setBotName() — Sets current bot instance implementation property
- 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
- 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
- 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
- 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.