public function toArray() { $this->checkRecipient(); if (is_null($this->action)) { throw CouldNotCreateMessage::noActionDefined(); } return ['recipient' => ['id' => $this->recipient_id], 'sender_action' => $this->action]; //return array //check null action }