addType('id', 'integer'); $this->addType('botId', 'integer'); $this->addType('createdAt', 'integer'); $this->addType('updatedAt', 'integer'); } public function jsonSerialize(): array { return [ 'id' => $this->id, 'bot_id' => $this->botId, 'room_token' => $this->roomToken, 'response_mode' => $this->responseMode, 'onboarding_status' => $this->onboardingStatus, 'current_question_id' => $this->currentQuestionId, 'onboarding_answers' => $this->getOnboardingAnswersArray(), 'activated_by' => $this->activatedBy, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, ]; } /** * Check if onboarding is complete */ public function isOnboardingComplete(): bool { return $this->onboardingStatus === 'completed'; } /** * Check if in mention-only mode */ public function isMentionMode(): bool { return $this->responseMode === 'mention'; } /** * Check if in always-respond mode */ public function isAlwaysMode(): bool { return $this->responseMode === 'always'; } /** * Get onboarding answers as decoded array * * @return array */ public function getOnboardingAnswersArray(): array { if ($this->onboardingAnswers === null || $this->onboardingAnswers === '') { return []; } $decoded = json_decode($this->onboardingAnswers, true); return is_array($decoded) ? $decoded : []; } /** * Set onboarding answers from array * * @param array $answers */ public function setOnboardingAnswersArray(array $answers): void { if (count($answers) === 0) { $this->onboardingAnswers = null; } else { $this->onboardingAnswers = json_encode($answers); } $this->markFieldUpdated('onboardingAnswers'); } /** * Add an answer to the onboarding answers * * @param string $questionId * @param string $questionText * @param string $answerId * @param string $answerText */ public function addOnboardingAnswer(string $questionId, string $questionText, string $answerId, string $answerText): void { $answers = $this->getOnboardingAnswersArray(); $answers[] = [ 'question_id' => $questionId, 'question_text' => $questionText, 'answer_id' => $answerId, 'answer_text' => $answerText, ]; $this->setOnboardingAnswersArray($answers); } }