http = $http; } /** * @param array $query * @return array> */ public function list(string $sessionId, array $query = []): array { return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups", $query) ?? []; } /** @return array */ public function get(string $sessionId, string $groupId): array { return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}"); } /** * @param array $body * @return array */ public function create(string $sessionId, array $body): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups", [], $body); } /** * Join a group via an invite code (the token from a chat.whatsapp.com/ * link). Returns {success: true, groupId}. * * @return array */ public function joinGroup(string $sessionId, string $inviteCode): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/join", [], ['inviteCode' => $inviteCode]); } /** @return array */ public function addParticipants(string $sessionId, string $groupId, array $participants): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/participants", [], ['participants' => $participants]); } /** @return array */ public function removeParticipants(string $sessionId, string $groupId, array $participants): array { return $this->http->request('DELETE', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/participants", [], ['participants' => $participants]); } /** @return array */ public function promoteParticipants(string $sessionId, string $groupId, array $participants): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/participants/promote", [], ['participants' => $participants]); } /** @return array */ public function demoteParticipants(string $sessionId, string $groupId, array $participants): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/participants/demote", [], ['participants' => $participants]); } /** @return array */ public function setSubject(string $sessionId, string $groupId, string $subject): array { return $this->http->request('PUT', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/subject", [], ['subject' => $subject]); } /** @return array */ public function setDescription(string $sessionId, string $groupId, string $description): array { return $this->http->request('PUT', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/description", [], ['description' => $description]); } /** * Get group settings. Only the settings the active engine supports are * present — any of {announce, locked, ephemeralSeconds} may be absent. * * @return array */ public function getGroupSettings(string $sessionId, string $groupId): array { return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/settings"); } /** * Update group settings. At least one of {announce, locked, * ephemeralSeconds} is required (400 otherwise); ephemeralSeconds responds * 501 on engines without disappearing-message support (whatsapp-web.js). * * @param array $settings * @return array */ public function updateGroupSettings(string $sessionId, string $groupId, array $settings): array { return $this->http->request('PUT', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/settings", [], $settings); } /** @return array */ public function leave(string $sessionId, string $groupId): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/leave"); } /** @return array */ public function inviteCode(string $sessionId, string $groupId): array { return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/invite-code"); } /** @return array */ public function revokeInviteCode(string $sessionId, string $groupId): array { return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/groups/{$this->http->encodeSegment($groupId)}/invite-code/revoke"); } }