1. Go to this page and download the library: Download shamanhead/telbot library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shamanhead / telbot example snippets
use \Telbot\Bot as Bot;
$bot = new Bot('BOT_API_KEY HERE');
use \Telbot\Bot as Bot;
use \Telbot\Inquiry as Inquiry;
use \Telbot\InputHandle as InputHandle;
$bot = new Bot('API_TOKEN');
$InputHandle = new InputHandle();
Inquiry::send($bot
,'sendMessage',
[
'chat_id' => $InputHandle->getChatId(),
'text' => 'Testing your bot.'
]
);
use \Telbot\Utils\ as Utils;
use \Telbot\Bot as Bot;
Utils::buildInlineKeyboard([[['one', 'text']], [['two', 'text']], [['three', 'test']]])
Utils::buildKeyboard([[['third'], ['second'], ['first']]])
use \Telbot\Utils as Utils;
use \Telbot\Bot as Bot;
use \Telbot\InputHandle as InputHandle;
use \Telbot\Inquiry as Inquiry;
$bot = new Bot('API_TOKEN');
$InputHandle = new InputHandle();
Inquiry::send($bot, 'sendMessage', [
'chat_id' => $InputHandle->getChatId(),
'text' => 'Simple text.',
'reply_markup' => Utils::buildInlineKeyboard([[['one', 'callback']], [['two', 'callback']], [['three', 'callback']]])
]);
use \Telbot\Context as Context; //We \Inquiry as Inquiry;
use \Telbot\InputHandle as InputHandle;
$InputHandle = new InputHandle();
$bot = new Bot('API_TOKEN');
$DBH = new PDO();
$bot->externalPDO($DBH);
$bot->enableSql();
if(!Context::read($bot, $InputHandle->getChatId(), $InputHandle->getUserId())){ //reading context
Inquiry::send($bot
,'sendMessage',
[
'chat_id' => $InputHandle->getChatId(),
'text' => 'Write smth'
]
);
Context::write($bot, $InputHandle->getChatId(), $InputHandle->getUserId(), 'smth'); //creating new context
}else{
Inquiry::send($bot
,'sendMessage',
[
'chat_id' => $InputHandle->getChatId(),
'text' => 'Okay, you writed!'
]
);
Context::delete($bot, $InputHandle->getChatId(), $InputHandle->getUserId()); //delete context
}
Chat::add($bot, $chatId);
Chat::delete($bot, $chatId);
Chat::get($bot, $chatId);
Chat::getAll($bot);
Inquiry::send($bot, $method, $data);
Inquiry::send($bot, 'sendMessage', [
'chat_id' => $InputHandle->getChatId(),
'text' => 'This is a testing message'
]);
Inquiry::send($bot, 'answerCallbackQuery', [
'callback_query_id' => $InputHandle->getCallbackQueryId(),
'text' => 'This is a callback answer, who lool like common notification'
]);
//sending photo
use \Telbot\Bot as Bot;
use \Telbot\InputHandle as InputHandle;
use \Telbot\Inquiry as Inquiry;
$bot = new Bot('927942575:AAHZpZoG2pBRw25Lw-pPaw8FU15t00Lsf3A');
$InputHandle = new InputHandle();
Inquiry::send($bot ,'sendPhoto', [
'chat_id' => $InputHandle->getChatId(),
'photo' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Telegram_2019_Logo.svg/1200px-Telegram_2019_Logo.svg.png',
'caption' => 'This is an image!So beautiful'
]);
use \Telbot\Utils as Utils;
use \Telbot\Bot as Bot;
use \Telbot\InputHandle as InputHandle;
use \Telbot\Inquiry as Inquiry;
$bot = new Bot('927942575:AAHZpZoG2pBRw25Lw-pPaw8FU15t00Lsf3A');
$InputHandle = new InputHandle();
Inquiry::send($bot ,'sendPhoto', [
'chat_id' => $InputHandle->getChatId(),
'photo' => Utils::encodeFile('app/something/telegram.png'),
'caption' => 'This is an image!So beautiful'
]);
$InputHanle = new InputHandle();
$InputHandle->getUpdateId() // returns an update id of telegram answer query.
$InputHandle->getQueryType() // returns a query type of telegram answer query(callback_query,inline_query,message).
$InputHandle->getInstance() // returns an array of telegram answer.
$InputHandle->getCallbackData() // returns a callback data from telegram answer query.
$InputHandle->getCallBackQueryId() // returns a callback query id from telegram answer query.
$InputHandle->getUserId() // returns user id.
$InputHandle->userIsBot() // return true if user who send quiry is bot.
$InputHandle->getUserName() // returns name of user, who sends query.
$InputHandle->getMessageId() // returns user's message id.
$InputHandle->getUserFirstName() // returns user's first name.
$InputHandle->getLanguageCode() // returns user's language code.
$InputHandle->getChatType() // returns chat type.
$InputHandle->getChat() // returns chat array from telegram answer query.
$InputHandle->newChatMember() // returns true when new member comes to telegram chat.
$InputHandle->getChatId() // returns a chat id, where the message come.
$InputHandle->getDate() // returns date when telegram answer query was send.
$InputHandle->getEntities() // returns message entities from telegram answer query.
$InputHandle->getChatTitle() // returns title of chat where bot gets query.
$InputHandle->getInlineQueryText() // returns query data from inline query.
$InputHandle->getInlineQueryOffset() // returns query offset from inline query.
$InputHandle->getInlineQueryId() // returns an inline query in from telegram answer query.
Privilege::setToChat($bot, $value, $userId, $chatId); //for one chat
Privilege::setToAllChats($bot, $value, $userId); //for all chats
Privilege::get($bot, $userId); //getting a privelege
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.