Skip to content

Commit

Permalink
Added webhooks and tests for messages api
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Oct 17, 2024
1 parent 34a172e commit fd60978
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Messages/Webhook/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use InvalidArgumentException;
use Vonage\Webhook\Factory as WebhookFactory;

class Factory extends WebhookFactory
{
protected static array $classMap = [
'sms' => 'Vonage\Messages\Webhook\InboundSMS',
'mms' => 'Vonage\Messages\Webhook\InboundMMS',
'rcs' => 'Vonage\Messages\Webhook\InboundRCS',
'whatsapp' => 'Vonage\Messages\Webhook\InboundWhatsApp',
'messenger' => 'Vonage\Messages\Webhook\InboundMessenger',
'viber_service' => 'Vonage\Messages\Webhook\InboundViber'
];

public static function createFromArray(array $data): mixed
{
if (!isset($data['channel'])) {
throw new InvalidArgumentException("The 'channel' key is missing in the incoming data.");
}

$channel = $data['channel'];

if (!array_key_exists($channel, self::$classMap)) {
throw new InvalidArgumentException("Unable to determine incoming webhook type for channel: {$channel}");
}

return new self::$classMap[$channel]();
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundMMS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundMMS implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundMessenger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundMessenger implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundRCS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundRCS implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundSMS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundSMS implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundViber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundViber implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
28 changes: 28 additions & 0 deletions src/Messages/Webhook/InboundWhatsApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Vonage\Messages\Webhook;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

final class InboundWhatsApp implements ArrayHydrateInterface
{
protected ?array $data = null;

public function fromArray(array $data): self
{
$this->data = $data;
return $this;
}

public function toArray(): array
{
return $this->data;
}

public function __get($name)
{
return $this->data[$name];
}
}
Loading

0 comments on commit fd60978

Please sign in to comment.