Skip to content

Commit 738d2ca

Browse files
committed
Add method to get bot user_id from API token
1 parent 9fe0e0b commit 738d2ca

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/Telegram.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ class Telegram
3737
*
3838
* @var string
3939
*/
40-
protected $api_key = '';
40+
protected $api_key = null;
4141

4242
/**
4343
* Telegram Bot name
4444
*
4545
* @var string
4646
*/
47-
protected $bot_name = '';
47+
protected $bot_name = null;
48+
49+
/**
50+
* Telegram Bot user_id
51+
*
52+
* @var string
53+
*/
54+
protected $bot_user_id = null;
4855

4956
/**
5057
* Raw request data (json) for webhook methods
@@ -135,6 +142,9 @@ public function __construct($api_key, $bot_name)
135142
$this->api_key = $api_key;
136143
$this->bot_name = $bot_name;
137144

145+
//Retrieves the bot user_id from the token
146+
$this->bot_user_id = explode(':', $this->api_key)[0];
147+
138148
//Set default download and upload path
139149
$this->setDownloadPath(BASE_PATH . '/../Download');
140150
$this->setUploadPath(BASE_PATH . '/../Upload');
@@ -318,7 +328,9 @@ public function handleGetUpdatesCore($offset, $limit = null, $timeout = null)
318328

319329
if ($response->isOk()) {
320330
//Process all updates
331+
$a = 1;
321332
foreach ((array) $response->getResult() as $result) {
333+
//print($result);
322334
$this->processUpdate($result);
323335
}
324336
}
@@ -680,6 +692,16 @@ public function getBotName()
680692
return $this->bot_name;
681693
}
682694

695+
/**
696+
* Get Bot user_id
697+
*
698+
* @return int
699+
*/
700+
public function getBotUserId() : int
701+
{
702+
return $this->bot_user_id;
703+
}
704+
683705
/**
684706
* Get Version
685707
*

0 commit comments

Comments
 (0)