Skip to content

Commit

Permalink
Merge branch 'main' into feature/gnp-oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Jun 24, 2024
2 parents cb002f6 + 3b1b1a9 commit 54eddf3
Show file tree
Hide file tree
Showing 93 changed files with 3,510 additions and 1,113 deletions.
110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Client Library for PHP

![The Vonage logo](./vonage_logo.png)

*This library requires a minimum PHP version of 8.0*
*This library requires a minimum PHP version of 8.1*

This is the PHP client library for use Vonage's API. To use this, you'll need a Vonage account. [Sign up for free here](https://ui.idp.vonage.com/ui/auth/registration).

Expand Down Expand Up @@ -445,8 +445,116 @@ If you would like to have the system randomly pick a FROM number from the number
leave off the second parameter to `\Vonage\Voice\OutboundCall`'s constructor, and the system will select a number
at random for you.

## Using the Conversations API

This API is used for in-app messaging and is contains a wide range of features and
concepts. For more information, take a look at the [API Documentation]()

### Retrieve a list of Conversations with Filter

```php
$credentials = new \Vonage\Client\Credentials\Keypair(file_get_contents('./path-to-my-key.key', 'my-app-id'));
$client = new \Vonage\Client($credentials);
$filter = new \Vonage\Conversation\Filter\ListConversationFilter();
$filter->setStartDate('2018-01-01 10:00:00');
$filter->setEndDate('2019-01-01 10:00:00')

$conversations = $client->conversations()->listConversations($filter)

var_dump($conversations);
```

### Create a Conversation

```php

$credentials = new \Vonage\Client\Credentials\Keypair(file_get_contents('./path-to-my-key.key', 'my-app-id'));
$client = new \Vonage\Client($credentials);

$conversation = new CreateConversationRequest('customer_chat', 'Customer Chat', 'https://example.com/image.png');
$conversation->setTtl(60);

$conversationNumber = new ConversationNumber('447700900000');

$conversationCallback = new ConversationCallback('https://example.com/eventcallback');
$conversationCallback->setEventMask('member:invited, member:joined');
$conversationCallback->setApplicationId('afa393df-2c46-475b-b2d6-92da4ea05481');
$conversationCallback->setNccoUrl('https://example.com/ncco');

$conversation->setNumber($conversationNumber);
$conversation->setConversationCallback($conversationCallback);

$response = $this->conversationsClient->createConversation($conversation);

var_dump($response);

```

### List Members in a Conversation

```php

$credentials = new \Vonage\Client\Credentials\Keypair(file_get_contents('./path-to-my-key.key', 'my-app-id'));
$client = new \Vonage\Client($credentials);

$filter = new ListUserConversationsFilter();
$filter->setState('INVITED');
$filter->setIncludeCustomData(true);
$filter->setOrderBy('created');
$filter->setStartDate('2018-01-01 10:00:00');
$filter->setEndDate('2018-01-01 12:00:00');
$filter->setPageSize(5);
$filter->setOrder('asc');

$response = $this->conversationsClient->listUserConversationsByUserId('CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a');

foreach ($response as $member) {
$members[] = $member;
}

var_dump($members);

```

### Create a Member in a Conversation

```php

$channel = Channel::createChannel(Channel::CHANNEL_TYPE_APP);
$channel->addUserFromTypes([
'sms',
'phone'
]);

$channel->addUserToField('USR-82e028d9-9999-4f1e-8188-604b2d3471ec');

$createMemberRequest = new CreateMemberRequest(
'invited',
$channel,
'USR-82e028d9-5201-4f1e-8188-604b2d3471ec',
'my_user_name',
);

$createMemberRequest->setAudioPossible(true);
$createMemberRequest->setAudioEnabled(true);
$createMemberRequest->setAudioEarmuffed(false);
$createMemberRequest->setAudioMuted(false);
$createMemberRequest->setKnockingId('4f1e-8188');
$createMemberRequest->setMemberIdInviting('MEM-63f61863-4a51-4f6b-86e1-46edebio0391');
$createMemberRequest->setFrom('value');

$response = $this->conversationsClient->createMember(
$createMemberRequest,
'CON-63f61863-4a51-4f6b-86e1-46edebio0391'
);

var_dump($response);
````

### Building a call with NCCO Actions

### Create an Event

Full parameter lists for NCCO Actions can be found in the [Voice API Docs](https://developer.nexmo.com/voice/voice-api/ncco-reference).

Each of these examples uses the following structure to add actions to a call:
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ parameters:
count: 1
path: src/Account/Price.php

-
message: "#^Result of method Vonage\\\\Account\\\\Price\\:\\:getResponse\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Account/Price.php

-
message: "#^Access to an undefined property Vonage\\\\Application\\\\Application\\:\\:\\$data\\.$#"
count: 1
Expand Down Expand Up @@ -55,21 +50,11 @@ parameters:
count: 1
path: src/Client/Exception/Server.php

-
message: "#^Result of method Vonage\\\\Network\\:\\:getResponse\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Network.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Network/Number/Response.php

-
message: "#^Result of method Vonage\\\\Numbers\\\\Number\\:\\:getResponse\\(\\) \\(void\\) is used\\.$#"
count: 1
path: src/Numbers/Number.php

-
message: "#^Access to an undefined property Vonage\\\\Verify\\\\Verification\\:\\:\\$data\\.$#"
count: 1
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<testsuite name="client">
<directory>test/Client</directory>
</testsuite>
<testsuite name="conversations">
<directory>test/Conversation</directory>
</testsuite>
<testsuite name="proactive_connect">
<directory>test/ProactiveConnect</directory>
</testsuite>
Expand Down
2 changes: 0 additions & 2 deletions src/Account/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Psr\Container\ContainerInterface;
use Vonage\Client\APIResource;
use Vonage\Client\Credentials\Handler\BasicHandler;
use Vonage\Client\Credentials\Handler\BasicQueryHandler;

class ClientFactory
{
public function __invoke(ContainerInterface $container): Client
Expand Down
5 changes: 2 additions & 3 deletions src/Network.php → src/Account/Network.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

declare(strict_types=1);

namespace Vonage;
namespace Vonage\Account;

use Vonage\Entity\EntityInterface;
use Vonage\Entity\Hydrator\ArrayHydrateInterface;
use Vonage\Entity\JsonResponseTrait;
use Vonage\Entity\JsonSerializableTrait;
use Vonage\Entity\NoRequestResponseTrait;

use function get_class;
use function ltrim;
use function preg_replace;
use function strtolower;
use function trigger_error;

class Network implements
EntityInterface,
Expand Down
5 changes: 0 additions & 5 deletions src/Account/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

namespace Vonage\Account;

use JsonSerializable;
use RuntimeException;
use Vonage\Entity\EntityInterface;
use Vonage\Entity\Hydrator\ArrayHydrateInterface;
use Vonage\Entity\JsonResponseTrait;
use Vonage\Entity\JsonSerializableInterface;
use Vonage\Entity\JsonSerializableTrait;
use Vonage\Entity\JsonUnserializableInterface;
use Vonage\Entity\NoRequestResponseTrait;
use Vonage\Network;

use function array_key_exists;
use function ltrim;
use function preg_replace;
Expand Down
1 change: 0 additions & 1 deletion src/Account/SmsPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

namespace Vonage\Account;

class SmsPrice extends Price
{
/**
Expand Down
1 change: 0 additions & 1 deletion src/Account/VoicePrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

namespace Vonage\Account;

class VoicePrice extends Price
{
/**
Expand Down
54 changes: 0 additions & 54 deletions src/ApiErrorHandler.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Vonage\Entity\Hydrator\ArrayHydrateInterface;
use Vonage\Entity\JsonResponseTrait;
use Vonage\Entity\JsonSerializableTrait;
use Vonage\Entity\JsonUnserializableInterface;
use Vonage\Entity\Psr7Trait;

use function count;
Expand Down
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use Vonage\Users\ClientFactory as UsersClientFactory;
use Vonage\Verify\ClientFactory as VerifyClientFactory;
use Vonage\Verify2\ClientFactory as Verify2ClientFactory;
use Vonage\Conversation\ClientFactory as ConversationClientFactory;
use Vonage\Verify\Verification;
use Vonage\Voice\ClientFactory as VoiceClientFactory;
use Vonage\Logger\{LoggerAwareInterface, LoggerTrait};
Expand All @@ -74,6 +75,7 @@
* @method Messages\Client messages()
* @method Application\Client applications()
* @method Conversion\Client conversion()
* @method Conversation\Client conversation()
* @method Insights\Client insights()
* @method Numbers\Client numbers()
* @method Redact\Client redact()
Expand Down Expand Up @@ -212,6 +214,7 @@ public function __construct(
'account' => ClientFactory::class,
'applications' => ApplicationClientFactory::class,
'conversion' => ConversionClientFactory::class,
'conversation' => ConversationClientFactory::class,
'insights' => InsightsClientFactory::class,
'numbers' => NumbersClientFactory::class,
'meetings' => MeetingsClientFactory::class,
Expand Down Expand Up @@ -357,6 +360,7 @@ public static function authRequest(RequestInterface $request, Basic $credentials

/**
* @throws ClientException
* @deprecated Use the Vonage/JWT library if you need to generate a token
*/
public function generateJwt($claims = []): Token
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Vonage;
namespace Vonage\Client;

use Exception;

Expand Down
Loading

0 comments on commit 54eddf3

Please sign in to comment.