Skip to content

Commit

Permalink
Rooms logic fully implemented, not yet tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverearl committed Dec 1, 2024
1 parent 7b2a85d commit cd270a3
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
156 changes: 156 additions & 0 deletions src/Actions/ManagesRooms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

declare(strict_types=1);

namespace Nomiai\PhpSdk\Actions;

use Nomiai\PhpSdk\Resources\Message;
use Nomiai\PhpSdk\Resources\Nomi;
use Nomiai\PhpSdk\Resources\Room;

/** @mixin \Nomiai\PhpSdk\Traits\MakesHttpRequests */
trait ManagesRooms
{
/**
* Returns all the rooms that are associated with your account.
*
* @see https://api.nomi.ai/docs/reference/get-v1-rooms
*
* @return array<int, \Nomiai\PhpSdk\Resources\Room>
*/
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<string, mixed> $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<string, mixed> $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<string, mixed> $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']);
}
}
2 changes: 2 additions & 0 deletions src/NomiAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,7 @@ class NomiAI
use ManagesAvatars;
use ManagesChats;
use ManagesNomis;
use ManagesRooms;

/**
* The default endpoint to use for the library.
Expand Down
21 changes: 21 additions & 0 deletions tests/Feature/RoomTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

describe('rooms', function (): void {
it('can get a list of rooms associated with an account', function (): void {})->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();
});

0 comments on commit cd270a3

Please sign in to comment.