Skip to content

Commit

Permalink
Quick reply buttons support
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Sep 12, 2023
1 parent e95f99c commit 815960c
Show file tree
Hide file tree
Showing 33 changed files with 605 additions and 874 deletions.
44 changes: 42 additions & 2 deletions bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,52 @@ public function sendMessageToTelegram($params)

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

$keyboardButtons = [];

$metaMsg = $params['msg']->meta_msg_array;

if (isset($metaMsg['content']['quick_replies']) && !empty($metaMsg['content']['quick_replies'])) {
foreach ($metaMsg['content']['quick_replies'] as $quickReplyButton) {
if ($quickReplyButton['type'] == 'trigger' || $quickReplyButton['type'] == 'button') {
$keyboardButtons[] = [
'text' => $quickReplyButton['content']['name'],
'callback_data' => ($quickReplyButton['type'] == 'button' ? 'bpayload__||' : 'trigger__||') . $quickReplyButton['content']['payload']. '__' . md5($quickReplyButton['content']['name']) .'__'.$params['msg']->id
];
} elseif ($quickReplyButton['type'] == 'url') {
$keyboardButtons[] = [
'text' => $quickReplyButton['content']['name'],
'url' => $quickReplyButton['content']['payload']
];
}

}
}

$data = [
'chat_id' => $tChat->tchat_id,
'text' => trim($params['msg']->msg) . $signatureText,
'text' => trim($params['msg']->msg) . $signatureText
];

Longman\TelegramBot\Request::sendMessage($data);
if (!empty($keyboardButtons)) {
$inline_keyboard = new Longman\TelegramBot\Entities\InlineKeyboard($keyboardButtons);
$inline_keyboard->setOneTimeKeyboard(true);
$inline_keyboard->setIsPersistent(false);
$data['reply_markup'] = $inline_keyboard;
}

$sendData = Longman\TelegramBot\Request::sendMessage($data);

if ($sendData->isOk()) {
$metaMsg['iwh_msg_id'] = $sendData->getResult()->getMessageId();

$params['msg']->meta_msg_array = $metaMsg;
$params['msg']->meta_msg = json_encode($metaMsg);
$params['msg']->del_st = erLhcoreClassModelmsg::STATUS_READ;

if ($params['msg']->id > 0) {
$params['msg']->updateThis(['update' => ['meta_msg','del_st']]);
}
}
}

foreach ($images['images'] as $image) {
Expand Down
34 changes: 33 additions & 1 deletion classes/Commands/CallbackqueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\ServerResponse;

/**
* Callback query command
Expand Down Expand Up @@ -44,7 +45,7 @@ class CallbackqueryCommand extends SystemCommand
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
public function execute(): ServerResponse
{
$callback_query = $this->getCallbackQuery();
$callback_query_id = $callback_query->getId();
Expand Down Expand Up @@ -389,6 +390,37 @@ public function execute()
Request::sendMessage($data);
}

} elseif ($paramsCallback[0] == 'bpayload__' || $paramsCallback[0] == 'trigger__') {

/*$data = [
'callback_query_id' => $callback_query_id,
'text' => 'Thanks!',
'show_alert' => $callback_data === 'thumb up',
'cache_time' => 1,
];
Request::answerCallbackQuery($data);*/

$payloadParts = explode('__',$paramsCallback[1]);

$message = \erLhcoreClassModelmsg::fetch($payloadParts[2]);

$chat = \erLhcoreClassModelChat::fetch($message->chat_id);

\Longman\TelegramBot\Commands\SystemCommands\GenericmessageCommand::sendBotResponse($chat, $message, array(
'type' => ($paramsCallback[0] == 'bpayload__' ? 'payload' : 'trigger'),
'payload' => $payloadParts[0] . '__' . $payloadParts[1],
'msg_last_id' => $chat->last_msg_id // Message visitor is clicking is not necessary the last message
));

return Request::send('editMessageReplyMarkup',[
'chat_id' => $callback_query->getFrom()->getId(),
'message_id' => $message->meta_msg_array['iwh_msg_id'],
'reply_markup' => null
]);

return Request::emptyResponse();

} else {
$data = [
'callback_query_id' => $callback_query_id,
Expand Down
8 changes: 3 additions & 5 deletions classes/Commands/ChangeownerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\InlineKeyboardButton;

use Longman\TelegramBot\Entities\ServerResponse;
/**
* User "/register" command
*
Expand Down Expand Up @@ -48,7 +48,7 @@ class ChangeownerCommand extends UserCommand
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
public function execute(): ServerResponse
{
$message = $this->getMessage();

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

Request::sendMessage($data);

$transferLegacy = \erLhcoreClassTransfer::getTransferByChat($chat->id);

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

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

return ;
return Request::sendMessage($data);
}

$onlineOperators = \erLhcoreClassModelUser::getUserList();
Expand Down
50 changes: 0 additions & 50 deletions classes/Commands/ChannelchatcreatedCommand.php

This file was deleted.

49 changes: 0 additions & 49 deletions classes/Commands/ChannelpostCommand.php

This file was deleted.

4 changes: 3 additions & 1 deletion classes/Commands/ChatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\InlineKeyboardButton;
use Longman\TelegramBot\Entities\ServerResponse;


/**
* User "/register" command
Expand Down Expand Up @@ -48,7 +50,7 @@ class ChatCommand extends UserCommand
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
public function execute(): ServerResponse
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
Expand Down
20 changes: 18 additions & 2 deletions classes/Commands/ChatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,26 @@
namespace Longman\TelegramBot\Commands\UserCommands;

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboard;
use Longman\TelegramBot\Entities\InlineKeyboardButton;

use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\CallbackQuery;
use Longman\TelegramBot\Entities\ChatJoinRequest;
use Longman\TelegramBot\Entities\ChatMemberUpdated;
use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
use Longman\TelegramBot\Entities\Poll;
use Longman\TelegramBot\Entities\PollAnswer;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;

/**
* User "/register" command
*
Expand Down Expand Up @@ -48,7 +64,7 @@ class ChatsCommand extends UserCommand
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
public function execute(): ServerResponse
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
Expand Down
51 changes: 0 additions & 51 deletions classes/Commands/ChoseninlineresultCommand.php

This file was deleted.

Loading

0 comments on commit 815960c

Please sign in to comment.