PHP code example of saber13812002 / telegram-bale-bot-php

1. Go to this page and download the library: Download saber13812002/telegram-bale-bot-php 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/ */

    

saber13812002 / telegram-bale-bot-php example snippets




$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$bale = new Telegram('YOUR TELEGRAM TOKEN HERE', 'bale');



$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$bale = new Telegram('YOUR TELEGRAM TOKEN HERE', 'bale');

$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$bale = new Telegram('YOUR TELEGRAM TOKEN HERE', 'bale');

$chat_id = $telegram->ChatID();
$chat_id_bale = $bale->ChatID();
$content = array('chat_id' => $chat_id, 'text' => 'Test');
$content_bale = array('chat_id' => $chat_id_bale, 'text' => 'Test');
$telegram->sendMessage($content);
$bale->sendMessage($content_bale);

$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');
$bale = new Telegram('YOUR TELEGRAM TOKEN HERE', 'bale');

$result = $telegram->getData();
$result_bale = $bale->getData();
$text = $result['message'] ['text'];
$text_bale = $result_bale['message'] ['text'];
$chat_id = $result['message'] ['chat']['id'];
$chat_id_bale = $result_bale['message'] ['chat']['id'];
$content = array('chat_id' => $chat_id, 'text' => 'Test');
$content_bale = array('chat_id' => $chat_id_bale, 'text' => 'Test');
$telegram->sendMessage($content);
$bale->sendMessage($content_bale);

// Load a local file to upload. If is already on Telegram's Servers just pass the resource id
$img = curl_file_create('test.png','image/png'); 
$content = array('chat_id' => $chat_id, 'photo' => $img );
$telegram->sendPhoto($content);

$file = $telegram->getFile($file_id);
$telegram->downloadFile($file['result']['file_path'], './my_downloaded_file_on_local_server.png');

$telegram = new Telegram('YOUR TELEGRAM TOKEN HERE');

$req = $telegram->getUpdates();

for ($i = 0; $i < $telegram-> UpdateCount(); $i++) {
	// You NEED to call serveUpdate before accessing the values of message in Telegram Class
	$telegram->serveUpdate($i);
	$text = $telegram->Text();
	$chat_id = $telegram->ChatID();

	if ($text == '/start') {
		$reply = 'Working';
		$content = array('chat_id' => $chat_id, 'text' => $reply);
		$telegram->sendMessage($content);
	}
	// DO OTHER STUFF
}

$option = array( 
    //First row
    array($telegram->buildKeyboardButton("Button 1"), $telegram->buildKeyboardButton("Button 2")), 
    //Second row 
    array($telegram->buildKeyboardButton("Button 3"), $telegram->buildKeyboardButton("Button 4"), $telegram->buildKeyboardButton("Button 5")), 
    //Third row
    array($telegram->buildKeyboardButton("Button 6")) );
$keyb = $telegram->buildKeyBoard($option, $onetime=false);
$content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "This is a Keyboard Test");
$telegram->sendMessage($content);

$option = array( 
    //First row
    array($telegram->buildInlineKeyBoardButton("Button 1", $url="http://link1.com"), $telegram->buildInlineKeyBoardButton("Button 2", $url="http://link2.com")), 
    //Second row 
    array($telegram->buildInlineKeyBoardButton("Button 3", $url="http://link3.com"), $telegram->buildInlineKeyBoardButton("Button 4", $url="http://link4.com"), $telegram->buildInlineKeyBoardButton("Button 5", $url="http://link5.com")), 
    //Third row
    array($telegram->buildInlineKeyBoardButton("Button 6", $url="http://link6.com")) );
$keyb = $telegram->buildInlineKeyBoard($option);
$content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "This is a Keyboard Test");
$telegram->sendMessage($content);

buildKeyBoard(array $options, $onetime=true, $resize=true, $selective=true)

buildInlineKeyBoard(array $inline_keyboard)

buildInlineKeyBoardButton($text, $url, $callback_data, $switch_inline_query)

buildKeyBoardButton($text, $url, $request_contact, $request_location)

buildKeyBoardHide($selective=true)

buildForceReply($selective=true)

composer 

php composer.phar