Skip to content

Commit 690b712

Browse files
committed
[Notifier] added telegram options
1 parent 2460ca5 commit 690b712

11 files changed

+416
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
*/
17+
abstract class AbstractTelegramReplyMarkup
18+
{
19+
protected $options = [];
20+
21+
public function toArray(): array
22+
{
23+
return $this->options;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
*/
17+
abstract class AbstractKeyboardButton
18+
{
19+
protected $options = [];
20+
21+
public function toArray(): array
22+
{
23+
return $this->options;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
* @see https://core.telegram.org/bots/api#inlinekeyboardbutton
17+
*/
18+
class InlineKeyboardButton extends AbstractKeyboardButton
19+
{
20+
public function __construct(string $text = '')
21+
{
22+
$this->options['text'] = $text;
23+
}
24+
25+
public function url(string $url): self
26+
{
27+
$this->options['url'] = $url;
28+
29+
return $this;
30+
}
31+
32+
public function loginUrl(string $url): self
33+
{
34+
$this->options['login_url']['url'] = $url;
35+
36+
return $this;
37+
}
38+
39+
public function loginUrlForwardText(string $text): self
40+
{
41+
$this->options['login_url']['forward_text'] = $text;
42+
43+
return $this;
44+
}
45+
46+
public function requestWriteAccess(bool $bool): self
47+
{
48+
$this->options['login_url']['request_write_access'] = $bool;
49+
50+
return $this;
51+
}
52+
53+
public function callbackData(string $data): self
54+
{
55+
$this->options['callback_data'] = $data;
56+
57+
return $this;
58+
}
59+
60+
public function switchInlineQuery(string $query): self
61+
{
62+
$this->options['switch_inline_query'] = $query;
63+
64+
return $this;
65+
}
66+
67+
public function payButton(bool $bool): self
68+
{
69+
$this->options['pay'] = $bool;
70+
71+
return $this;
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
* @see https://core.telegram.org/bots/api#keyboardbutton
17+
*/
18+
class KeyboardButton extends AbstractKeyboardButton
19+
{
20+
public function __construct(string $text)
21+
{
22+
$this->options['text'] = $text;
23+
}
24+
25+
public function requestContact(bool $bool): self
26+
{
27+
$this->options['request_contact'] = $bool;
28+
29+
return $this;
30+
}
31+
32+
public function requestLocation(bool $bool): self
33+
{
34+
$this->options['request_location'] = $bool;
35+
36+
return $this;
37+
}
38+
39+
public function requestPollType(string $type): self
40+
{
41+
$this->options['request_contact']['type'] = $type;
42+
43+
return $this;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
* @see https://core.telegram.org/bots/api#forcereply
17+
*/
18+
class ForceReply extends AbstractTelegramReplyMarkup
19+
{
20+
public function __construct(bool $forceReply = false, bool $selective = false)
21+
{
22+
$this->options['force_reply'] = $forceReply;
23+
$this->options['selective'] = $selective;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;
13+
14+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton;
15+
16+
/**
17+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
18+
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
19+
*/
20+
class InlineKeyboardMarkup extends AbstractTelegramReplyMarkup
21+
{
22+
public function __construct()
23+
{
24+
$this->options['inline_keyboard'] = [];
25+
}
26+
27+
/**
28+
* @param array|InlineKeyboardButton[] $buttons
29+
*/
30+
public function inlineKeyboard(array $buttons): self
31+
{
32+
$buttons = \array_map(static function (InlineKeyboardButton $button) {
33+
return $button->toArray();
34+
}, $buttons);
35+
36+
$this->options['inline_keyboard'][] = $buttons;
37+
return $this;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;
13+
14+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\KeyboardButton;
15+
16+
/**
17+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
18+
* @see https://core.telegram.org/bots/api#replykeyboardmarkup
19+
*/
20+
class ReplyKeyboardMarkup extends AbstractTelegramReplyMarkup
21+
{
22+
public function __construct()
23+
{
24+
$this->options['keyboard'] = [];
25+
}
26+
27+
public function keyboard(array $buttons): self
28+
{
29+
$buttons = \array_map(static function (KeyboardButton $button) {
30+
return $button->toArray();
31+
}, $buttons);
32+
33+
$this->options['keyboard'][] = $buttons;
34+
35+
return $this;
36+
}
37+
38+
public function resizeKeyboard(bool $bool): self
39+
{
40+
$this->options['resize_keyboard'] = $bool;
41+
42+
return $this;
43+
}
44+
45+
public function oneTimeKeyboard(bool $bool): self
46+
{
47+
$this->options['one_time_keyboard'] = $bool;
48+
49+
return $this;
50+
}
51+
52+
public function selective(bool $bool): self
53+
{
54+
$this->options['selective'] = $bool;
55+
56+
return $this;
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup;
13+
14+
/**
15+
* @author Mihail Krasilnikov <mihail.krasilnikov.j@gmail.com>
16+
* @see https://core.telegram.org/bots/api#replykeyboardremove
17+
*/
18+
class ReplyKeyboardRemove extends AbstractTelegramReplyMarkup
19+
{
20+
public function __construct(bool $removeKeyboard = false, bool $selective = false)
21+
{
22+
$this->options['remove_keyboard'] = $removeKeyboard;
23+
$this->options['selective'] = $selective;
24+
}
25+
}

0 commit comments

Comments
 (0)