Skip to content

Commit 1a8fb29

Browse files
committed
Initial move to a dedicated example repository.
1 parent b4e83a6 commit 1a8fb29

Some content is hidden

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

43 files changed

+3103
-4
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
composer.phar
22
/vendor/
3-
4-
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
3+
composer.lock

Commands/CallbackqueryCommand.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
* @var string
23+
*/
24+
protected $name = 'callbackquery';
25+
26+
/**
27+
* @var string
28+
*/
29+
protected $description = 'Reply to callback query';
30+
31+
/**
32+
* @var string
33+
*/
34+
protected $version = '1.1.0';
35+
36+
/**
37+
* Command execute method
38+
*
39+
* @return \Longman\TelegramBot\Entities\ServerResponse
40+
* @throws \Longman\TelegramBot\Exception\TelegramException
41+
*/
42+
public function execute()
43+
{
44+
$update = $this->getUpdate();
45+
$callback_query = $update->getCallbackQuery();
46+
$callback_query_id = $callback_query->getId();
47+
$callback_data = $callback_query->getData();
48+
49+
$data = [
50+
'callback_query_id' => $callback_query_id,
51+
'text' => 'Hello World!',
52+
'show_alert' => $callback_data === 'thumb up',
53+
'cache_time' => 5,
54+
];
55+
56+
return Request::answerCallbackQuery($data);
57+
}
58+
}

Commands/CancelCommand.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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\Conversation;
15+
use Longman\TelegramBot\Entities\Keyboard;
16+
use Longman\TelegramBot\Request;
17+
18+
/**
19+
* User "/cancel" command
20+
*
21+
* This command cancels the currently active conversation and
22+
* returns a message to let the user know which conversation it was.
23+
* If no conversation is active, the returned message says so.
24+
*/
25+
class CancelCommand extends UserCommand
26+
{
27+
/**
28+
* @var string
29+
*/
30+
protected $name = 'cancel';
31+
32+
/**
33+
* @var string
34+
*/
35+
protected $description = 'Cancel the currently active conversation';
36+
37+
/**
38+
* @var string
39+
*/
40+
protected $usage = '/cancel';
41+
42+
/**
43+
* @var string
44+
*/
45+
protected $version = '0.2.0';
46+
47+
/**
48+
* @var bool
49+
*/
50+
protected $need_mysql = true;
51+
52+
/**
53+
* Command execute method
54+
*
55+
* @return \Longman\TelegramBot\Entities\ServerResponse
56+
* @throws \Longman\TelegramBot\Exception\TelegramException
57+
*/
58+
public function execute()
59+
{
60+
$text = 'No active conversation!';
61+
62+
//Cancel current conversation if any
63+
$conversation = new Conversation(
64+
$this->getMessage()->getFrom()->getId(),
65+
$this->getMessage()->getChat()->getId()
66+
);
67+
68+
if ($conversation_command = $conversation->getCommand()) {
69+
$conversation->cancel();
70+
$text = 'Conversation "' . $conversation_command . '" cancelled!';
71+
}
72+
73+
return $this->removeKeyboard($text);
74+
}
75+
76+
/**
77+
* Remove the keyboard and output a text
78+
*
79+
* @param string $text
80+
*
81+
* @return \Longman\TelegramBot\Entities\ServerResponse
82+
* @throws \Longman\TelegramBot\Exception\TelegramException
83+
*/
84+
private function removeKeyboard($text)
85+
{
86+
return Request::sendMessage(
87+
[
88+
'reply_markup' => Keyboard::remove(['selective' => true]),
89+
'chat_id' => $this->getMessage()->getChat()->getId(),
90+
'text' => $text,
91+
]
92+
);
93+
}
94+
95+
/**
96+
* Command execute method if MySQL is required but not available
97+
*
98+
* @return \Longman\TelegramBot\Entities\ServerResponse
99+
* @throws \Longman\TelegramBot\Exception\TelegramException
100+
*/
101+
public function executeNoDb()
102+
{
103+
return $this->removeKeyboard('Nothing to cancel.');
104+
}
105+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
15+
/**
16+
* Channel chat created command
17+
*/
18+
class ChannelchatcreatedCommand extends SystemCommand
19+
{
20+
/**
21+
* @var string
22+
*/
23+
protected $name = 'Channelchatcreated';
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $description = 'Channel chat created';
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $version = '1.1.0';
34+
35+
/**
36+
* Command execute method
37+
*
38+
* @return \Longman\TelegramBot\Entities\ServerResponse
39+
* @throws \Longman\TelegramBot\Exception\TelegramException
40+
*/
41+
public function execute()
42+
{
43+
//$message = $this->getMessage();
44+
//$channel_chat_created = $message->getChannelChatCreated();
45+
46+
return parent::execute();
47+
}
48+
}

Commands/ChannelpostCommand.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
15+
/**
16+
* Channel post command
17+
*/
18+
class ChannelpostCommand extends SystemCommand
19+
{
20+
/**
21+
* @var string
22+
*/
23+
protected $name = 'Channelpost';
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $description = 'Handle channel post';
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $version = '1.0.0';
34+
35+
/**
36+
* Command execute method
37+
*
38+
* @return \Longman\TelegramBot\Entities\ServerResponse
39+
* @throws \Longman\TelegramBot\Exception\TelegramException
40+
*/
41+
public function execute()
42+
{
43+
//$channel_post = $this->getUpdate()->getChannelPost();
44+
45+
return parent::execute();
46+
}
47+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
15+
/**
16+
* Chosen inline result command
17+
*/
18+
class ChoseninlineresultCommand extends SystemCommand
19+
{
20+
/**
21+
* @var string
22+
*/
23+
protected $name = 'choseninlineresult';
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $description = 'Chosen result query';
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $version = '1.1.0';
34+
35+
/**
36+
* Command execute method
37+
*
38+
* @return \Longman\TelegramBot\Entities\ServerResponse
39+
* @throws \Longman\TelegramBot\Exception\TelegramException
40+
*/
41+
public function execute()
42+
{
43+
//Information about chosen result is returned
44+
//$update = $this->getUpdate();
45+
//$inline_query = $update->getChosenInlineResult();
46+
//$query = $inline_query->getQuery();
47+
48+
return parent::execute();
49+
}
50+
}

0 commit comments

Comments
 (0)