diff --git a/src/Actions/ManagesRooms.php b/src/Actions/ManagesRooms.php new file mode 100644 index 0000000..4bd8749 --- /dev/null +++ b/src/Actions/ManagesRooms.php @@ -0,0 +1,156 @@ + + */ + public function getRooms(): array + { + $response = $this->get('/v1/rooms'); + + return array_map(fn(array $n): Room => Room::make($n), $response['rooms']); + } + + /** + * Return the details of a specific room associated to your account. + * + * @see https://api.nomi.ai/docs/reference/get-v1-rooms-id + */ + public function getRoom(string $id): Room + { + $response = $this->get("/v1/rooms/{$id}"); + + return Room::make($response); + } + + /** + * Create a new room, with the provided details. + * + * @param array $request + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms + */ + public function createRoom(array $request): Room + { + $response = $this->post('/v1/rooms', $request); + + return Room::make($response); + } + + /** + * Update an existing room with new information or Nomis. + * + * @param array $update + * + * @see https://api.nomi.ai/docs/reference/put-v1-rooms-id + */ + public function updateRoom(Room $room, array $update): Room + { + return $this->updateRoomById($room->uuid, $update); + } + + /** + * Update an existing room by ID with new information or Nomis. + * + * @param array $update + * + * @see https://api.nomi.ai/docs/reference/put-v1-rooms-id + */ + public function updateRoomById(string $id, array $update): Room + { + $response = $this->put("/v1/rooms/{$id}", $update); + + return Room::make($response); + } + + /** + * Deletes the specified room associated with your account. + * + * @see https://api.nomi.ai/docs/reference/delete-v1-rooms-id + */ + public function deleteRoom(Room $room): true + { + return $this->deleteRoomById($room->uuid); + } + + /** + * Deletes the specified room by its ID from your account. + * + * @see https://api.nomi.ai/docs/reference/delete-v1-rooms-id + */ + public function deleteRoomById(string $id): true + { + $this->delete("/v1/rooms/{$id}"); + + return true; + } + + /** + * Sends a message to a given room. + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms-id-chat + */ + public function sendMessageToRoom(Room $room, string $message): Message + { + return $this->sendMessageToRoomById($room->uuid, $message); + } + + /** + * Sends a message to a given room by its ID. + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms-id-chat + */ + public function sendMessageToRoomById(string $id, string $message): Message + { + $response = $this->post("/v1/rooms/{$id}/chat", ['messageText' => $message]); + + return Message::make($response['sentMessage']); + } + + /** + * Requests a Nomi within a given room to post a message. + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms-id-chat-request + */ + public function requestNomiToMessageRoom(Room $room, Nomi $nomi): Message + { + return $this->requestNomiByIdToMessageRoomById($room->uuid, $nomi->uuid); + + } + + /** + * Requests a Nomi within a given room by their ID to post a message. + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms-id-chat-request + */ + public function requestNomiByIdToMessageRoom(Room $room, string $nomiId): Message + { + return $this->requestNomiByIdToMessageRoomById($room->uuid, $nomiId); + } + + /** + * Requests a Nomi by their ID to post a message in a room by its ID. + * + * @see https://api.nomi.ai/docs/reference/post-v1-rooms-id-chat-request + */ + public function requestNomiByIdToMessageRoomById(string $roomId, string $nomiId): Message + { + $response = $this->post("/v1/rooms/{$roomId}/chat/request", ['nomiUuid' => $nomiId]); + + return Message::make($response['replyMessage']); + } +} diff --git a/src/NomiAI.php b/src/NomiAI.php index 94cf197..22e6eba 100755 --- a/src/NomiAI.php +++ b/src/NomiAI.php @@ -11,6 +11,7 @@ use Nomiai\PhpSdk\Actions\ManagesAvatars; use Nomiai\PhpSdk\Actions\ManagesChats; use Nomiai\PhpSdk\Actions\ManagesNomis; +use Nomiai\PhpSdk\Actions\ManagesRooms; use Nomiai\PhpSdk\Traits\MakesHttpRequests; class NomiAI @@ -19,6 +20,7 @@ class NomiAI use ManagesAvatars; use ManagesChats; use ManagesNomis; + use ManagesRooms; /** * The default endpoint to use for the library. diff --git a/tests/Feature/RoomTest.php b/tests/Feature/RoomTest.php new file mode 100644 index 0000000..db63522 --- /dev/null +++ b/tests/Feature/RoomTest.php @@ -0,0 +1,21 @@ +todo(); + + it('can get a specific room by id', function (): void {})->todo(); + + it('can create a room', function (): void {})->todo(); + + it('can update a room', function (): void {})->todo(); + + it('can delete a room', function (): void {})->todo(); +}); + +describe('room messages', function (): void { + it('can send a message to a room', function (): void {})->todo(); + + it('can request a nomi post a message to a room', function (): void {})->todo(); +});