|
@@ -6,6 +6,7 @@ namespace BotKit\Drivers;
|
|
|
use BotKit\Events\Event;
|
|
|
use BotKit\Events\PlainMessageEvent;
|
|
|
use BotKit\Events\UnknownEvent;
|
|
|
+use BotKit\Events\CallbackEvent;
|
|
|
use BotKit\Events\MemberJoinedEvent;
|
|
|
use BotKit\Events\MemberLeftEvent;
|
|
|
use BotKit\Common\User;
|
|
@@ -17,6 +18,7 @@ use BotKit\EventAttachments\ImageAttachment;
|
|
|
use BotKit\Enums\Platform;
|
|
|
use BotKit\Enums\State;
|
|
|
use BotKit\Enums\KeyboardButtonColor;
|
|
|
+use BotKit\Enums\CallbackType;
|
|
|
use BotKit\Models\UserModel;
|
|
|
use BotKit\KeyboardButtons\CallbackButton;
|
|
|
|
|
@@ -58,36 +60,20 @@ class TestDriver implements Driver {
|
|
|
|
|
|
if ($data->type == 'callback') {
|
|
|
// Обратный вызов
|
|
|
+ $user = $this->getUser($details->userId);
|
|
|
+ return new CallbackEvent(
|
|
|
+ $details->msgId,
|
|
|
+ $user,
|
|
|
+ $chat,
|
|
|
+ CallbackType::from($details->callbackType),
|
|
|
+ $details->params
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
- $user = $this->getUser();
|
|
|
- } else if ($data->type == 'botKitMsg') {
|
|
|
+ if ($data->type == 'botKitMsg') {
|
|
|
// Обычное текстовое сообщение
|
|
|
-
|
|
|
- // Получение объекта из БД
|
|
|
- $obj = UserModel::where([
|
|
|
- ['platform_id', '=', $details->userID],
|
|
|
- ['platform', '=', $this->platform->value]
|
|
|
- ]);
|
|
|
-
|
|
|
- if ($obj === false) {
|
|
|
- // Пользователя нет в БД
|
|
|
- $obj = UserModel::create(
|
|
|
- $details->userID,
|
|
|
- $this->platform->value,
|
|
|
- State::HelloWorld->value
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- $state_obj = State::from($obj['state']);
|
|
|
-
|
|
|
- $user = new User(
|
|
|
- $details->userID,
|
|
|
- $state_obj,
|
|
|
- "Test username",
|
|
|
- $obj
|
|
|
- );
|
|
|
+ $user = $this->getUser($details->userID);
|
|
|
$text = $details->text;
|
|
|
-
|
|
|
return new PlainMessageEvent(
|
|
|
$details->id,
|
|
|
$user,
|
|
@@ -113,6 +99,14 @@ class TestDriver implements Driver {
|
|
|
$this->sendInternal($msg, -1);
|
|
|
}
|
|
|
|
|
|
+ public function editMessage($messageId, Message $msg) : void {
|
|
|
+ $this->actions[] = [
|
|
|
+ "action" => "editMessage",
|
|
|
+ "messageId" => $messageId,
|
|
|
+ "newMessage" => $this->getMessageData($msg, -1)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
public function sendToChat(Chat $chat, Message $msg) {
|
|
|
$this->sendInternal($msg, -1);
|
|
|
}
|
|
@@ -197,6 +191,16 @@ class TestDriver implements Driver {
|
|
|
|
|
|
// Отправляет сообщение
|
|
|
private function sendInternal(Message $msg, int $reply_to_id) : void {
|
|
|
+
|
|
|
+
|
|
|
+ $this->actions[] = [
|
|
|
+ "action" => "newMessage",
|
|
|
+ "message" => $this->getMessageData($msg, $reply_to_id)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Возвращает разметку для сообщения
|
|
|
+ private function getMessageData(Message $msg, int $reply_to_id) : array {
|
|
|
$attachments = [];
|
|
|
|
|
|
// Поиск клавиатур
|
|
@@ -243,6 +247,7 @@ class TestDriver implements Driver {
|
|
|
"type" => $button_type,
|
|
|
"color" => $button_color,
|
|
|
"label" => $button->getText(),
|
|
|
+ "callbackType" => $button->getType(),
|
|
|
"payload" => $button->getPayload()
|
|
|
];
|
|
|
}
|
|
@@ -266,13 +271,10 @@ class TestDriver implements Driver {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $this->actions[] = [
|
|
|
- "action" => "newMessage",
|
|
|
- "message" => [
|
|
|
- "text" => $msg->getText(),
|
|
|
- "reply_to" => $reply_to_id,
|
|
|
- "attachments" => $attachments
|
|
|
- ]
|
|
|
+ return [
|
|
|
+ "text" => $msg->getText(),
|
|
|
+ "reply_to" => $reply_to_id,
|
|
|
+ "attachments" => $attachments
|
|
|
];
|
|
|
}
|
|
|
|
|
@@ -287,4 +289,33 @@ class TestDriver implements Driver {
|
|
|
"info" => $info
|
|
|
];
|
|
|
}
|
|
|
+
|
|
|
+ // Возвращает объект пользвателя
|
|
|
+ public function getUser($userID) : User {
|
|
|
+ // Получение объекта из БД
|
|
|
+ $obj = UserModel::where([
|
|
|
+ ['platform_id', '=', $userID],
|
|
|
+ ['platform', '=', $this->platform->value]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($obj === false) {
|
|
|
+ // Пользователя нет в БД
|
|
|
+ $obj = UserModel::create(
|
|
|
+ $userID,
|
|
|
+ $this->platform->value,
|
|
|
+ State::HelloWorld->value
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $state_obj = State::from($obj['state']);
|
|
|
+
|
|
|
+ $user = new User(
|
|
|
+ $userID,
|
|
|
+ $state_obj,
|
|
|
+ "Test username",
|
|
|
+ $obj
|
|
|
+ );
|
|
|
+
|
|
|
+ return $user;
|
|
|
+ }
|
|
|
}
|