<?php

class Telegram 
{
    private $token;
    public function __construct($token)
    {
        $this->token = $token;
    }
    
    public function req($method, $post=[])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot{$this->token}/{$method}");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        return json_decode(curl_exec($ch));
    }
    
    public function deleteMessage($post= [])
    {
        return $this->req('deleteMessage', $post);
    }
    
    public function forwardMessage($post= [])
    {
        return $this->req('forwardMessage', $post);
    }
    
    public function copyMessage($post= [])
    {
        return $this->req('copyMessage', $post);
    }
    
    public function editMessage($post= [])
    {
        return $this->req('editMessageText', $post);
    }
    
    public function sendMessage($post= [])
    {
        return $this->req('sendMessage', $post);
    }
    
    public function sendPhoto($post= [])
    {
        return $this->req('sendPhoto', $post);
    }
    
    public function sendVideo($post= [])
    {
        return $this->req('sendVideo', $post);
    }
    
    public function sendAnimation($post= [])
    {
        return $this->req('sendAnimation', $post);
    }
    
    public function sendVoice($post= [])
    {
        return $this->req('sendVoice', $post);
    }
    
    public function sendAudio($post= [])
    {
        return $this->req('sendAudio', $post);
    }
    
    public function sendDocument($post= [])
    {
        return $this->req('sendDocument', $post);
    }
    
    public function getMe($post= [])
    {
        return $this->req('getMe', $post);
    }
    
    public function JoinCheck($userId, $channel=[])
    {
        foreach($channel as $_channel)
        {
            $status= $this->req('getChatMember', ['chat_id'=> $_channel, 'user_id'=> $userId])->result->status;
            if($status== 'left')
            {
                return true;
                break;
            }
        }
    }
}
