public function toArray()
{
$payload_name = $this->type == ButtonType::Web || $this->type == ButtonType::AccountLink ? 'url' : 'payload';
if ($this->type == ButtonType::AccountLink) {
return ['type' => $this->type, 'url' => $this->payload];
}
if ($this->type == ButtonType::AccountUnlink) {
return ['type' => $this->type];
}
if ($this->is_webview) {
$result = ['type' => $this->type, $payload_name => $this->payload, 'title' => MessengerUtils::checkStringLengthAndEncoding($this->title, 320, 'UTF-8'), 'webview_height_ratio' => $this->webview_height_ratio];
if ($this->is_webview_extended) {
$result['messenger_extensions'] = true;
if (!is_null($this->fallback_url)) {
$result['fallback_url'] = $this->fallback_url;
}
}
return $result;
}
return ['type' => $this->type, $payload_name => $this->payload, 'title' => MessengerUtils::checkStringLengthAndEncoding($this->title, 320, 'UTF-8')];
}