-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added webhooks and tests for messages api
- Loading branch information
Showing
8 changed files
with
409 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,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](); | ||
} | ||
} |
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,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]; | ||
} | ||
} |
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,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]; | ||
} | ||
} |
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,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]; | ||
} | ||
} |
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,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]; | ||
} | ||
} |
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,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]; | ||
} | ||
} |
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,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]; | ||
} | ||
} |
Oops, something went wrong.