diff --git a/src/AmoCRM/Models/Chats/Templates/TemplateModel.php b/src/AmoCRM/Models/Chats/Templates/TemplateModel.php index d79755b..fe356e8 100644 --- a/src/AmoCRM/Models/Chats/Templates/TemplateModel.php +++ b/src/AmoCRM/Models/Chats/Templates/TemplateModel.php @@ -190,12 +190,16 @@ public static function fromArray(array $template): TemplateModel */ public function toArray(): array { + $buttons = $this->getButtons() !== null && !$this->getButtons()->isEmpty() + ? $this->getButtons()->toArray() + : null; + return [ 'id' => $this->getId(), 'account_id' => $this->getAccountId(), 'name' => $this->getName(), 'content' => $this->getContent(), - 'buttons' => $this->getButtons() ? $this->getButtons()->toArray() : null, + 'buttons' => $buttons, 'created_at' => $this->getCreatedAt(), 'updated_at' => $this->getUpdatedAt(), 'is_editable' => $this->getIsEditable(), @@ -221,11 +225,14 @@ public function toApi(?string $requestId = "0"): array if (is_null($this->getRequestId()) && !is_null($requestId)) { $this->setRequestId($requestId); } + $buttons = $this->getButtons() !== null && !$this->getButtons()->isEmpty() + ? $this->getButtons()->toArray() + : null; $result = [ 'name' => $this->getName(), 'content' => $this->getContent(), - 'buttons' => $this->getButtons() ? $this->getButtons()->toApi() : null, + 'buttons' => $buttons, 'is_editable' => $this->getIsEditable(), 'external_id' => $this->getExternalId(), 'request_id' => $this->getRequestId(),