Skip to content

Commit e7a2b38

Browse files
Merge pull request #13 from novuhq/add-more-features
Notifications, Inbound Parse Functionality
2 parents 79c6a0b + 1d91f20 commit e7a2b38

8 files changed

+343
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ composer require unicodeveloper/novu
2828
* [Topics](#topics)
2929
* [Activity](#activity)
3030
* [Integrations](#integrations)
31+
* [Notifications](#notifications)
3132
* [Notification Templates](#notification-templates)
3233
* [Notification Groups](#notification-groups)
3334
* [Changes](#changes)
3435
* [Environments](#environments)
3536
* [Feeds](#feeds)
3637
* [Messages](#messages)
3738
* [Execution Details](#execution-details)
39+
* [Validate the MX Record setup for Inbound Parse functionality](#validate-the-mx-record-setup-for-inbound-parse-functionality)
3840
* [License](#license)
3941

4042
## Usage
@@ -270,6 +272,36 @@ $novu->deleteIntegration($integrationId);
270272

271273
```
272274

275+
## NOTIFICATIONS
276+
277+
```php
278+
279+
// Get all notifications
280+
$novu->getNotifications()->toArray();
281+
282+
// Get all notifications with query parameters
283+
$queryParams = [
284+
'page' => 3
285+
];
286+
$novu->getNotifications($queryParams)->toArray();
287+
288+
// Get one notification
289+
$novu->getNotification($notificationId)->toArray();
290+
291+
// Get notification stats
292+
$novu->getNotificationStats()->toArray();
293+
294+
// Get Notification graph stats
295+
$novu->getNotificationGraphStats()->toArray();
296+
297+
// Get Notification graph stats with query parameters
298+
$queryParams = [
299+
'days' => 5
300+
];
301+
$novu->getNotificationGraphStats($queryParams)->toArray();
302+
303+
```
304+
273305
## NOTIFICATION TEMPLATES
274306

275307
```php
@@ -428,6 +460,15 @@ $novu->getExecutionDetails([
428460

429461
```
430462

463+
## Validate the MX Record setup for Inbound Parse functionality
464+
465+
```php
466+
467+
// Validate MX Record for Inbound Parse
468+
$novu->validateMXRecordForInboundParse()->toArray();
469+
470+
```
471+
431472
## License
432473

433474
**Novu PHP SDK** was created by **[Prosper Otemuyiwa](https://twitter.com/unicodeveloper)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

src/Actions/ManagesInboundParse.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Novu\SDK\Actions;
4+
5+
use Novu\SDK\Resources\InboundParse;
6+
7+
trait ManagesInboundParse
8+
{
9+
10+
/**
11+
* Validate the MX Record setup for Inbound Parse functionality
12+
*
13+
* @return \Novu\SDK\Resources\InboundParse
14+
*/
15+
public function validateMXRecordForInboundParse()
16+
{
17+
$record = $this->get("inbound-parse/mx/status")['data'];
18+
19+
return new InboundParse($record, $this);
20+
}
21+
}

src/Actions/ManagesNotifications.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Novu\SDK\Actions;
4+
5+
use Novu\SDK\Resources\Notification;
6+
use Novu\SDK\Resources\NotificationStats;
7+
use Novu\SDK\Resources\NotificationGraphStats;
8+
9+
trait ManagesNotifications
10+
{
11+
12+
/**
13+
* Get A Notification
14+
*
15+
* @param string $notificationId
16+
* @return \Novu\SDK\Resources\Notification
17+
*/
18+
public function getNotification($notificationId)
19+
{
20+
$response = $this->get("notifications/{$notificationId}")['data'];
21+
22+
return new Notification($response, $this);
23+
}
24+
25+
/**
26+
* Get All Notifications
27+
* @param array $queryParams
28+
* @return \Novu\SDK\Resources\Notification
29+
*/
30+
public function getNotifications(array $queryParams = [])
31+
{
32+
$uri = "notifications";
33+
34+
if(! empty($queryParams)) {
35+
$uri .= '?' . http_build_query($queryParams);
36+
}
37+
38+
$response = $this->get($uri);
39+
40+
return new Notification($response, $this);
41+
}
42+
43+
/**
44+
* Get Notification Statistics
45+
*
46+
* @return \Novu\SDK\Resources\NotificationStats
47+
*/
48+
public function getNotificationStats()
49+
{
50+
$response = $this->get("notifications/stats")['data'];
51+
52+
return new NotificationStats($response, $this);
53+
}
54+
55+
/**
56+
* Get Notification Graph Stats
57+
* @param array $queryParams
58+
* @return \Novu\SDK\Resources\NotificationGraphStats
59+
*/
60+
public function getNotificationGraphStats(array $queryParams = [])
61+
{
62+
$uri = "notifications/graph/stats";
63+
64+
if(! empty($queryParams)) {
65+
$uri .= '?' . http_build_query($queryParams);
66+
}
67+
68+
$response = $this->get($uri)['data'];
69+
70+
return new NotificationGraphStats($response, $this);
71+
}
72+
73+
}

src/Novu.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Novu
1212
Actions\ManagesTopics,
1313
Actions\ManagesSubscribers,
1414
Actions\ManagesActivity,
15+
Actions\ManagesInboundParse,
16+
Actions\ManagesNotifications,
1517
Actions\ManagesChanges,
1618
Actions\ManagesEnvironments,
1719
Actions\ManagesExecutionDetails,

src/Resources/InboundParse.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class InboundParse extends Resource
6+
{
7+
/**
8+
* The mxRecordConfigured status
9+
*
10+
* @var bool
11+
*/
12+
public $mxRecordConfigured;
13+
14+
/**
15+
* Return the array form of InboundParse object.
16+
*
17+
* @return array
18+
*/
19+
public function toArray(): array
20+
{
21+
return [
22+
'mxRecordConfigured' => $this->mxRecordConfigured
23+
];
24+
}
25+
}

src/Resources/Notification.php

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class Notification extends Resource
6+
{
7+
/**
8+
* The internal id Novu generated
9+
*
10+
* @var string
11+
*/
12+
public $id;
13+
14+
/**
15+
* The environment Id
16+
*
17+
* @var string
18+
*/
19+
public $environmentId;
20+
21+
/**
22+
* The organization id
23+
*
24+
* @var string
25+
*/
26+
public $organizationId;
27+
28+
/**
29+
* The transaction id
30+
*
31+
* @var string
32+
*/
33+
public $transactionId;
34+
35+
/**
36+
* The createdAt
37+
*
38+
* @var string
39+
*/
40+
public $createdAt;
41+
42+
/**
43+
* The channels
44+
*
45+
* @var array
46+
*/
47+
public $channels;
48+
49+
/**
50+
* The subscriber
51+
*
52+
* @var array
53+
*/
54+
public $subscriber;
55+
56+
/**
57+
* The template
58+
*
59+
* @var array
60+
*/
61+
public $template;
62+
63+
/**
64+
* The jobs
65+
*
66+
* @var string
67+
*/
68+
public $jobs;
69+
70+
71+
/**
72+
* Return the array form of Notification object.
73+
*
74+
* @return array
75+
*/
76+
public function toArray(): array
77+
{
78+
79+
$publicProperties = get_object_vars($this);
80+
81+
unset($publicProperties['attributes']);
82+
unset($publicProperties['novu']);
83+
84+
return array_filter($publicProperties, function ($value) {
85+
return null !== $value;
86+
});
87+
}
88+
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class NotificationGraphStats extends Resource
6+
{
7+
/**
8+
* The internal id Novu generated
9+
*
10+
* @var string
11+
*/
12+
public $id;
13+
14+
/**
15+
* The count
16+
*
17+
* @var integer
18+
*/
19+
public $count;
20+
21+
/**
22+
* The templates
23+
*
24+
* @var array
25+
*/
26+
public $templates;
27+
28+
/**
29+
* The channels
30+
*
31+
* @var array
32+
*/
33+
public $channels;
34+
35+
36+
/**
37+
* Return the array form of Notification Graph Stats
38+
*
39+
* @return array
40+
*/
41+
public function toArray(): array
42+
{
43+
$publicProperties = get_object_vars($this);
44+
45+
unset($publicProperties['attributes']);
46+
unset($publicProperties['novu']);
47+
48+
return array_filter($publicProperties, function ($value) {
49+
return null !== $value;
50+
});
51+
}
52+
}

src/Resources/NotificationStats.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Novu\SDK\Resources;
4+
5+
class NotificationStats extends Resource
6+
{
7+
/**
8+
* The weekly sent count
9+
*
10+
* @var integer
11+
*/
12+
public $weeklySent;
13+
14+
/**
15+
* The monthly sent count
16+
*
17+
* @var integer
18+
*/
19+
public $monthlySent;
20+
21+
/**
22+
* The yearly sent count
23+
*
24+
* @var integer
25+
*/
26+
public $yearlySent;
27+
28+
/**
29+
* Return the array form of Notification Stats object.
30+
*
31+
* @return array
32+
*/
33+
public function toArray(): array
34+
{
35+
return [
36+
'weeklySent' => $this->weeklySent,
37+
'monthlySent' => $this->monthlySent,
38+
'yearlySent' => $this->yearlySent,
39+
];
40+
}
41+
}

0 commit comments

Comments
 (0)