Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed May 1, 2024
1 parent 68aed3a commit 2de610f
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Conversation/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Vonage\Client\APIClient;
use Vonage\Client\APIResource;
use Vonage\Conversation\ConversationObjects\Conversation;
use Vonage\Conversation\ConversationObjects\NewConversationRequest;
use Vonage\Conversation\Filter\ListConversationFilter;
use Vonage\Entity\Hydrator\ArrayHydrator;
use Vonage\Entity\IterableAPICollection;
Expand All @@ -25,6 +26,7 @@ public function listConversations(ListConversationFilter $conversationFilter = n
if (!$conversationFilter) {
$conversationFilter = new ListConversationFilter();
}

$response = $this->api->search($conversationFilter);
$response->setHasPagination(false);
$response->setNaiveCount(true);
Expand All @@ -35,4 +37,9 @@ public function listConversations(ListConversationFilter $conversationFilter = n

return $response;
}

public function createConversation(NewConversationRequest $createConversation): ?array
{
return $this->api->create($createConversation->toArray());
}
}
119 changes: 119 additions & 0 deletions src/Conversation/ConversationObjects/ConversationCallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);

namespace Vonage\Conversation\ConversationObjects;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

class ConversationCallback implements ArrayHydrateInterface
{
protected string $method = 'POST';
protected ?array $params;

public function __construct(
protected ?string $url = null,
protected ?string $eventMask = null
) {
}

public function getMethod(): string
{
return $this->method;
}

public function setMethod(string $method): ConversationCallback
{
$this->method = $method;

return $this;
}

public function getParams(): ?array
{
return $this->params;
}

public function setParams(?array $params): ConversationCallback
{
$this->params = $params;

return $this;
}

public function getUrl(): ?string
{
return $this->url;
}

public function setUrl(?string $url): ConversationCallback
{
$this->url = $url;

return $this;
}

public function getEventMask(): ?string
{
return $this->eventMask;
}

public function setEventMask(?string $eventMask): ConversationCallback
{
$this->eventMask = $eventMask;

return $this;
}

public function setApplicationId(string $applicationId): static
{
$this->params['applicationId'] = $applicationId;

return $this;
}

public function setNccoUrl(string $nccoUrl): static
{
$this->params['ncco_url'] = $nccoUrl;

return $this;
}

public function fromArray(array $data): static
{
if (isset($data['url'])) {
$this->setUrl($data['url']);
}

if (isset($data['event_mask'])) {
$this->setEventMask($data['event_mask']);
}

if (isset($data['params'])) {
$this->setParams($data['params']);
}

return $this;
}

public function toArray(): array
{
$returnPayload = [];

if ($this->getUrl()) {
$returnPayload['url'] = $this->getUrl();
}

if ($this->getEventMask()) {
$returnPayload['event_mask'] = $this->getEventMask();
}

if ($this->getParams()) {
$returnPayload['params'] = $this->getParams();
}

$returnPayload['method'] = $this->getMethod();

return $returnPayload;
}
}
53 changes: 53 additions & 0 deletions src/Conversation/ConversationObjects/ConversationNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Vonage\Conversation\ConversationObjects;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

class ConversationNumber implements ArrayHydrateInterface
{
public const PHONE_TYPE = 'phone';

protected string $type = self::PHONE_TYPE;

public function __construct(
protected ?string $number,
) {
}

public function getType(): string
{
return $this->type;
}

public function getNumber(): ?string
{
return $this->number;
}

public function setNumber(?string $number): ConversationNumber
{
$this->number = $number;

return $this;
}

public function fromArray(array $data): static
{
if (isset($data['number'])) {
$this->number = $data['number'];
}

return $this;
}

public function toArray(): array
{
return [
'type' => $this->getType(),
'number' => $this->getNumber()
];
}
}
177 changes: 177 additions & 0 deletions src/Conversation/ConversationObjects/NewConversationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

declare(strict_types=1);

namespace Vonage\Conversation\ConversationObjects;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

class NewConversationRequest implements ArrayHydrateInterface
{
protected ?int $ttl = null;
protected ?array $customData = null;

protected ?ConversationNumber $number = null;
protected ?ConversationCallback $conversationCallback = null;

public function __construct(
protected ?string $name,
protected ?string $displayName,
protected ?string $imageUrl
) {
}

public function getTtl(): ?int
{
return $this->ttl;
}

public function setTtl(?int $ttl): NewConversationRequest
{
$this->ttl = $ttl;

return $this;
}

public function getCustomData(): ?array
{
return $this->customData;
}

public function setCustomData(?array $customData): NewConversationRequest
{
$this->customData = $customData;

return $this;
}

public function getNumber(): ?ConversationNumber
{
return $this->number;
}

public function setNumber(ConversationNumber $number): NewConversationRequest
{
$this->number = $number;

return $this;
}

public function getConversationCallback(): ?ConversationCallback
{
return $this->conversationCallback;
}

public function setConversationCallback(?ConversationCallback $conversationCallback): NewConversationRequest
{
$this->conversationCallback = $conversationCallback;

return $this;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): NewConversationRequest
{
$this->name = $name;

return $this;
}

public function getDisplayName(): ?string
{
return $this->displayName;
}

public function setDisplayName(?string $displayName): NewConversationRequest
{
$this->displayName = $displayName;

return $this;
}

public function getImageUrl(): ?string
{
return $this->imageUrl;
}

public function setImageUrl(?string $imageUrl): NewConversationRequest
{
$this->imageUrl = $imageUrl;

return $this;
}

public function fromArray(array $data)
{
if (isset($data['name'])) {
$this->setName($data['name']);
}

if (isset($data['display_name'])) {
$this->setDisplayName($data['display_name']);
}

if (isset($data['image_url'])) {
$this->setImageUrl($data['image_url']);
}

if (isset($data['properties']['ttl'])) {
$this->setTtl($data['properties']['ttl']);
}

if (isset($data['properties']['custom_data'])) {
$this->setCustomData($data['properties']['custom_data']);
}

if (isset($data['numbers'])) {
$numbers = new ConversationNumber(null);
$numbers->fromArray($data['numbers']);
$this->setNumbers($numbers);

Check failure on line 133 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test

Call to an undefined method Vonage\Conversation\ConversationObjects\NewConversationRequest::setNumbers().

Check failure on line 133 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test

Call to an undefined method Vonage\Conversation\ConversationObjects\NewConversationRequest::setNumbers().

Check failure on line 133 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test

Call to an undefined method Vonage\Conversation\ConversationObjects\NewConversationRequest::setNumbers().
}

if (isset($data['callback'])) {
$callback = new Callback();

Check failure on line 137 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test

Instantiated class Vonage\Conversation\ConversationObjects\Callback not found.

Check failure on line 137 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test

Instantiated class Vonage\Conversation\ConversationObjects\Callback not found.

Check failure on line 137 in src/Conversation/ConversationObjects/NewConversationRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test

Instantiated class Vonage\Conversation\ConversationObjects\Callback not found.
$callback->fromArray($data['callback']);
$this->setConversationCallback($callback);
}
}

public function toArray(): array
{
$returnPayload = [];

if ($this->getName()) {
$returnPayload['name'] = $this->getName();
}

if ($this->getDisplayName()) {
$returnPayload['display_name'] = $this->getDisplayName();
}

if ($this->getImageUrl()) {
$returnPayload['image_url'] = $this->getImageUrl();
}

if ($this->getTtl()) {
$returnPayload['properties']['ttl'] = $this->getTtl();
}

if ($this->getCustomData()) {
$returnPayload['properties']['custom_data'] = $this->getCustomData();
}

if ($this->getNumber()) {
$returnPayload['numbers'] = $this->getNumber()->toArray();
}

if ($this->getConversationCallback()) {
$returnPayload['callback'] = $this->getConversationCallback()->toArray();
}

return $returnPayload;
}
}
Loading

0 comments on commit 2de610f

Please sign in to comment.