Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @experimental in 5.2
*/
abstract class AbstractTelegramReplyMarkup
{
protected $options = [];

public function toArray(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @experimental in 5.2
*/
abstract class AbstractKeyboardButton
{
protected $options = [];

public function toArray(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#inlinekeyboardbutton
*
* @experimental in 5.2
*/
final class InlineKeyboardButton extends AbstractKeyboardButton
{
public function __construct(string $text = '')
{
$this->options['text'] = $text;
}

public function url(string $url): self
{
$this->options['url'] = $url;

return $this;
}

public function loginUrl(string $url): self
{
$this->options['login_url']['url'] = $url;

return $this;
}

public function loginUrlForwardText(string $text): self
{
$this->options['login_url']['forward_text'] = $text;

return $this;
}

public function requestWriteAccess(bool $bool): self
{
$this->options['login_url']['request_write_access'] = $bool;

return $this;
}

public function callbackData(string $data): self
{
$this->options['callback_data'] = $data;

return $this;
}

public function switchInlineQuery(string $query): self
{
$this->options['switch_inline_query'] = $query;

return $this;
}

public function payButton(bool $bool): self
{
$this->options['pay'] = $bool;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#keyboardbutton
*
* @experimental in 5.2
*/
final class KeyboardButton extends AbstractKeyboardButton
{
public function __construct(string $text)
{
$this->options['text'] = $text;
}

public function requestContact(bool $bool): self
{
$this->options['request_contact'] = $bool;

return $this;
}

public function requestLocation(bool $bool): self
{
$this->options['request_location'] = $bool;

return $this;
}

public function requestPollType(string $type): self
{
$this->options['request_contact']['type'] = $type;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#forcereply
*
* @experimental in 5.2
*/
final class ForceReply extends AbstractTelegramReplyMarkup
{
public function __construct(bool $forceReply = false, bool $selective = false)
{
$this->options['force_reply'] = $forceReply;
$this->options['selective'] = $selective;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;

use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
*
* @experimental in 5.2
*/
final class InlineKeyboardMarkup extends AbstractTelegramReplyMarkup
{
public function __construct()
{
$this->options['inline_keyboard'] = [];
}

/**
* @param array|InlineKeyboardButton[] $buttons
*/
public function inlineKeyboard(array $buttons): self
{
$buttons = array_map(static function (InlineKeyboardButton $button) {
return $button->toArray();
}, $buttons);

$this->options['inline_keyboard'][] = $buttons;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;

use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\KeyboardButton;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#replykeyboardmarkup
*
* @experimental in 5.2
*/
final class ReplyKeyboardMarkup extends AbstractTelegramReplyMarkup
{
public function __construct()
{
$this->options['keyboard'] = [];
}

/**
* @param array|KeyboardButton[] $buttons
*
* @return $this
*/
public function keyboard(array $buttons): self
{
$buttons = array_map(static function (KeyboardButton $button) {
return $button->toArray();
}, $buttons);

$this->options['keyboard'][] = $buttons;

return $this;
}

public function resizeKeyboard(bool $bool): self
{
$this->options['resize_keyboard'] = $bool;

return $this;
}

public function oneTimeKeyboard(bool $bool): self
{
$this->options['one_time_keyboard'] = $bool;

return $this;
}

public function selective(bool $bool): self
{
$this->options['selective'] = $bool;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;

/**
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
*
* @see https://core.telegram.org/bots/api#replykeyboardremove
*
* @experimental in 5.2
*/
final class ReplyKeyboardRemove extends AbstractTelegramReplyMarkup
{
public function __construct(bool $removeKeyboard = false, bool $selective = false)
{
$this->options['remove_keyboard'] = $removeKeyboard;
$this->options['selective'] = $selective;
}
}
Loading