pembuatan/bot
最新稳定版本:v0.0.2
Composer 安装命令:
composer require pembuatan/bot
包简介
Pustaka sederhana untuk pembuatan bot Telegram dengan menggunakan bahasa PHP
README 文档
README
Simple Telegram Bot API library for PHP
Quick Start
Initiate with setToken and end with run method.
Sample 1: Start
require 'Bot.php'; Bot::setToken(BOT_TOKEN, BOT_USERNAME); //init (required) Bot::start('Welcome, I am a bot.'); //event Bot::run(); //launch (required)
Sample 2: Keyboard
Bot::chat('/help', function(){ $keyboard = Bot::keyboard(' [/info] [/admin] [/help] '); $options = ['reply_markup' => $keyboard]; return Bot::sendMessage("List of Commands:", $options); });
Sample 3: Inline Keyboard
Bot::chat('/inline_keyboard', function(){ $inline_keyboard = Bot::inline_keyboard(' [Google|https://www.google.com] [Facebook|https://www.facebook.com] [More|more_data] '); $options = ['reply_markup' => $inline_keyboard]; return Bot::sendMessage("Options:", $options); });
Sample 4: Sending Document
Bot::chat('/send', function($file){ if (file_exists($file)) return Bot::sendDocument($file); return Bot::sendMessage("$file not exists"); });
Sample 5: Chat Array
$help = function(){ return Bot::sendMessage("This is <b>bold</b> and <i>italic</i> text.", ['parse_mode' => 'html']); }; $info = function() { Bot::sendChatAction('typing'); Bot::sendDocument('composer.json', ['caption' => 'for composer']); }; Bot::chat_array([ '/help' => $help, '/info' => $info, ]);
Sample 6: Regex
Bot::regex('/^\/start (\d+)$/', function($m){ return Bot::sendMessage($m[1]); }); Bot::start(function(){ return Bot::sendMessage('Press button bellow:', [ 'reply_markup' => Bot::inline_keyboard(' [BUTTON|https://t.me/Testing58384bot?start=1234567890] ') ] ); });
Documentation
Note that all properties and methods are static. For example: Bot::$property or Bot::method().
Bot Properties
| Property | Type | Description |
|---|---|---|
| token | string | bot token from @BotFather |
| name | string | bot name from @BotFather |
| url | string | telegram URL for endpoint |
| getUpdates | array | parsed-JSON from Telegram server |
| inputObject | object | decoded-JSON from Telegram server |
| _command | array | list of commands and responses |
| _onMessage | array | list of events (types) and the responses |
| version | integer | app version |
| message_id | string | message ID |
| message_text | string | message text |
| user | string | first name (and last name) |
| from_id | integer | from ID |
| chat_id | integer | from ID |
| admin_id | integer | admin ID |
Bot Methods
| Method | Parameter(s) | Description |
|---|---|---|
| setToken | string bot token, string bot name |
|
| setAdmin | integer admin ID |
|
| isAdmin | to check if user is admin | |
| name | to get bot name | |
| chat | string command, string or callable response |
to set command and its response |
| cmd | string command, string or callable response |
to set command and its response |
| chat_array | associative array list of command (key) and its response (value) |
to set command and its response |
| keyboard | string keyboard pattern, string input_field_placeholder = 'type here', boolean resize_keyboard = true, boolean one_time_keyboard = true |
to create keyboard(s) from string |
| inline_keyboard | string keyboard pattern |
to create inline keyboard(s) from string |
| message_id | to get message id | |
| message_text | to get message text | |
| user | to get user first name (and last name) | |
| from_id | to get user ID | |
| chat_id | to get chat ID | |
| on | string type, string or callable response |
to set response |
| regex | string pattern, string or callable response |
to set response |
| run | to run the bot | |
| send | string method, associative array data |
to send request to Telegram server |
| answerInlineQuery | result, array options = [] |
to answer Inline Query |
| answerCallbackQuery | text, array options = [] |
to answer Callback Query |
| message | to get body of message JSON from user | |
| type | to get type of message | |
__callStatic |
string method, array parameters |
to call any method |
| prosesPesan | string teks, array data = null |
to send a long message |
| bg_exec | string function name, array parameters, string PHP script to be loaded first, integer timeout = 1000 |
to call function in background |
Telegram Events
Note that event parameters up to 2 parameters. For example: Bot::start($param1, $param2).
all(when user sends anything, it's similar withon('*', $response)method)start(when user sends/starttext message or pressesSTARTbutton)text(see: docs)animationaudiodocumentphotostickervideovideo_notevoicecontactdicegamepollvenuelocationmessage_auto_delete_timer_changedpinned_messageinvoicesuccessful_paymentuser_sharedchat_sharedwrite_access_allowedpassport_dataproximity_alert_triggeredforum_topic_createdforum_topic_editedforum_topic_closedforum_topic_reopenedgeneral_forum_topic_hiddengeneral_forum_topic_unhiddenvoice_chat_scheduledvoice_chat_startedvoice_chat_endedvoice_chat_participants_invitedinline_querycallback_queryedited_messagechannel_postedited_channel_post
Telegram Methods
All Telegram methods are compatible with this bot. For example:
echo Bot::getMe(); echo Bot::setWebhook(WEBHOOK_URL); echo Bot::getWebhookInfo(); echo Bot::deleteWebhook(true); //default is `false` for `drop_pending_updates`, see: https://core.telegram.org/bots/api#deletewebhook
See more: https://core.telegram.org/bots/api#available-methods
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-27






