Download the PHP package webpajooh/telebot without Composer
On this page you can find all versions of the php package webpajooh/telebot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webpajooh/telebot
More information about webpajooh/telebot
Files in webpajooh/telebot
Package telebot
Short Description A minimal library to develop your new Telegram bot
License MIT
Informations about the package telebot
TeleBot
A minimal library to develop your new Telegram bot
Installation
composer require webpajooh/telebot
How to use
Start point
We start by creating an instance of TeleBot
class:
Get the update object
There are short ways to access the update
object and some important fields. I recommend you to read the official documentation to understand these objects well.
You also can use the hasCallbackQuery()
method, when you want to check if the update
object has a callback_query
field.
Methods
Thanks to magic methods, we can use API methods without implementing them, and just call them by name and pass an array as parameter:
Router
You may define some routes to your bot features; define them by the listen()
method:
The third parameter that is true by default, makes you able to terminate the script after running a command. In the previous example we passed false
so script continues.
You can also get parameters and use them as variables:
TeleBot translates them to regex, so it will be good to take a look at this table to know how to use them properly:
Type | TeleBot | Regex |
---|---|---|
Digits | %d | (\d+) |
String (Anything but a whitespace) | %s | (\S+) |
Character | %c | (\S) |
Everything including an empty string | %p | (.*) |
Logger
You may need to log something into a log.txt
file:
Keyboard
TeleBot includes two classes for making keyboards; InlineKeyboard
and ReplyKeyboard
. Here you see an example:
Then you can use it as bellow:
Consider that the chunk()
method supports more complex orders, just pass an array like [1, 3, 2] to build such a keyboard:
[ 1 ] [ 2 ] [ 3️ ] [ 4 ] [ 5 ] [ 6 ]
Default parameters
Sometimes you do not want to repeat yourself by passing a parameter everywhere, so you can define default parameters for each method. Here are three example that makes it clear how to use it:
Extend it!
You may want to add some methods to TeleBot class to improve your code readability and avoid duplication. Look at this simple example as an inspiration:
Have you seen a problem?
Create an issue and explain your problem!