Skip to content

Commit a48aba9

Browse files
authored
Merge pull request #289 from bitrix24/feature/288-add-crm-on-contact-events
Add support for CRM Contact events: `onCrmContactAdd`, `onCrmContactU…
2 parents e76b288 + 5963716 commit a48aba9

File tree

9 files changed

+207
-2
lines changed

9 files changed

+207
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
- `list` Get a list of custom types crm.type.list
1414
- `delete` This method deletes an existing smart process by the identifier id
1515
- For `AbstractCrmItem` added method `getSmartProcessItem` to get smart process item, [see details](https://github.com/bitrix24/b24phpsdk/issues/282)
16-
17-
16+
- Added support for events, [see details](https://github.com/bitrix24/b24phpsdk/issues/288)
17+
- `onCrmContactAdd`
18+
- `onCrmContactUpdate`
19+
- `onCrmContactDelete`
1820

1921
### Fixed
2022

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events;
15+
16+
use Bitrix24\SDK\Core\Contracts\Events\EventInterface;
17+
use Bitrix24\SDK\Core\Contracts\Events\EventsFabricInterface;
18+
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
19+
use Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactAdd\OnCrmContactAdd;
20+
use Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactDelete\OnCrmContactDelete;
21+
use Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactUpdate\OnCrmContactUpdate;
22+
use Symfony\Component\HttpFoundation\Request;
23+
24+
readonly class CrmContactEventsFactory implements EventsFabricInterface
25+
{
26+
public function isSupport(string $eventCode): bool
27+
{
28+
return in_array(strtoupper($eventCode), [
29+
OnCrmContactAdd::CODE,
30+
OnCrmContactUpdate::CODE,
31+
OnCrmContactDelete::CODE,
32+
], true);
33+
}
34+
35+
/**
36+
* @throws InvalidArgumentException
37+
*/
38+
public function create(Request $eventRequest): EventInterface
39+
{
40+
$eventPayload = $eventRequest->request->all();
41+
if (!array_key_exists('event', $eventPayload)) {
42+
throw new InvalidArgumentException('«event» key not found in event payload');
43+
}
44+
45+
return match ($eventPayload['event']) {
46+
OnCrmContactAdd::CODE => new OnCrmContactAdd($eventRequest),
47+
OnCrmContactUpdate::CODE => new OnCrmContactUpdate($eventRequest),
48+
OnCrmContactDelete::CODE => new OnCrmContactDelete($eventRequest),
49+
default => throw new InvalidArgumentException(
50+
sprintf('Unexpected event code «%s»', $eventPayload['event'])
51+
),
52+
};
53+
}
54+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactAdd;
15+
16+
use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;
17+
18+
class OnCrmContactAdd extends AbstractEventRequest
19+
{
20+
public const CODE = 'ONCRMCONTACTADD';
21+
22+
public function getPayload(): OnCrmContactAddPayload
23+
{
24+
return new OnCrmContactAddPayload($this->eventPayload['data']);
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactAdd;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* @property-read positive-int $ID
20+
*/
21+
class OnCrmContactAddPayload extends AbstractItem
22+
{
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactDelete;
15+
16+
use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;
17+
18+
class OnCrmContactDelete extends AbstractEventRequest
19+
{
20+
public const CODE = 'ONCRMCONTACTDELETE';
21+
22+
public function getPayload(): OnCrmContactDeletePayload
23+
{
24+
return new OnCrmContactDeletePayload($this->eventPayload['data']);
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactDelete;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* @property-read positive-int $ID
20+
*/
21+
class OnCrmContactDeletePayload extends AbstractItem
22+
{
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactUpdate;
15+
16+
use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;
17+
18+
class OnCrmContactUpdate extends AbstractEventRequest
19+
{
20+
public const CODE = 'ONCRMCONTACTUPDATE';
21+
22+
public function getPayload(): OnCrmContactUpdatePayload
23+
{
24+
return new OnCrmContactUpdatePayload($this->eventPayload['data']);
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Maksim Mesilov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Contact\Events\OnCrmContactUpdate;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* @property-read positive-int $ID
20+
*/
21+
class OnCrmContactUpdatePayload extends AbstractItem
22+
{
23+
}

src/Services/RemoteEventsFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Bitrix24\SDK\Core\Requests\Events\UnsupportedRemoteEvent;
2424
use Bitrix24\SDK\Services\Calendar\Events\CalendarEventsFactory;
2525
use Bitrix24\SDK\Services\CRM\Company\Events\CrmCompanyEventsFactory;
26+
use Bitrix24\SDK\Services\CRM\Contact\Events\CrmContactEventsFactory;
2627
use Bitrix24\SDK\Services\Sale;
2728
use Bitrix24\SDK\Services\Telephony\Events\TelephonyEventsFabric;
2829
use Bitrix24\SDK\Services\Telephony\Events\TelephonyEventsFactory;
@@ -150,6 +151,7 @@ public static function init(LoggerInterface $logger): self
150151
new TelephonyEventsFactory(),
151152
new CalendarEventsFactory(),
152153
new CrmCompanyEventsFactory(),
154+
new CrmContactEventsFactory(),
153155
new Sale\Events\SaleEventsFactory(),
154156
],
155157
$logger

0 commit comments

Comments
 (0)