Skip to content

Commit cfa3d1f

Browse files
committed
Add bot token per notification support.
Closes #84.
1 parent a4b5b52 commit cfa3d1f

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/TelegramChannel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function __construct(Telegram $telegram)
3131
* @param mixed $notifiable
3232
* @param Notification $notification
3333
*
34+
* @throws CouldNotSendNotification
3435
* @return null|array
3536
*
36-
* @throws CouldNotSendNotification
3737
*/
3838
public function send($notifiable, Notification $notification): ?array
3939
{
@@ -51,6 +51,10 @@ public function send($notifiable, Notification $notification): ?array
5151
$message->to($to);
5252
}
5353

54+
if ($message->hasToken()) {
55+
$this->telegram->setToken($message->token);
56+
}
57+
5458
$params = $message->toArray();
5559

5660
if ($message instanceof TelegramMessage) {

src/Traits/HasSharedLogic.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ trait HasSharedLogic
1313
/** @var array Inline Keyboard Buttons. */
1414
protected $buttons = [];
1515

16+
/** @var string Bot Token. */
17+
public $token;
18+
1619
/**
1720
* Recipient's Chat ID.
1821
*
19-
* @param $chatId
22+
* @param string|int $chatId
2023
*
2124
* @return $this
2225
*/
@@ -36,7 +39,7 @@ public function to($chatId): self
3639
*
3740
* @return $this
3841
*/
39-
public function button($text, $url, $columns = 2): self
42+
public function button(string $text, string $url, int $columns = 2): self
4043
{
4144
$this->buttons[] = compact('text', 'url');
4245

@@ -52,6 +55,7 @@ public function button($text, $url, $columns = 2): self
5255
* Users will receive a notification with no sound.
5356
*
5457
* @param bool $disableNotification
58+
*
5559
* @return $this
5660
*/
5761
public function disableNotification(bool $disableNotification = true): self
@@ -61,6 +65,31 @@ public function disableNotification(bool $disableNotification = true): self
6165
return $this;
6266
}
6367

68+
/**
69+
* Bot Token.
70+
* Overrides default bot token with the given value for this notification.
71+
*
72+
* @param string $token
73+
*
74+
* @return $this
75+
*/
76+
public function token(string $token): self
77+
{
78+
$this->token = $token;
79+
80+
return $this;
81+
}
82+
83+
/**
84+
* Determine if bot token is given for this notification.
85+
*
86+
* @return bool
87+
*/
88+
public function hasToken(): bool
89+
{
90+
return null !== $this->token;
91+
}
92+
6493
/**
6594
* Additional options to pass to sendMessage method.
6695
*

0 commit comments

Comments
 (0)