-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rooms logic fully implemented, not yet tested.
- Loading branch information
1 parent
7b2a85d
commit cd270a3
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |