Skip to content

Commit 3ba8d8f

Browse files
committed
[Notifier] added telegram options
1 parent 2460ca5 commit 3ba8d8f

File tree

11 files changed

+446
-9
lines changed

11 files changed

+446
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
* @experimental in 5.2
18+
*/
19+
abstract class AbstractTelegramReplyMarkup
20+
{
21+
protected $options = [];
22+
23+
public function toArray(): array
24+
{
25+
return $this->options;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
* @experimental in 5.2
18+
*/
19+
abstract class AbstractKeyboardButton
20+
{
21+
protected $options = [];
22+
23+
public function toArray(): array
24+
{
25+
return $this->options;
26+
}
27+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
* @see https://core.telegram.org/bots/api#inlinekeyboardbutton
18+
*
19+
* @experimental in 5.2
20+
*/
21+
final class InlineKeyboardButton extends AbstractKeyboardButton
22+
{
23+
public function __construct(string $text = '')
24+
{
25+
$this->options['text'] = $text;
26+
}
27+
28+
public function url(string $url): self
29+
{
30+
$this->options['url'] = $url;
31+
32+
return $this;
33+
}
34+
35+
public function loginUrl(string $url): self
36+
{
37+
$this->options['login_url']['url'] = $url;
38+
39+
return $this;
40+
}
41+
42+
public function loginUrlForwardText(string $text): self
43+
{
44+
$this->options['login_url']['forward_text'] = $text;
45+
46+
return $this;
47+
}
48+
49+
public function requestWriteAccess(bool $bool): self
50+
{
51+
$this->options['login_url']['request_write_access'] = $bool;
52+
53+
return $this;
54+
}
55+
56+
public function callbackData(string $data): self
57+
{
58+
$this->options['callback_data'] = $data;
59+
60+
return $this;
61+
}
62+
63+
public function switchInlineQuery(string $query): self
64+
{
65+
$this->options['switch_inline_query'] = $query;
66+
67+
return $this;
68+
}
69+
70+
public function payButton(bool $bool): self
71+
{
72+
$this->options['pay'] = $bool;
73+
74+
return $this;
75+
}
76+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
* @see https://core.telegram.org/bots/api#keyboardbutton
18+
*
19+
* @experimental in 5.2
20+
*/
21+
final class KeyboardButton extends AbstractKeyboardButton
22+
{
23+
public function __construct(string $text)
24+
{
25+
$this->options['text'] = $text;
26+
}
27+
28+
public function requestContact(bool $bool): self
29+
{
30+
$this->options['request_contact'] = $bool;
31+
32+
return $this;
33+
}
34+
35+
public function requestLocation(bool $bool): self
36+
{
37+
$this->options['request_location'] = $bool;
38+
39+
return $this;
40+
}
41+
42+
public function requestPollType(string $type): self
43+
{
44+
$this->options['request_contact']['type'] = $type;
45+
46+
return $this;
47+
}
48+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
* @see https://core.telegram.org/bots/api#forcereply
18+
*
19+
* @experimental in 5.2
20+
*/
21+
final class ForceReply extends AbstractTelegramReplyMarkup
22+
{
23+
public function __construct(bool $forceReply = false, bool $selective = false)
24+
{
25+
$this->options['force_reply'] = $forceReply;
26+
$this->options['selective'] = $selective;
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
*
19+
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
20+
*
21+
* @experimental in 5.2
22+
*/
23+
final class InlineKeyboardMarkup extends AbstractTelegramReplyMarkup
24+
{
25+
public function __construct()
26+
{
27+
$this->options['inline_keyboard'] = [];
28+
}
29+
30+
/**
31+
* @param array|InlineKeyboardButton[] $buttons
32+
*/
33+
public function inlineKeyboard(array $buttons): self
34+
{
35+
$buttons = array_map(static function (InlineKeyboardButton $button) {
36+
return $button->toArray();
37+
}, $buttons);
38+
39+
$this->options['inline_keyboard'][] = $buttons;
40+
41+
return $this;
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
*
19+
* @see https://core.telegram.org/bots/api#replykeyboardmarkup
20+
*
21+
* @experimental in 5.2
22+
*/
23+
final class ReplyKeyboardMarkup extends AbstractTelegramReplyMarkup
24+
{
25+
public function __construct()
26+
{
27+
$this->options['keyboard'] = [];
28+
}
29+
30+
/**
31+
* @param array|KeyboardButton[] $buttons
32+
*
33+
* @return $this
34+
*/
35+
public function keyboard(array $buttons): self
36+
{
37+
$buttons = array_map(static function (KeyboardButton $button) {
38+
return $button->toArray();
39+
}, $buttons);
40+
41+
$this->options['keyboard'][] = $buttons;
42+
43+
return $this;
44+
}
45+
46+
public function resizeKeyboard(bool $bool): self
47+
{
48+
$this->options['resize_keyboard'] = $bool;
49+
50+
return $this;
51+
}
52+
53+
public function oneTimeKeyboard(bool $bool): self
54+
{
55+
$this->options['one_time_keyboard'] = $bool;
56+
57+
return $this;
58+
}
59+
60+
public function selective(bool $bool): self
61+
{
62+
$this->options['selective'] = $bool;
63+
64+
return $this;
65+
}
66+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
* @see https://core.telegram.org/bots/api#replykeyboardremove
18+
*
19+
* @experimental in 5.2
20+
*/
21+
final class ReplyKeyboardRemove extends AbstractTelegramReplyMarkup
22+
{
23+
public function __construct(bool $removeKeyboard = false, bool $selective = false)
24+
{
25+
$this->options['remove_keyboard'] = $removeKeyboard;
26+
$this->options['selective'] = $selective;
27+
}
28+
}

0 commit comments

Comments
 (0)