Spaces:
Runtime error
Runtime error
File size: 2,094 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <?php
declare(strict_types=1);
namespace OpenWA\Resources;
use OpenWA\Http\HttpExecutor;
/**
* Templates resource — stored message templates with {{variable}} placeholders.
*
* Backed by src/modules/template/template.controller.ts
* (@Controller('sessions/:sessionId/templates')).
*/
class TemplatesResource
{
private HttpExecutor $http;
public function __construct(HttpExecutor $http)
{
$this->http = $http;
}
/** @return array<int,array<string,mixed>> */
public function list(string $sessionId): array
{
return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/templates") ?? [];
}
/** @return array<string,mixed> */
public function get(string $sessionId, string $templateId): array
{
return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/templates/{$this->http->encodeSegment($templateId)}");
}
/**
* Create a template. Requires an OPERATOR-level key.
*
* @param array<string,mixed> $body Must contain 'name' and 'body'; 'header'/'footer' optional.
* @return array<string,mixed>
*/
public function create(string $sessionId, array $body): array
{
return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/templates", [], $body);
}
/**
* Update a template. Requires an OPERATOR-level key.
*
* @param array<string,mixed> $body
* @return array<string,mixed>
*/
public function update(string $sessionId, string $templateId, array $body): array
{
return $this->http->request('PUT', "/api/sessions/{$this->http->encodeSegment($sessionId)}/templates/{$this->http->encodeSegment($templateId)}", [], $body);
}
/** Delete a template. Requires an OPERATOR-level key. */
public function delete(string $sessionId, string $templateId): void
{
$this->http->request('DELETE', "/api/sessions/{$this->http->encodeSegment($sessionId)}/templates/{$this->http->encodeSegment($templateId)}");
}
}
|