Skip to content
New issue

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

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

Already on GitHub? # to your account

add ability to change default behaiveor #185

Merged
merged 9 commits into from
Jan 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Telegram
/** @var string Telegram Bot API Base URI */
protected string $apiBaseUri;

public function __construct(string $token = null, HttpClient $httpClient = null, string $apiBaseUri = null)
public function __construct(?string $token = null, ?HttpClient $httpClient = null, ?string $apiBaseUri = null)
{
$this->token = $token;
$this->http = $httpClient ?? new HttpClient();
Expand Down
4 changes: 2 additions & 2 deletions src/TelegramFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function content(string $content): self
* @param resource|StreamInterface|string $file
* @return $this
*/
public function file(mixed $file, string $type, string $filename = null): self
public function file(mixed $file, string $type, ?string $filename = null): self
{
$this->type = $type;

Expand Down Expand Up @@ -102,7 +102,7 @@ public function audio(string $file): self
*
* @return $this
*/
public function document(string $file, string $filename = null): self
public function document(string $file, ?string $filename = null): self
{
return $this->file($file, 'document', $filename);
}
Expand Down
2 changes: 1 addition & 1 deletion src/TelegramMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function create(string $content = ''): self
*
* @return $this
*/
public function content(string $content, int $limit = null): self
public function content(string $content, ?int $limit = null): self
{
$this->payload['text'] = $content;

Expand Down
29 changes: 29 additions & 0 deletions src/Traits/HasSharedLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NotificationChannels\Telegram\Traits;

use Illuminate\Support\Traits\Conditionable;
use InvalidArgumentException;

/**
* Trait HasSharedLogic.
Expand Down Expand Up @@ -50,6 +51,34 @@ public function keyboardMarkup(array $markup): self
return $this;
}

/**
* unsets parse mode of the message.
*
* @return static
*/
public function normal()
{
unset($this->payload['parse_mode']);

return $this;
}

/**
* Sets parse mode of the message.
*
* @return static
*/
public function parseMode(?string $mode = null)
{
if (isset($mode) and ! in_array($mode, $allowed = ['Markdown', 'HTML', 'MarkdownV2'])) {
throw new InvalidArgumentException("Invalid aggregate type [$mode], allowed types: [".implode(', ', $allowed).'].');
}

$this->payload['parse_mode'] = $mode;

return $this;
}

/**
* Add a normal keyboard button.
*
Expand Down