Build a robot with three lines of code :)
bot::setToken('token-string');
bot::autoInput();
bot::this()->message( bot::get('text') )->send();
usage in night framework
use Models\BotFire as bot;
or usage in other project ( view sample )
include_once('BotFire.php');
use Models\BotFire as bot;
bot::setToken('token-string');
bot::autoInput();
download and move BotFire.php to models directory :|
// Get the current chat_id
$chat_id=bot::$chat_id;
// Get the current username
$username=bot::$username;
// Get the current first_name
$first_name=bot::$first_name;
// Get the current last_name
$last_name=bot::$last_name;
// first_name + last_name
$full_name=bot::$full_name;
//Receive text the user has sent
$text=bot::get('text');
// get message_id
$message_id=bot::get('message_id');
// get message caption
$caption=bot::get('caption');
//Receive object of string sent by telegram
$ob_str=bot::$input;
//Receive json object sent by telegram
$json==bot::$json;
// support messages [text,photo,video,video_note,voice,animation,document]
$message = bot::getMessageType();
output text sample :
{
"type":"text",
"data":"Hello botfire"
}
output photo sample :
{
"type": "photo",
"data": [
{
"file_id": "AgA***",
"file_unique_id": "AQA***",
"file_size": 20303,
"width": 320,
"height": 296
}
]
}
check client type
// If the request is from the supergroup return true else false
$is_group=bot::isGroup();
// If the request is from the supergroup or group return true else false
$is_group=bot::isGroup(false);
// If the request is from the private user
$is_user=bot::isUser();
get request from the supergroup
// get group id
$chat_id = bot::$chat_id;
// Get the group title
$title = bot::$title;
// get sender user
$user = bot::get('user');
$user_chat_id = $user->id;
$is_bot = $user->is_bot;
$res=bot::this()->getMe()->send();
echo $res;
bot::this()->message('your message text')->send();
bot::this()->message('use parse_mode')->parse_mode('HTML')->send();
// send message to other user chat_id
bot::id(chat_id)->message('your message text')->send();
// if you want to get json result
$res=bot::this()->message('your message text')->sendAndGetJson();
use other methods
bot::this()
->message('text')
->parse_mode(string) // HTML or Markdown
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->disable_web_page_preview(boolean)
->send();
// send from url
bot::this()->photo(image_url_string)->send();
// send by file_id
bot::this()->photo(file_id_string)->send();
// send file from local server
$file=bot::loadFile('user.png');
bot::this()->photo( $file )->send();
// send photo with caption
bot::this()->photo( $file , 'Caption text for photo' )->send();
use other methods
bot::this()
->photo( $file , 'Caption text for photo' )
->parse_mode(string) // HTML or Markdown
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
** Other methods can be used like the photo method **
Use this method to send audio our audio must be in the .MP3 or .M4A format.
bot::this()->audio( $file , 'Caption text for audio' )->send();
use other methods
bot::this()
->audio( $file , 'Caption text for audio' )
->duration(int_to_seconds) //Duration of the audio in seconds
->performer(string)
->title(string) //Track name
->parse_mode(string) // HTML or Markdown
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
Use this method to send general files
bot::this()->document( $file , 'Caption text for document' )->send();
// use other methods
bot::this()
->document( $file , 'Caption text for document' )
->thumb(loadFile_or_string)
->parse_mode(string) // HTML or Markdown
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
Use this method to send video files,
bot::this()->video( $file , 'Caption text for video' )->send();
// use other methods
bot::this()
->video( $file , 'Caption text for video' )
->duration(int_to_seconds) //Duration of sent video in seconds
->width(int) //Animation width
->height(int)//Animation height
->thumb(loadFile_or_string)
->parse_mode(string) // HTML or Markdown
->supports_streaming(boolean) //Pass True, if the uploaded video is suitable for streaming
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
bot::this()->animation( $file , 'Caption text for animation' )->send();
// use other methods
bot::this()
->animation( $file , 'Caption text for animation' )
->duration(int_to_seconds) //Duration of sent animation in seconds
->width(int) //Animation width
->height(int)//Animation height
->thumb(loadFile_or_string)
->parse_mode(string) // HTML or Markdown
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
Use this method to send audio
bot::this()->voice( $file , 'Caption text for voice' )->send();
// use other methods
bot::this()
->voice($file,'caption')
->parse_mode(string) // HTML or Markdown
->duration(int_to_seconds) //Duration of sent voice in seconds
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.
bot::this()->voice( video_file )->send();
// use other methods
bot::this()
->voice( video_file )
->duration(int_to_seconds) //Duration of sent video in seconds
->length(int) //Video width and height
->thumb(loadFile_or_string)
->disable_notification(boolean)
->reply_to(message_id)
->keyboard(botfire_keyboard)
->send();
The loadFile function is used to send server files
bot::this()->document( bot::loadFile(file_path_string) )->send();
Use this method to send point on the map. On success, the sent Message is returned.
bot::this()->location($latitude,$longitude)->send();
// support live_period
bot::this()->location($latitude,$longitude)->live_period($number)->send();
Use this method when you need to tell the user that something is happening on the bot's side
action list :
'typing','upload_photo','record_video','upload_video','record_audio','upload_audio','upload_document','find_location','record_video_note','upload_video_note'
bot::this()->chatAction('typing')->send();
inline keyboard sample :
$k=bot::keyboard();
$k->inline()->row(function($col){
// usage callback
$col->btn('button name','callback_text');
// usage url
$col->btnUrl('night framework','https://nightframework.com');
})
->row(function($col){
$col->btn('one button','callback_text_2');
});
// send message with inline button
bot::this()->message('message text')->keyboard($k)->send();
// send photo with inline button
bot::this()->photo(file_id,'caption')->keyboard($k)->send();
sample 2
$k=bot::keyboard();
$k->btn('game 1','game_callback');
$k->btn('game 2','game_callback');
$k->row();
bot::this()->message('message text')->keyboard($k)->send();
Telegram ReplyKeyboardMarkup Docs
$k=bot::keyboard();
$k->markup()->row(function($col){
$col->btn('button name');
});
$k->markup(true)->row(function($col){
$col->btn('button name');
});
bot::this()->message('text')->keyboard($k)->send();
bot::this()->message('text')->removeKeyboard()->send();
check request calback
if(bot::$isCallback){
/// code ..
}
Receive callback data
$data=bot::get('data');
Receive callback_query_id
$query_id = bot::get('callback_id');
bot::this()->answerCallback()->send();
// send alert
bot::this()->answerCallback(true)->text('hello Telegram :)')->send();
// or open robot link
$link='t.me/your_robot?start=xxxx';
bot::this()->answerCallback()->url($link)->send();
Use this method to edit text and game messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
bot::this()->editMessage('new text string')->send();
// use other methods
bot::this()
->editMessage('new text string')
// Use custom message_id
->message_id(id)
// Use custom inline_message_id
->inline_message_id(id)
->parse_mode('HTML')
->disable_web_page_preview(boolean)
->keyboard($k) // A JSON-serialized object for an inline keyboard.
->send();
Use this method to edit captions of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
bot::this()->editCaption('new text string')->send();
// use other methods
bot::this()
->editCaption('new text string')
// Use custom message_id
->message_id(id)
// Use custom inline_message_id
->inline_message_id(id)
->parse_mode('HTML')
->keyboard($k) // A JSON-serialized object for an inline keyboard.
->send();
Use this method to edit only the reply markup of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
bot::this()->editReplyMarkup()->keyboard($k)->send();
// use other methods
bot::this()
->editReplyMarkup('new text string')
// Use custom message_id
->message_id(id)
// Use custom inline_message_id
->inline_message_id(id)
->keyboard($k) // A JSON-serialized object for an inline keyboard.
->send();
Use this method to delete a message
bot::this()->deleteMessage()->send();
// or
bot::this()->deleteMessage()->message_id('custom message_id')->send();
bot::this()->setWebhook($url)->send();
// or
bot::this()->setWebhook($url)->max_connections(40)->send();
// or
$cert=bot::loadFile('certificate.txt');
bot::this()
->setWebhook($url)
->certificate($cert)
->allowed_updates($array)
->send();
$res=bot::this()->getWebhookInfo()->send();
echo $res;