404

[ Avaa Bypassed ]




Upload:

Command:

botdev@18.223.3.50: ~ $
<?php // we are on git saeed
class Bot {
	
	public $BOT_TOKEN;
	private $API_URL;
	private $WEBHOOK_URL;
	public $botUsername;
	public $debug;
	public $TG;
	function __construct($botUsername,$botToken,$webhookUrl) {
		$this->botUsername = $botUsername;
		$this->BOT_TOKEN = $botToken;
		$this->WEBHOOK_URL = $webhookUrl;
		$this->API_URL = 'https://api.telegram.org/bot' . $this->BOT_TOKEN . '/';
		
// 		$botme=$this->getMe();
// 		$testMessage  =  var_export($botme, true);
// 		file_put_contents("testbot2.html", $testMessage, FILE_APPEND | LOCK_EX);
		
	}
	public function setTG($tg){
		$this->TG = $tg;
	}
	public function apiRequestWebhook($method, $parameters) {
		if (! is_string ( $method )) {
			error_log ( "Method name must be a string\n" );
			return false;
		}
		
		if (! $parameters) {
			$parameters = array ();
		} else if (! is_array ( $parameters )) {
			error_log ( "Parameters must be an array\n" );
			return false;
		}
		
		$parameters ["method"] = $method;
		if($_SERVER['SERVER_NAME']!="unittest"){
			header ( "Content-Type: application/json" );
		}
		echo json_encode ( $parameters );
		return true;
	}
	public function getMe(){
		$this->apiRequest( 'getMe', array (
				'get' => "true"
		) );
		
	}
	public function setWebhook(){
		return $this->apiRequest( 'setWebhook', array (
				'url' => $this->WEBHOOK_URL
		) );
		
	}
	public function deleteWebhook(){
		$this->apiRequest( 'deleteWebhook', array (
				'url' => $this->WEBHOOK_URL
		) );
		
	}
	public function WebhookInfo(){
	echo	$this->apiRequest( 'WebhookInfo');
		
	}
	public function exec_curl_request($handle, $method) {

		$response = curl_exec ( $handle );

		if ($response === false) {
			$errno = curl_errno ( $handle );
			$error = curl_error ( $handle );
			print_r($error);
			throw new Exception($error);
			error_log ( "Curl returned error $errno: $error\n" );
			curl_close ( $handle );
			return false;
		}
		if($method == "sendVoice"){
			print_r($response);
		}
		$http_code = intval ( curl_getinfo ( $handle, CURLINFO_HTTP_CODE ) );
		curl_close ( $handle );
		
		if ($http_code >= 500) {
			// do not wat to DDOS server if something goes wrong
			sleep ( 10 );
			return false;
		} else if ($http_code != 200) {
			$response = json_decode ( $response, true );
			error_log ( "Request has failed with error {$response['error_code']}: {$response['description']}\n" );
			if ($http_code == 401) {
				throw new Exception ( 'Invalid access token provided' );
			}
			return false;
		} else {
			$response = json_decode ( $response, true );
			if (isset ( $response ['description'] )) {
				error_log ( "Request was successfull: {$response['description']}\n" );
			}
			$response = $response ['result'];
		}

		return $response;
	}
	public function apiRequest($method, $parameters) {
		// print_r($parameters);

		if (! is_string ( $method )) {
			error_log ( "Method name must be a string\n" );
			return false;
		}

		if (! $parameters) {
			$parameters = array ();
		} else if (! is_array ( $parameters )) {
			error_log ( "Parameters must be an array\n" );
			return false;
		}

		foreach ( $parameters as $key => &$val ) {
			// encoding to JSON array parameters, for example reply_markup
			if (! is_numeric ( $val ) && ! is_string ( $val )) {
				$val = json_encode ( $val );
			}
		}
	    $url = $this->API_URL . $method . '?' . http_build_query ( $parameters );
		if($method == "sendVoice"){
			echo "sending audio";
		}
		if($method == "sendVoice"){
			print_r($url);
		}
		$handle = curl_init ( $url );
		curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, true );
		curl_setopt ( $handle, CURLOPT_CONNECTTIMEOUT, 150 );
		curl_setopt ( $handle, CURLOPT_TIMEOUT, 220 );
		$result = $this->executeCurl($handle, $method);
		return $result;
		
	}
	public function executeCurl($handle, $method){
		return $this->exec_curl_request($handle, $method);
	}
	public function apiRequestJson($method, $parameters) {
		if (! is_string ( $method )) {
			error_log ( "Method name must be a string\n" );
			return false;
		}
		
		if (! $parameters) {
			$parameters = array ();
		} else if (! is_array ( $parameters )) {
			error_log ( "Parameters must be an array\n" );
			return false;
		}
		
		$parameters ["method"] = $method;
		print_r($parameters);
		$handle = curl_init ( $this->API_URL . $method );
		curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, true );
		curl_setopt ( $handle, CURLOPT_CONNECTTIMEOUT, 5 );
		curl_setopt( $handle, CURLOPT_POST, 1);
		curl_setopt ( $handle, CURLOPT_TIMEOUT, 60 );
		curl_setopt ( $handle, CURLOPT_POSTFIELDS, json_encode ( $parameters ) );
		curl_setopt ( $handle, CURLOPT_HTTPHEADER, array (
				"Content-Type: application/json" 
		) );
		
		return $this->exec_curl_request ( $handle, $method );
	}
}



?>

Filemanager

Name Type Size Permission Actions
Bot.php File 4.63 KB 0755
MessageProcessor.php File 19.88 KB 0755