<?php


class TelegramBot{
	public $api = "https://api.telegram.org/bot";
    public $token;
	
	public function __construct($token){
	$this->token = $token;
	}
	
	public function sendSticker($chat_id , $sticker){
	return $this->request("sendSticker" , array('chat_id' => $chat_id , 'sticker' => $sticker ));
	}
	
	public function sendMessage($chat_id , $message, $keyboard = array()){
	return $this->request("sendMessage" , array('chat_id' => $chat_id , 'text' => $message , 'parse_mode' => 'html',  'reply_markup' => $keyboard));
	}
	
	public function sendReplyMessage($chat_id , $message , $message_id){
    return $this->request("sendMessage"  , array('chat_id' => $chat_id , 'text' => $message , 'reply_to_message_id' => $message_id , 'parse_mode' => 'html'));	
	}
	
	public function getChatMembersCount($chat_id){
	$rq = $this->request("getChatMembersCount" , array('chat_id' => $chat_id));
	$json = json_decode($rq , TRUE);
	return $json['result'];
	}
	
	public function getChatMember($chat_id , $user_id){
	$rq = $this->request("getChatMember" , array('chat_id' => $chat_id , 'user_id' => $user_id));
	return $rq;
	}    
	public function getChatAdministrators($chat_id){
	$rq = $this->request("getChatAdministrators" , array('chat_id' => $chat_id));
	return $rq; 
	}
	
	public function kickChatMember($chat_id , $user_id){
	$rq = $this->request("kickChatMember" , array('chat_id' => $chat_id , 'user_id' => $user_id));
	return $rq; 
	}

	public function editMessageText($chat_id , $message , $message_id){
	$rq = $this->request("editMessageText" , array('chat_id' => $chat_id , 'message_id' => $message_id , 'text' => $message , 'parse_mode' => 'html'));
	//return $rq; 
	}


    // function request made by baddev
	function request($method , $args ){
		$url = $this->api.$this->token."/".$method;

		$fields_string = http_build_query($args);
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL, $url);
		curl_setopt($ch,CURLOPT_POST, true);
		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
		
		$result = curl_exec($ch);
        file_put_contents("log_req.txt", print_r($result));
		return $result;
	}
	
}