Skip to content

Commit da1f79d

Browse files
committed
Merge pull request #151 from jacklul/bots-2-0
Bots 2.0
2 parents b1d24af + b44ff53 commit da1f79d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1762
-242
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Commands\UserCommands;
12+
13+
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Request;
15+
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
16+
17+
/**
18+
* User "/inlinekeyboard" command
19+
*/
20+
class InlinekeyboardCommand extends UserCommand
21+
{
22+
/**#@+
23+
* {@inheritdoc}
24+
*/
25+
protected $name = 'inlinekeyboard';
26+
protected $description = 'Show a custom inline keybord with reply markup';
27+
protected $usage = '/inlinekeyboard';
28+
protected $version = '0.0.1';
29+
/**#@-*/
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function execute()
35+
{
36+
$message = $this->getMessage();
37+
$chat_id = $message->getChat()->getId();
38+
$text = $message->getText(true);
39+
40+
$data = [];
41+
$data['chat_id'] = $chat_id;
42+
$data['text'] = 'Press a Button:';
43+
44+
//Keyboard examples
45+
$inline_keyboards = [];
46+
47+
//0
48+
$inline_keyboard[] = [
49+
[
50+
'text' => '<',
51+
'callback_data' => 'go_left'
52+
],
53+
[
54+
'text' => '^',
55+
'callback_data' => 'go_up'
56+
],
57+
[
58+
'text' => '>',
59+
'callback_data' => 'go_right'
60+
]
61+
];
62+
63+
$inline_keyboards[] = $inline_keyboard;
64+
unset($inline_keyboard);
65+
66+
//1
67+
$inline_keyboard[] = [
68+
[
69+
'text' => 'open google.com',
70+
'url' => 'google.com'
71+
],
72+
[
73+
'text' => 'open youtube.com',
74+
'url' => 'youtube.com'
75+
]
76+
];
77+
78+
$inline_keyboards[] = $inline_keyboard;
79+
unset($inline_keyboard);
80+
81+
//2
82+
$inline_keyboard[] = [
83+
[
84+
'text' => 'search \'test\' inline',
85+
'switch_inline_query' => 'test'
86+
],
87+
[
88+
'text' => 'search \'cats\' inline',
89+
'switch_inline_query' => 'cats'
90+
]
91+
];
92+
$inline_keyboard[] = [
93+
[
94+
'text' => 'search \'earth\' inline',
95+
'switch_inline_query' => 'earth'
96+
],
97+
];
98+
99+
$inline_keyboards[] = $inline_keyboard;
100+
unset($inline_keyboard);
101+
102+
//3
103+
$inline_keyboard[] = [
104+
[
105+
'text' => 'open url',
106+
'url' => 'https://github.com/akalongman/php-telegram-bot'
107+
]
108+
];
109+
$inline_keyboard[] = [
110+
[
111+
'text' => 'switch to inline',
112+
'switch_inline_query' => 'thumb up'
113+
]
114+
];
115+
$inline_keyboard[] = [
116+
[
117+
'text' => 'send callback query',
118+
'callback_data' => 'thumb up'
119+
],
120+
[
121+
'text' => 'send callback query (no alert)',
122+
'callback_data' => 'thumb down'
123+
]
124+
];
125+
126+
$inline_keyboards[] = $inline_keyboard;
127+
unset($inline_keyboard);
128+
129+
$data['reply_markup'] = new InlineKeyboardMarkup(
130+
[
131+
'inline_keyboard' => $inline_keyboards[3],
132+
]
133+
);
134+
135+
return Request::sendMessage($data);
136+
}
137+
}

examples/Commands/KeyboardCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class KeyboardCommand extends UserCommand
2525
protected $name = 'keyboard';
2626
protected $description = 'Show a custom keybord with reply markup';
2727
protected $usage = '/keyboard';
28-
protected $version = '0.0.5';
28+
protected $version = '0.0.6';
2929
/**#@-*/
3030

3131
/**
@@ -49,7 +49,7 @@ public function execute()
4949
$keyboard[] = ['4','5','6'];
5050
$keyboard[] = ['1','2','3'];
5151
$keyboard[] = [' ','0',' '];
52-
52+
5353
$keyboards[] = $keyboard;
5454
unset($keyboard);
5555

@@ -78,6 +78,21 @@ public function execute()
7878
$keyboards[] = $keyboard;
7979
unset($keyboard);
8080

81+
//4 (bots 2.0)
82+
$keyboard[] = [
83+
[
84+
'text' => 'request_contact',
85+
'request_contact' => true
86+
],
87+
[
88+
'text' => 'request_location',
89+
'request_location' => true
90+
]
91+
];
92+
93+
$keyboards[] = $keyboard;
94+
unset($keyboard);
95+
8196
$data['reply_markup'] = new ReplyKeyboardMarkup(
8297
[
8398
'keyboard' => $keyboards[1] ,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Commands\SystemCommands;
12+
13+
use Longman\TelegramBot\Commands\SystemCommand;
14+
use Longman\TelegramBot\Request;
15+
16+
/**
17+
* Callback query command
18+
*/
19+
class CallbackqueryCommand extends SystemCommand
20+
{
21+
/**#@+
22+
* {@inheritdoc}
23+
*/
24+
protected $name = 'callbackquery';
25+
protected $description = 'Reply to callback query';
26+
protected $version = '1.0.0';
27+
/**#@-*/
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function execute()
33+
{
34+
$update = $this->getUpdate();
35+
$callback_query = $update->getCallbackQuery();
36+
$callback_query_id = $callback_query->getId();
37+
$callback_data = $callback_query->getData();
38+
39+
$data['callback_query_id'] = $callback_query_id;
40+
41+
if ($callback_data == 'thumb up') {
42+
$data['text'] = 'Hello World!';
43+
$data['show_alert'] = true;
44+
} else {
45+
$data['text'] = 'Hello World!';
46+
$data['show_alert'] = false;
47+
}
48+
49+
return Request::answerCallbackQuery($data);
50+
}
51+
}

src/Commands/SystemCommands/InlinequeryCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function execute()
3939
$data = ['inline_query_id' => $inline_query->getId()];
4040

4141
$articles = [
42-
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
43-
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
44-
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
42+
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
43+
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
44+
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => [ 'message_text' => $query ] ],
4545
];
4646

4747
$array_article = [];

src/Commands/SystemCommands/LeftchatparticipantCommand.php renamed to src/Commands/SystemCommands/LeftchatmemberCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
use Longman\TelegramBot\Commands\SystemCommand;
1414

1515
/**
16-
* Left chat participant command
16+
* Left chat member command
1717
*/
18-
class LeftchatparticipantCommand extends SystemCommand
18+
class LeftchatmemberCommand extends SystemCommand
1919
{
2020
/**#@+
2121
* {@inheritdoc}
2222
*/
23-
protected $name = 'leftchatparticipant';
24-
protected $description = 'Left Chat Participant';
23+
protected $name = 'Leftchatmember';
24+
protected $description = 'Left Chat Member';
2525
protected $version = '1.0.1';
2626
/**#@-*/
2727

@@ -31,6 +31,6 @@ class LeftchatparticipantCommand extends SystemCommand
3131
/*public function execute()
3232
{
3333
//$message = $this->getMessage();
34-
//$participant = $message->getLeftChatParticipant();
34+
//$member = $message->getLeftChatMember();
3535
}*/
3636
}

src/Commands/SystemCommands/NewchatparticipantCommand.php renamed to src/Commands/SystemCommands/NewchatmemberCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
use Longman\TelegramBot\Request;
1515

1616
/**
17-
* New chat participant command
17+
* New chat member command
1818
*/
19-
class NewchatparticipantCommand extends SystemCommand
19+
class NewchatmemberCommand extends SystemCommand
2020
{
2121
/**#@+
2222
* {@inheritdoc}
2323
*/
24-
protected $name = 'Newchatparticipant';
25-
protected $description = 'New Chat Participant';
24+
protected $name = 'Newchatmember';
25+
protected $description = 'New Chat Member';
2626
protected $version = '1.0.1';
2727
/**#@-*/
2828

@@ -34,12 +34,12 @@ public function execute()
3434
$message = $this->getMessage();
3535

3636
$chat_id = $message->getChat()->getId();
37-
$participant = $message->getNewChatParticipant();
37+
$member = $message->getNewChatMember();
3838

39-
if (strtolower($participant->getUsername()) === strtolower($this->getTelegram()->getBotName())) {
39+
if ($message->botAddedInChat()) {
4040
$text = 'Hi there!';
4141
} else {
42-
$text = 'Hi ' . $participant->tryMention() . '!';
42+
$text = 'Hi ' . $member->tryMention() . '!';
4343
}
4444

4545
$data = [

src/Commands/UserCommands/SurveyCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10+
1011
namespace Longman\TelegramBot\Commands\UserCommands;
1112

1213
use Longman\TelegramBot\Request;

src/Commands/UserCommands/WhoamiCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public function execute()
9191
if ($ServerResponse->isOk()) {
9292
Request::downloadFile($ServerResponse->getResult());
9393
}
94-
9594
} else {
9695
//No Photo just send text
9796
$data['text'] = $caption;

src/ConversationDB.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static function selectConversation($user_id, $chat_id, $limit = null)
6363
$sth->execute();
6464

6565
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
66-
6766
} catch (\Exception $e) {
6867
throw new TelegramException($e->getMessage());
6968
}

0 commit comments

Comments
 (0)