Skip to content

parser fix #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v2.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
'message' => array (
'message_id' => 12345,
'from' => array (
'id' => 123,
'id' => 100,
'is_bot' => false,
'first_name' => 'Yehuda',
'last_name' => 'Eisenberg',
'language_code' => 'en',
),
'chat' => array (
'id' => 123,
'id' => 101,
'first_name' => 'Yehuda',
'last_name' => 'Eisenberg',
'type' => 'private',
Expand All @@ -47,8 +47,8 @@

$bot->setUpdate($update);

var_dump($bot->getUpdate()->update_id);
var_dump($bot->getUpdate()->message);
// var_dump($bot->getUpdate()->update_id);
var_dump($bot->getUpdate());

// $bot->sendMessage($user, $text);

11 changes: 9 additions & 2 deletions src/Objects/TelegramObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
class TelegramObject{
protected $fields = [];

// public function __construct(... $values){
// foreach(array_combine(array_keys($this->fields), $values) as $field => $arg){
// $this->field = $arg;
// }
// }

public function __get($fieldName){
if(isset($this->fields[$fieldName])){
return $this->fields[$fieldName];
}
else{
throw new TelegramException("Field '$fieldName' not defined in class " . __CLASS__);
throw new TelegramException("Field '$fieldName' not defined in class " . get_class($this));
}
}

Expand All @@ -32,7 +38,8 @@ public function __set($fieldName, $value){
$this->fields[$fieldName] = $value;
}
else{
throw new TelegramException("Field '$fieldName' not defined in class " . __CLASS__);
var_dump($this);
throw new TelegramException("Field '$fieldName' not defined in class " . get_class($this));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function walker($arr){

$this->currentObj->$subarrK = $newObject; // creat new sub object to update key

$tmp = $this->currentObj->$subarrK; // put the pointer to previus level in tmp
$tmp = $this->currentObj; // put pointer to previus level in tmp

$this->currentObj = $this->currentObj->$subarrK; // set current object to dipper
$this->walker($subarrV); // walk over the sub object
Expand Down
24 changes: 23 additions & 1 deletion src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ class TelegramBot{

public function __construct($config){
if (PHP_SAPI === 'cli'){
print "cli mode. using getUpdates method"; #TODO add async heandling
print "cli mode. using getUpdates method" . PHP_EOL; #TODO add async heandling

}else{
// using webhook method
$this->setUpdate(json_decode("php://input"), true);

}
}

public function setUpdate($update){
if(gettype($update) == "string" || gettype($update) == "array"){
$this->update = new Parser($update);
}elseif(gettype($update) == "object" && get_class($update) == "YehudaEi\TelegramBots\Objects\Update"){
$this->update = $update;
}else{
throw new TelegramException("Invalid update. update must be an array, json or object");
}
}

Expand Down Expand Up @@ -88,5 +93,22 @@ public function forwardMessage($destChat, $fromChat, $message){
$data["disable_notification"] = $this->bot->config->notification;
$data["message_id"] = $message->message_id;
return $this->exec("forwardMessage", $data);
}
public function sendDocument($chat, $document, $reply_to_message_id, $reply_markup, $caption){
if(get_class($chat) !== "User")
throw new TelegramException("\$chat must be a User");
elseif(get_class($document) !== "Document")
if(!filter_var($document, FILTER_VALIDATE_URL) && !is_link($document) && get_class($document) !== "CURLFile")
throw new TelegramException("\$document must be a Document or an URL or a CURLFile object");

$data['chat'] = $chat;
if(get_class($document) == "Document")
$data['document'] = $document->file_id;
else
$data['document'] = $document;




}
}