Telekit is a powerful toolkit for building Telegram bots with ease, using Laravel Eloquent ORM. With Telekit, developers can quickly build and deploy bots, saving time and effort.
One of the standout features of Telekit is its support for Laravel Eloquent ORM, which allows developers to easily interact with the database and perform complex operations with just a few lines of code. This makes it simple to manage data within your Telegram bot and keep your code organized and maintainable.
Telekit also provides a range of tools and utilities for working with the Telegram API, making it easy to handle incoming messages, send messages to users, and perform other common bot tasks. Developers can take advantage of Telekit's intuitive API to quickly build and test new bot features, without having to worry about the underlying details of the Telegram protocol.
- PHP version 8.0
- Postgres, Mysql, Sqlite database
- Running migrations (chats table)
Open a terminal or command prompt and navigate to your project directory.
Run the following command:
composer require rasa/telekit
This will download and install the Telekit library and all its dependencies into your project's vendor directory.
Once the installation is complete, you can start using Telekit by including its autoload file in your code
- my website
- Receive updates in the browser https://api.telegram.org/bot{TOKEN}/getUpdates
- Set up a webhook https://api.telegram.org/bot{TOKEN}/setwebhook?url=https://test.com/example_bot/index.php
- Delete a webhook https://api.telegram.org/bot{TOKEN}/deleteWebhook
php artisan serve
php artisan
php artisan send all
php artisan send --to=CHAT_ID
php artisan send -t CHAT_ID
php artisan send --to=CHAT_ID --message="hello world"
php artisan send -t CHAT_ID -m "hello world"
php artisan make:interaction MyInteraction
php artisan make:trigger myTrigger
php artisan make:migration table
php artisan make:model User
php artisan database
php artisan database:params
php artisan database:version
php artisan database:tables
php artisan database:table chats
php artisan database:table chats --desc
php artisan database:showTable chats --columns="chat_id"
php artisan database:showTable chats --columns="chat_id" --columns="username" --columns="attempts"
php artisan migrate
php artisan migrate --fresh
php artisan responses
class Hi extends Trigger {
public function __construct($request)
{
$this->reply_message('Hi');
}
}
<?php
namespace Triggers;
class Help extends Trigger {
public function __construct($request)
{
$this->sendMessage()
->chat_id($request['message']['chat']['id'])
->text('Помощь')
->send();
}
}
$this->sendMessage()
->chat_id($request['message']['chat']['id'])
->text('Choose the option')
->parse_mode()
->reply_markup([
'one_time_keyboard' => true,
'resize_keyboard' => true,
'inline_keyboard' => [
[
[
'text' => 'About',
'callback_data' => 'About',
],
[
'text' => 'Help',
'callback_data' => 'help',
]
],
[
[
'text' => 'Settings',
'callback_data' => 'settings',
]
]
]
])
->send();
$this->photo()
->protect_content(true)
->caption('Подпись')
->photo("image1.png", "кот.jpg", "image/jpg")
->send()
$this->document()
->protect_content(true)
->caption('Sign')
->photo("image1.png", "cat.jpg", "image/jpg")
->send()
$this->mediaGroup()
->chat_id(id)
->media([
['type' => 'document', 'name' => 'mycat', 'path' => 'img/image1.png'],
['type' => 'document', 'name' => 'mycat2', 'path' => 'img/image1.png']
])
->send();
namespace Inlines;
use Core\Responses\Interaction;
class Example extends Interaction {
public function __construct($request)
{
$result = [
[
"type" => "article",
"id" => "0",
"title" => "Do",
"description" => "something",
"input_message_content" => [
"message_text" => "result: <b> OK </b>",
"parse_mode" => "HTML"
]
],
[
"type" => "article",
"id" => "1",
"title" => "Do 2",
"description" => "something 2",
"input_message_content" => [
"message_text" => "result: <b> OK 2 </b>",
"parse_mode" => "HTML"
]
]
];
$this->answerInlineQuery()
->inline_query_id($request['inline_query']['id'])
->results($result)
->cache_time(1)
->is_personal(true)
->send(false, false);
}
}
$this->send_invoice()
->title('Subscription')
->description("Buy subscription for an month.")
->payload('Subscription: month')
->currency('USD')
->prices(['label' => 'Subscription for an month', 'amount' => 100000])
->send();