Code Monkey home page Code Monkey logo

Telegram Robot Library PHP Composer

Latest Stable Version Total Downloads


Botfire is a modern library that is used to build different types of Telegram bot projects. Likewise, a dedicated framework has been created for this purpose, which doubles the simplicity of construction and development


Install Botfire Library

composer require botfire/botfire

use

use botfire\botfire\bot;

Set Token

bot::token('your-bot-token');
bot::autoInput();

Webhook

Set Webhook

$result = bot::webhook()->url( $url )->set();

Get Webhook

$get = bot::webhook()->getInfo();

echo $get;

Message

Send Message

bot::id($chat_id)->message('...')->send();

// auto set chat_id
bot::this()->message('...')->send();

Send Photo

bot::id($chat->id)->photo($file_id)->send();

Send Audio

bot::id($chat->id)->audio($file_id)->send();

Send Voice

bot::id($chat->id)->voice($file_id)->send();

Send Video Note

bot::id($chat->id)->videoNote($file_id)->send();

Send Video

bot::id($chat->id)->video($file_id)->send();

Send Animation

bot::id($chat->id)->animation($file_id)->send();

Send Document

bot::id($chat->id)->document($file_id)->send();

Send Contact

bot::id($chat->id)->contact($phone_number,$first_name,$last_name)->send();

Send chat action

bot::id($chat->id)->chatAction($action)->send();

'typing','upload_photo','record_video','upload_video','record_audio','upload_audio','upload_document','find_location','record_video_note','upload_video_note'


Send MediaGroup docs


Edit Message

Edit message

bot::id($chat->id)->editMessage('new text')->message_id($msg_id)->send();

Edit caption

bot::id($chat->id)->editCaption('caption text')->message_id($msg_id)->send();

Edit reply markup

$k = bot::keyboard();
$k->btn('hello inline button','callback data')->row();

bot::id($chat->id)->editReplyMarkup()->keyboard( $k )->send();

Delete message

bot::id($chat->id)->deleteMessage()->message_id($msg_id)->send();

Receive user messages via webhook

Get message text

$text = bot::text();

get message caption

$caption = bot::caption();

Get callback data

$data = bot::data();

Get message id

$msg_id = bot::message_id();

Get all message Object

$msg = bot::getMessage();

Get All receive Object

$get = bot::json(); // object

$get = bot::input(); // text

User Type

if( bot::isUser() ){
  // Receive private messages
}
else if( bot::isGroup() ){
  // Receive from super group
}
else if( ! bot::isGroup() && bot::isGroup(true)  ){
  // Receive from normal group
}
else if( bot::isChannel() ){
  // Receive channel post
}

Request Type

if( bot::getCallback() ){
  // When I click on the inline button
  
  $data = bot::data();
  
  //...
}
else {
  // When I send normal text
  // ...
}

Receive edited message

if (bot::getEditedMessage()) {
  // ...
}

// for channel
if(bot::getEditedChannelPost()){
  // ...
}

Answer Callback

Answer

bot::this()->answerCallback()->send();

Answer and send alert

bot::this()->answerCallback(true)->text('hello')->send();

Sender

Get chat info

$chat = bot::chat();

Get From

$from = bot::from();

Keyboard

inline keyboard

$k = bot::keyboard();

$k
->btn('btn name 1','data callback 1')
->btn('btn name 2','data callback 2')
->row()
->btnUrl('btn name 3','https://github.com')
->row();

bot::id(bot::chat()->id)->message('...')->keyboard($k)->send();

markup keyboard

markup($resize_keyboard,$one_time_keyboard,$selective)

example

$k = bot::keyboard();

$k->markup(true)->btn('button name')->row();

bot::id(bot::chat()->id)->message('...')->keyboard($k)->send();

can use autoRow method

$k = bot::keyboard();

foreach($list as $item){
  $k->btn($item->name,$item->value);
}

// Creates two buttons in each row
$k->autoRow(2);

bot::this()->message(...)->keyboard($k)->send();


/*
out:
______________
| btn1 | btn2 |
_______________
| btn3 | btn4 |
*/

send user contatc

$k = bot::keyboard()->markup(true)->contact('Send Phone')->row();

bot::id(bot::chat()->id)->message('Click Send Phone Button')->keyboard($k)->send();

Bot Info

$info = bot::getMe();

bot::id($chat_id)->message($info)->send();

User Profile

method : getUserProfilePhotos($user_id,$offset=null,$limit=null)

sample

$profile = bot::getUserProfilePhotos(bot::chat()->id);

Available message method

usage

bot::this()->photo($file_id)->caption($text)->send();
method ***
caption($text) media message caption
message_id($msg_id)
inline_message_id($inline_msg_id)
callback_query_id($query_id)
parse_mode($type) Send Markdown or HTML
vcard($vcard)
disable_web_page_preview($bool)
disable_notification($bool)
live_period($int) should be between 60 and 86400
reply_to($message_id)
duration($duration)
performer($performer)
title($title)
width($int)
height($int)
supports_streaming($bool)
thumb($thumb)
length($int)
latitude($latitude)
longitude($longitude)
foursquare_id($foursquare_id)
foursquare_type($foursquare_type)

Permissions

setChatPermissions

Use this method to set default chat permissions for all members

bot::this()
      ->setChatPermissions()
      ->can_change_info(false)
      ->send();
/*
| methods : 
|
| can_send_messages(true|false)
| can_send_media_messages(true|false)
| can_send_polls(true|false)
| can_send_other_messages(true|false)
| can_add_web_page_previews(true|false)
| can_change_info(true|false)
| can_invite_users(true|false)
| can_pin_messages(true|false)
|
*/

restrictChatMember($user_id,$until_date=null)

Use this method to restrict a user in a supergroup

bot::this()
    ->restrictChatMember(chat_id)
    ->can_send_polls(false)
    ->send();
/*
| methods : 
|
| can_send_messages(true|false)
| can_send_media_messages(true|false)
| can_send_polls(true|false)
| can_send_other_messages(true|false)
| can_add_web_page_previews(true|false)
| can_change_info(true|false)
| can_invite_users(true|false)
| can_pin_messages(true|false)
|
*/

Bot Fire's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.