Skip to content

Commit 9405781

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

File tree

11 files changed

+423
-9
lines changed

11 files changed

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

0 commit comments

Comments
 (0)