Download the PHP package shamanhead/telbot without Composer
On this page you can find all versions of the php package shamanhead/telbot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shamanhead/telbot
More information about shamanhead/telbot
Files in shamanhead/telbot
Package telbot
Short Description A simple library to create message bot in telegram
License MIT
Homepage https://packagist.org/packages/shamanhead/telbot
Informations about the package telbot
telbot
Contents
- Introducion
-
Utils
- Creating keyboard
- Encoding files
- Building inline query result
-
Mysql features
- Context
- Chats
-
Inquiry
- Supported methods
- Sending simple answers
- Sending callback answers
- Sending inline answers
- Sending files
-
InputHandle
- Creating a new InputHandle object
- Working with data
- Privilege
- Examples
- License
Introducion
If you want to create your bot, for the first you need to register him.You can do it with @BotFather. Open the dialog with him and write /newbot , like as in this image:
After that you need to set webhook on your bot.Webhook its a system, who sending queries to your server, if telegram gets one.
Before start creating a webhook you need bot api token and server.If you dont have a server, you can use heroku to create one.
You can find your bot api token by writing /mybots, then select your bot, and then select button "API Token".Example:
When you finish all this actions, you can set webhook to your bot.For this you need to use bot api method setWebhook:
Then, if you done all right, you will see this answer:
After that you can start working with your bot.But how I can work?You can ask me.Lets see, how.
Creating you bot
How to create bot?Very easy!Just create a new bot class:
So, lets create a script, who will send a text message as test.But how?The Inquiry class will help us with it:
Utils
Supporting class for ease of work with telegram bot api types.
Creating keyboard
You can create keyboards easy using this way:
Examples:
Encoding files
If you want to send video or photo to user, you need to encode them to CURl format.For this use this method:
Parameter $filePath need to indicate path to file you want to send.
Building inline query result
If you want to send an answer to inline query, you need to build answer object.For this use this method:
You can check example here
Mysql features
To start work with mysql, first you need to do is enable sql connection in your bot object:
You can also disable sql by using similar method:
Warning: if your sql connection doesnt exist, you can not use this modules:User, Chat. In this case Context instead of writing context values to the database would be create new file with context(one to user).
Later you need to specify sql credentials:
Or you can indicate your external pdo connection as sql credentials:
After all this actions, you can start to work with database.
Context
Using class Context you can create context dependence:
Working with chats in database
All the same, but a bit different:
To add chats to database, you need to use this function:
To delete chats:
To get chats:
This function returns array with row information of this chat(row id, chat id, bot token)
To get all chats:
Inquiry
Its the main class in this library.This paragraph shows all capabilities of this class.
This class has only one method - Inquiry::send().With this class you can send both simple text messages and complex answers.
Supported methods
All method supported during version of API 4.7
Sending simple answer
Sending callback query answer
Sending Inline query answer
Sending Inline query answer
You can send any of telegram methods with this method send.All of this supported.
Sending files
To send files from your server, you need to encode file to CURl format.For this, you need to use method Utils::encodeFile.
Input Handle
This class needs for comfortable work with telegram answer query.
Creating a new InputHandle object
Working with data
Privelege
Privelege
You can give a user a specific privilege in the chat(or all chats). This can be used to give access to certain commands to that particular user.
Examples
See examples at 'examples' folder.
License
Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.