Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: UTF decoded problem with button_value and incorrect conversation Identifier #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"botman/botman": "~2.0|~3.0",
"ext-json": "*",
"ext-curl": "*",
"ralouphie/mimey": "^2.1",
"xantios/mimey": "^2.1",
"ext-fileinfo": "*"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/VKKeyboardButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function setType($type = self::TYPE_TEXT){
* @return $this
*/
public function setValue($value = "button_value"){
$this->action["payload"] = json_encode(["__message" => $value]);
$this->action["payload"] = json_encode(["__message" => $value], JSON_UNESCAPED_UNICODE); //так как VK не проподит декодирование UTF символов из формата \u*
return $this;
}

Expand Down
30 changes: 19 additions & 11 deletions src/VkCommunityCallbackDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,49 +331,57 @@ protected function serializeIncomingMessage($message, $sender, $recipient, $mess
})->toArray()) && count($_) > 0) ? ($attachments["files"] = $_) : false;

// Getting location
(($_ = $message_object["geo"] ?? []) && count($_) > 0)
? ($attachments["location"] =
new Location($_["coordinates"]["latitude"], $_["coordinates"]["longitude"], $_)
) : false;
(($_ = $message_object["geo"] ?? []) && count($_) > 0) ? ($attachments["location"] = new Location($_["coordinates"]["latitude"], $_["coordinates"]["longitude"], $_)) : false;
//Добавим аудио сообщения
(($_ = $collection->where('type', 'audio_message')->pluck('audio_message')->map(function ($item) {
return new Audio($item["link_ogg"], $item);
})->toArray()) && count($_) > 0) ? ($attachments["audios"] = $_) : false;
//Добавим стикеры сообщения
(($_ = $collection->where('type', 'sticker')->pluck('sticker')->map(function ($item) {
return new Image($item["images"][1]["url"], $item);
})->toArray()) && count($_) > 0) ? ($attachments["photos"] = $_) : false;
(($_ = $collection->where('type', 'graffiti')->pluck('graffiti')->map(function ($item) {
return new Image($item["url"], $item);
})->toArray()) && count($_) > 0) ? ($attachments["photos"] = $_) : false;


// Make an incoming message with no text if it is so
if($message == ""){
// Returning message with images only
if(count($attachments) == 1 and isset($attachments["photos"])){
$result = new IncomingMessage(Image::PATTERN, $sender, $recipient, $this->payload);
$result = new IncomingMessage(Image::PATTERN, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
$result->setImages($attachments["photos"]);

return $result;
}

// Returning message with videos only
if(count($attachments) == 1 and isset($attachments["videos"])){
$result = new IncomingMessage(Video::PATTERN, $sender, $recipient, $this->payload);
$result = new IncomingMessage(Video::PATTERN, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
$result->setVideos($attachments["videos"]);

return $result;
}

// Returning message with audio only
if(count($attachments) == 1 and isset($attachments["audios"])){
$result = new IncomingMessage(Audio::PATTERN, $sender, $recipient, $this->payload);
$result = new IncomingMessage(Audio::PATTERN, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
$result->setAudio($attachments["audios"]);

return $result;
}

// Returning message with files only
if(count($attachments) == 1 and isset($attachments["files"])){
$result = new IncomingMessage(File::PATTERN, $sender, $recipient, $this->payload);
$result = new IncomingMessage(File::PATTERN, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
$result->setFiles($attachments["files"]);

return $result;
}

// Returning message with location only
if(count($attachments) == 1 and isset($attachments["location"])){
$result = new IncomingMessage(Location::PATTERN, $sender, $recipient, $this->payload);
$result = new IncomingMessage(Location::PATTERN, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
$result->setLocation($attachments["location"]);

return $result;
Expand All @@ -382,7 +390,7 @@ protected function serializeIncomingMessage($message, $sender, $recipient, $mess

// Returning message with mixed attachments or with text given
if(count($attachments) >= 1){
$result = new IncomingMessage($message, $sender, $recipient, $this->payload);
$result = new IncomingMessage($message, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
if(isset($attachments["photos"])) $result->setImages($attachments["photos"]);
if(isset($attachments["videos"])) $result->setVideos($attachments["videos"]);
if(isset($attachments["audios"])) $result->setAudio($attachments["audios"]);
Expand All @@ -393,7 +401,7 @@ protected function serializeIncomingMessage($message, $sender, $recipient, $mess
}

// Returning regular message (if no attachments detected)
return new IncomingMessage($message, $sender, $recipient, $this->payload);
return new IncomingMessage($message, $sender, $recipient, $this->payload, $this->config->get("bot_id", ''));
}

/**
Expand Down