Skip to content

Commit 815960c

Browse files
committed
Quick reply buttons support
1 parent e95f99c commit 815960c

33 files changed

+605
-874
lines changed

bootstrap/bootstrap.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,52 @@ public function sendMessageToTelegram($params)
667667

668668
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.make_plain_message', array('msg' => & $params['msg']->msg));
669669

670+
$keyboardButtons = [];
671+
672+
$metaMsg = $params['msg']->meta_msg_array;
673+
674+
if (isset($metaMsg['content']['quick_replies']) && !empty($metaMsg['content']['quick_replies'])) {
675+
foreach ($metaMsg['content']['quick_replies'] as $quickReplyButton) {
676+
if ($quickReplyButton['type'] == 'trigger' || $quickReplyButton['type'] == 'button') {
677+
$keyboardButtons[] = [
678+
'text' => $quickReplyButton['content']['name'],
679+
'callback_data' => ($quickReplyButton['type'] == 'button' ? 'bpayload__||' : 'trigger__||') . $quickReplyButton['content']['payload']. '__' . md5($quickReplyButton['content']['name']) .'__'.$params['msg']->id
680+
];
681+
} elseif ($quickReplyButton['type'] == 'url') {
682+
$keyboardButtons[] = [
683+
'text' => $quickReplyButton['content']['name'],
684+
'url' => $quickReplyButton['content']['payload']
685+
];
686+
}
687+
688+
}
689+
}
690+
670691
$data = [
671692
'chat_id' => $tChat->tchat_id,
672-
'text' => trim($params['msg']->msg) . $signatureText,
693+
'text' => trim($params['msg']->msg) . $signatureText
673694
];
674695

675-
Longman\TelegramBot\Request::sendMessage($data);
696+
if (!empty($keyboardButtons)) {
697+
$inline_keyboard = new Longman\TelegramBot\Entities\InlineKeyboard($keyboardButtons);
698+
$inline_keyboard->setOneTimeKeyboard(true);
699+
$inline_keyboard->setIsPersistent(false);
700+
$data['reply_markup'] = $inline_keyboard;
701+
}
702+
703+
$sendData = Longman\TelegramBot\Request::sendMessage($data);
704+
705+
if ($sendData->isOk()) {
706+
$metaMsg['iwh_msg_id'] = $sendData->getResult()->getMessageId();
707+
708+
$params['msg']->meta_msg_array = $metaMsg;
709+
$params['msg']->meta_msg = json_encode($metaMsg);
710+
$params['msg']->del_st = erLhcoreClassModelmsg::STATUS_READ;
711+
712+
if ($params['msg']->id > 0) {
713+
$params['msg']->updateThis(['update' => ['meta_msg','del_st']]);
714+
}
715+
}
676716
}
677717

678718
foreach ($images['images'] as $image) {

classes/Commands/CallbackqueryCommand.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Longman\TelegramBot\Commands\SystemCommand;
1414
use Longman\TelegramBot\Request;
1515
use Longman\TelegramBot\Entities\InlineKeyboard;
16+
use Longman\TelegramBot\Entities\ServerResponse;
1617

1718
/**
1819
* Callback query command
@@ -44,7 +45,7 @@ class CallbackqueryCommand extends SystemCommand
4445
* @return \Longman\TelegramBot\Entities\ServerResponse
4546
* @throws \Longman\TelegramBot\Exception\TelegramException
4647
*/
47-
public function execute()
48+
public function execute(): ServerResponse
4849
{
4950
$callback_query = $this->getCallbackQuery();
5051
$callback_query_id = $callback_query->getId();
@@ -389,6 +390,37 @@ public function execute()
389390
Request::sendMessage($data);
390391
}
391392

393+
} elseif ($paramsCallback[0] == 'bpayload__' || $paramsCallback[0] == 'trigger__') {
394+
395+
/*$data = [
396+
'callback_query_id' => $callback_query_id,
397+
'text' => 'Thanks!',
398+
'show_alert' => $callback_data === 'thumb up',
399+
'cache_time' => 1,
400+
];
401+
402+
Request::answerCallbackQuery($data);*/
403+
404+
$payloadParts = explode('__',$paramsCallback[1]);
405+
406+
$message = \erLhcoreClassModelmsg::fetch($payloadParts[2]);
407+
408+
$chat = \erLhcoreClassModelChat::fetch($message->chat_id);
409+
410+
\Longman\TelegramBot\Commands\SystemCommands\GenericmessageCommand::sendBotResponse($chat, $message, array(
411+
'type' => ($paramsCallback[0] == 'bpayload__' ? 'payload' : 'trigger'),
412+
'payload' => $payloadParts[0] . '__' . $payloadParts[1],
413+
'msg_last_id' => $chat->last_msg_id // Message visitor is clicking is not necessary the last message
414+
));
415+
416+
return Request::send('editMessageReplyMarkup',[
417+
'chat_id' => $callback_query->getFrom()->getId(),
418+
'message_id' => $message->meta_msg_array['iwh_msg_id'],
419+
'reply_markup' => null
420+
]);
421+
422+
return Request::emptyResponse();
423+
392424
} else {
393425
$data = [
394426
'callback_query_id' => $callback_query_id,

classes/Commands/ChangeownerCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Longman\TelegramBot\Request;
1515
use Longman\TelegramBot\Entities\InlineKeyboard;
1616
use Longman\TelegramBot\Entities\InlineKeyboardButton;
17-
17+
use Longman\TelegramBot\Entities\ServerResponse;
1818
/**
1919
* User "/register" command
2020
*
@@ -48,7 +48,7 @@ class ChangeownerCommand extends UserCommand
4848
* @return \Longman\TelegramBot\Entities\ServerResponse
4949
* @throws \Longman\TelegramBot\Exception\TelegramException
5050
*/
51-
public function execute()
51+
public function execute(): ServerResponse
5252
{
5353
$message = $this->getMessage();
5454

@@ -157,8 +157,6 @@ public function execute()
157157
'text' => 'Chat was transferred to:' . PHP_EOL . (string)$operatorDestination->name_official,
158158
];
159159

160-
Request::sendMessage($data);
161-
162160
$transferLegacy = \erLhcoreClassTransfer::getTransferByChat($chat->id);
163161

164162
if (is_array($transferLegacy)) {
@@ -177,7 +175,7 @@ public function execute()
177175

178176
\erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chat_owner_changed', array('chat' => & $chat, 'user' => $operatorDestination));
179177

180-
return ;
178+
return Request::sendMessage($data);
181179
}
182180

183181
$onlineOperators = \erLhcoreClassModelUser::getUserList();

classes/Commands/ChannelchatcreatedCommand.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

classes/Commands/ChannelpostCommand.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

classes/Commands/ChatCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Longman\TelegramBot\Request;
1515
use Longman\TelegramBot\Entities\InlineKeyboard;
1616
use Longman\TelegramBot\Entities\InlineKeyboardButton;
17+
use Longman\TelegramBot\Entities\ServerResponse;
18+
1719

1820
/**
1921
* User "/register" command
@@ -48,7 +50,7 @@ class ChatCommand extends UserCommand
4850
* @return \Longman\TelegramBot\Entities\ServerResponse
4951
* @throws \Longman\TelegramBot\Exception\TelegramException
5052
*/
51-
public function execute()
53+
public function execute(): ServerResponse
5254
{
5355
$message = $this->getMessage();
5456
$chat_id = $message->getChat()->getId();

classes/Commands/ChatsCommand.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,26 @@
1111
namespace Longman\TelegramBot\Commands\UserCommands;
1212

1313
use Longman\TelegramBot\Commands\UserCommand;
14-
use Longman\TelegramBot\Request;
1514
use Longman\TelegramBot\Entities\InlineKeyboard;
1615
use Longman\TelegramBot\Entities\InlineKeyboardButton;
1716

17+
use Longman\TelegramBot\DB;
18+
use Longman\TelegramBot\Entities\CallbackQuery;
19+
use Longman\TelegramBot\Entities\ChatJoinRequest;
20+
use Longman\TelegramBot\Entities\ChatMemberUpdated;
21+
use Longman\TelegramBot\Entities\ChosenInlineResult;
22+
use Longman\TelegramBot\Entities\InlineQuery;
23+
use Longman\TelegramBot\Entities\Message;
24+
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
25+
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
26+
use Longman\TelegramBot\Entities\Poll;
27+
use Longman\TelegramBot\Entities\PollAnswer;
28+
use Longman\TelegramBot\Entities\ServerResponse;
29+
use Longman\TelegramBot\Entities\Update;
30+
use Longman\TelegramBot\Exception\TelegramException;
31+
use Longman\TelegramBot\Request;
32+
use Longman\TelegramBot\Telegram;
33+
1834
/**
1935
* User "/register" command
2036
*
@@ -48,7 +64,7 @@ class ChatsCommand extends UserCommand
4864
* @return \Longman\TelegramBot\Entities\ServerResponse
4965
* @throws \Longman\TelegramBot\Exception\TelegramException
5066
*/
51-
public function execute()
67+
public function execute(): ServerResponse
5268
{
5369
$message = $this->getMessage();
5470
$chat_id = $message->getChat()->getId();

classes/Commands/ChoseninlineresultCommand.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)