Download the PHP package mateodioev/tg-handler without Composer
On this page you can find all versions of the php package mateodioev/tg-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mateodioev/tg-handler
More information about mateodioev/tg-handler
Files in mateodioev/tg-handler
Package tg-handler
Short Description Library for created telegram bots more easy
License MIT
Informations about the package tg-handler
Telegram bot handler
Installation
Usage
Create new instance and add your command
Creating new command instance
All text commands need to extend Mateodioev\TgHandler\Commands\MessageCommand
class, and put the logic in the method handle
.
This command works with /start any text here
or /start
. If you need another prefixes (/, !) you can add with method addPrefix
or with property prefix
Using middlewares
You can add middlewares to your command. Middlewares are closures that will be executed before the command. All middlewares results will be passed to the command as an array.
For example, you can create a middleware that will check if the user is authorized, and if not, the command will not be executed.
You can use
StopCommand
exception to stop command execution
Using filters
Now you can set custom filters to you event for validate, all filters need to extends the interface Mateodioev\TgHandler\Filters\Filter
Now this command only respond to the user ID 996202950
Using multiple filters
You can use FilterCollection
Or can use this sintax
Conversations
To start a new conversation you simply return an instance of the Mateodioev\TgHandler\Conversations\Conversations
in a interface of Mateodioev\TgHandler\Events\EventInterface
Conversation:
EventInterface handler for this case an instance of MessageCommand
Register the conversation
For more details see examples folder
Loging
Basic usage
Collections of streams
Set log level
Use
The logger can be used from the bot or event instances (MessageCommand, CallbackCommand, etc)
Bot:
Event instances:
Manager errors
You can register an exception handler the will be used if an exception occurs within the Events::execute method method or in the event middlewares
All versions of tg-handler with dependencies
psr/log Version ^3.0
smoren/string-formatter Version ^1.0
mateodioev/string-vars Version ^1.2
mateodioev/tgbot Version ^v4.2
kombyte/simple-logger Version ^1.0