From 0544bc6efad99fef48281a6fd4d33e98b95a6321 Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 12:19:07 +0400 Subject: [PATCH 1/9] add OnVoximplantCallInit and OnVoximplantCallStart Signed-off-by: mesilov --- CHANGELOG.md | 20 +++++-- src/Application/ApplicationStatus.php | 11 ++++ src/Core/Credentials/Scope.php | 8 +++ .../Telephony/Requests/Events/Auth.php | 44 +++++++++++++++ .../Requests/Events/OnVoximplantCallInit.php | 54 ------------------- .../Events/OnVoximplantCallInit/CallData.php | 32 +++++++++++ .../OnVoximplantCallInit.php | 32 +++++++++++ .../Requests/Events/OnVoximplantCallStart.php | 29 ---------- .../Events/OnVoximplantCallStart/CallData.php | 28 ++++++++++ .../OnVoximplantCallStart.php | 29 ++++++++++ .../Application/ApplicationStatusTest.php | 12 ++++- tests/Unit/Core/Credentials/ScopeTest.php | 12 +++++ 12 files changed, 223 insertions(+), 88 deletions(-) create mode 100644 src/Services/Telephony/Requests/Events/Auth.php delete mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallInit.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallInit/OnVoximplantCallInit.php delete mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallStart.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallStart/CallData.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallStart/OnVoximplantCallStart.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6286db57..9f4e99fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,16 +3,28 @@ ## 2.0-beta.1 — 10.11.2022 ### Added + * add `Symfony\Component\Uid\Uuid` requirements -* add contracts for bitrix24 applications based on bitrix24-php-sdk - `Bitrix24\SDK\Application\Contracts`, now added `Bitrix24Account` +* add contracts for bitrix24 applications based on bitrix24-php-sdk - `Bitrix24\SDK\Application\Contracts`, now added `Bitrix24Account` * add [service builder factory](https://github.com/mesilov/bitrix24-php-sdk/issues/328) +* add method `Bitrix24\SDK\Core\Credentials\Scope::initFromString` +* add method `Bitrix24\SDK\Application\ApplicationStatus::initFromString` ### Changed -* ❗️Batch interface `BatchInterface` [renamed](https://github.com/mesilov/bitrix24-php-sdk/issues/324) to `Bitrix24\SDK\Core\Contracts\BatchOperationsInterface` + +* ❗️Batch interface `BatchInterface` [renamed](https://github.com/mesilov/bitrix24-php-sdk/issues/324) + to `Bitrix24\SDK\Core\Contracts\BatchOperationsInterface` +* ❗`Bitrix24\SDK\Services\Telephony\Requests\Events` moved to separated namespaces: + * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallInit` + to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallInit\OnVoximplantCallInit` + * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart` + to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart\OnVoximplantCallStart` ### Bugfix + * fix [typehint at ContactItemResult](https://github.com/mesilov/bitrix24-php-sdk/issues/320) * fix [return types in DealCategoryItemResult](https://github.com/mesilov/bitrix24-php-sdk/issues/322) +* fix [add auth node in telephony voximplant events requests](https://github.com/mesilov/bitrix24-php-sdk/issues/331) ### etc @@ -62,10 +74,10 @@ * method `Services\Main\Service::getAllMethods` marks as deprecated * method `Services\Main\Service::getMethodsByScope` marks as deprecated * ❗️fabric methods `Bitrix24\SDK\Core\Credentials` - renamed and now are [consistent](https://github.com/mesilov/bitrix24-php-sdk/issues/303): `createFromWebhook`, `createFromOAuth` + renamed and now are [consistent](https://github.com/mesilov/bitrix24-php-sdk/issues/303): `createFromWebhook`, `createFromOAuth` , `createFromPlacementRequest` * ❗️deleted [unused class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\ResponseDataCollection` -* ❗️deleted [redundant class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\Result` +* ❗️deleted [redundant class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\Result` * ❗️deleted [method](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `CoreBuilder::withWebhookUrl`, use method `CoreBuilder::withCredentials` diff --git a/src/Application/ApplicationStatus.php b/src/Application/ApplicationStatus.php index 54500ccf..3fefdbc8 100644 --- a/src/Application/ApplicationStatus.php +++ b/src/Application/ApplicationStatus.php @@ -116,4 +116,15 @@ public static function initFromRequest(Request $request): self { return new self($request->request->getAlpha('status')); } + + /** + * @param string $shortStatusCode + * + * @return static + * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + */ + public static function initFromString(string $shortStatusCode): self + { + return new self($shortStatusCode); + } } \ No newline at end of file diff --git a/src/Core/Credentials/Scope.php b/src/Core/Credentials/Scope.php index 123eb06c..6e64d1aa 100644 --- a/src/Core/Credentials/Scope.php +++ b/src/Core/Credentials/Scope.php @@ -100,4 +100,12 @@ public function getScopeCodes(): array { return $this->currentScope; } + + /** + * @throws \Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException + */ + public static function initFromString(string $scope): self + { + return new self(str_replace(' ', '', explode(',', $scope))); + } } \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/Auth.php b/src/Services/Telephony/Requests/Events/Auth.php new file mode 100644 index 00000000..b7c2e04a --- /dev/null +++ b/src/Services/Telephony/Requests/Events/Auth.php @@ -0,0 +1,44 @@ + Scope::initFromString((string)$this->data[$offset]), + 'status' => ApplicationStatus::initFromString((string)$this->data[$offset]), + 'user_id', 'expires_in', 'expires' => (int)$this->data[$offset], + default => parent::__get($offset), + }; + } +} + + + diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit.php deleted file mode 100644 index 753f2d67..00000000 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit.php +++ /dev/null @@ -1,54 +0,0 @@ -eventPayload['data']['CALL_ID']; - } - - /** - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException - */ - public function getCallType(): CallType - { - return CallType::initByTypeCode((int)$this->eventPayload['data']['CALL_TYPE']); - } - - /** - * @return string Line ID (numeric for leased PBX, regXXX for cloud hosted PBX, and sipXXX for office PBX). - */ - public function getAccountSearchId(): string - { - return $this->eventPayload['data']['ACCOUNT_SEARCH_ID']; - } - - /** - * @return string Number called by the operator (if call type is: 1 – Outbound) or number called by the subscriber (if call type is: 2 – Inbound). - */ - public function getPhoneNumber(): string - { - return $this->eventPayload['data']['PHONE_NUMBER']; - } - - /** - * @return string Line identifier (if call type is: 1 – Outbound) or telephone number used to make a call to the portal (if call type is: 2 – Inbound). - */ - public function getCallerId(): string - { - return $this->eventPayload['data']['CALLER_ID']; - } -} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php new file mode 100644 index 00000000..565ed6d7 --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php @@ -0,0 +1,32 @@ + CallType::initByTypeCode((int)$this->data[$offset]), + 'REST_APP_ID' => (int)$this->data[$offset], + default => parent::__get($offset), + }; + } +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/OnVoximplantCallInit.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/OnVoximplantCallInit.php new file mode 100644 index 00000000..2e0c2889 --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/OnVoximplantCallInit.php @@ -0,0 +1,32 @@ +eventPayload['auth']); + } + + /** + * @return \Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallInit\CallData + */ + public function getCallData(): CallData + { + return new CallData($this->eventPayload['data']); + } +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallStart.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallStart.php deleted file mode 100644 index 11df4201..00000000 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallStart.php +++ /dev/null @@ -1,29 +0,0 @@ -eventPayload['data']['CALL_ID']; - } - - /** - * @return int Identifier of the user who responded the call. - */ - public function getUserId(): int - { - return (int)$this->eventPayload['data']['USER_ID']; - } -} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/CallData.php new file mode 100644 index 00000000..86a08f01 --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/CallData.php @@ -0,0 +1,28 @@ + (int)$this->data[$offset], + default => parent::__get($offset), + }; + } +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/OnVoximplantCallStart.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/OnVoximplantCallStart.php new file mode 100644 index 00000000..6138ac4f --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallStart/OnVoximplantCallStart.php @@ -0,0 +1,29 @@ +eventPayload['auth']); + } + /** + * @return \Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart\CallData + */ + public function getCallData(): CallData + { + return new CallData($this->eventPayload['data']); + } +} \ No newline at end of file diff --git a/tests/Unit/Application/ApplicationStatusTest.php b/tests/Unit/Application/ApplicationStatusTest.php index cdf70fb6..d768b0e4 100644 --- a/tests/Unit/Application/ApplicationStatusTest.php +++ b/tests/Unit/Application/ApplicationStatusTest.php @@ -19,7 +19,7 @@ class ApplicationStatusTest extends TestCase * @dataProvider statusDataProvider * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException */ - public function testGetStatusCode(string $shortCode, string $longCode) + public function testGetStatusCode(string $shortCode, string $longCode): void { $this->assertEquals( $longCode, @@ -36,6 +36,16 @@ public function testInvalidStatusCode(): void new ApplicationStatus('foo'); } + /** + * @return void + * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + * @covers \Bitrix24\SDK\Application\ApplicationStatus::initFromString + */ + public function testInitFromString(): void + { + $this->assertTrue(ApplicationStatus::initFromString('F')->isFree()); + } + /** * @return \Generator */ diff --git a/tests/Unit/Core/Credentials/ScopeTest.php b/tests/Unit/Core/Credentials/ScopeTest.php index 5ffd952d..d7d37b32 100644 --- a/tests/Unit/Core/Credentials/ScopeTest.php +++ b/tests/Unit/Core/Credentials/ScopeTest.php @@ -82,4 +82,16 @@ public function testWrongScopeCode(): void $this->assertEquals(['crm', 'call', 'im'], $scope->getScopeCodes()); } + + /** + * @return void + * @throws \Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException + * @covers \Bitrix24\SDK\Core\Credentials\Scope::initFromString + * @testdox Test init Scope from string + */ + public function testInitFromString(): void + { + $scope = Scope::initFromString('crm,telephony,call,user_basic,placement,im,imopenlines'); + $this->assertEquals(['crm', 'telephony', 'call', 'user_basic', 'placement', 'im', 'imopenlines'], $scope->getScopeCodes()); + } } From c834b376902d856e7cae3940e00e1835cd2666b8 Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 12:38:23 +0400 Subject: [PATCH 2/9] add OnExternalCallStart Signed-off-by: mesilov --- CHANGELOG.md | 2 + .../Telephony/Requests/Events/Auth.php | 5 +- .../Requests/Events/OnExternalCallStart.php | 95 ------------------- .../Events/OnExternalCallStart/CallData.php | 42 ++++++++ .../OnExternalCallStart.php | 30 ++++++ 5 files changed, 75 insertions(+), 99 deletions(-) delete mode 100644 src/Services/Telephony/Requests/Events/OnExternalCallStart.php create mode 100644 src/Services/Telephony/Requests/Events/OnExternalCallStart/CallData.php create mode 100644 src/Services/Telephony/Requests/Events/OnExternalCallStart/OnExternalCallStart.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f4e99fe..fcdb5b57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallInit\OnVoximplantCallInit` * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart` to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart\OnVoximplantCallStart` + * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnExternalCallStart` + to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnExternalCallStart\OnExternalCallStart` ### Bugfix diff --git a/src/Services/Telephony/Requests/Events/Auth.php b/src/Services/Telephony/Requests/Events/Auth.php index b7c2e04a..a0a3dadd 100644 --- a/src/Services/Telephony/Requests/Events/Auth.php +++ b/src/Services/Telephony/Requests/Events/Auth.php @@ -38,7 +38,4 @@ public function __get($offset) default => parent::__get($offset), }; } -} - - - +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnExternalCallStart.php b/src/Services/Telephony/Requests/Events/OnExternalCallStart.php deleted file mode 100644 index 6361a3c1..00000000 --- a/src/Services/Telephony/Requests/Events/OnExternalCallStart.php +++ /dev/null @@ -1,95 +0,0 @@ -eventPayload['data']['USER_ID']; - } - - /** - * @return string Outbound call ID. - */ - public function getPhoneNumber(): string - { - return $this->eventPayload['data']['PHONE_NUMBER']; - } - - /** - * @return string - */ - public function getPhoneNumberInternational(): string - { - return $this->eventPayload['data']['PHONE_NUMBER_INTERNATIONAL']; - } - - /** - * @return \Bitrix24\SDK\Services\Telephony\Common\CrmEntityType - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException - */ - public function getCrmEntityType(): CrmEntityType - { - return CrmEntityType::initByCode($this->eventPayload['data']['CRM_ENTITY_TYPE']); - } - - /** - * @return int The CRM object ID, which type is specified in CRM_ENTITY_TYPE. - */ - public function getCrmEntityId(): int - { - return (int)$this->eventPayload['data']['CRM_ENTITY_ID']; - } - - /** - * @return int Call list ID, if the call is made from the call list. - */ - public function getCallListId(): int - { - return (int)$this->eventPayload['data']['CALL_LIST_ID']; - } - - /** - * @return string External line number, via which the the call is requested. - */ - public function getLineNumber(): string - { - return $this->eventPayload['data']['LINE_NUMBER']; - } - - /** - * @return string Call ID from the telephony.externalcall.register method. - */ - public function getCallId(): string - { - return $this->eventPayload['data']['CALL_ID']; - } - - /** - * @return string - */ - public function getExtension(): string - { - return $this->eventPayload['data']['EXTENSION']; - } - - /** - * @return bool Defines call as initiated from the mobile app. - */ - public function isMobile(): bool - { - return !($this->eventPayload['data']['IS_MOBILE'] === '0'); - } -} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnExternalCallStart/CallData.php b/src/Services/Telephony/Requests/Events/OnExternalCallStart/CallData.php new file mode 100644 index 00000000..6a876d0d --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnExternalCallStart/CallData.php @@ -0,0 +1,42 @@ + (int)$this->data[$offset] !== 0, + 'CALL_TYPE' => CallType::initByTypeCode((int)$this->data[$offset]), + 'CRM_ENTITY_TYPE' => (string)$this->data[$offset], + 'REST_APP_ID', 'CALL_LIST_ID', 'CRM_CREATED_LEAD', 'CRM_ENTITY_ID', 'USER_ID' => (int)$this->data[$offset], + default => parent::__get($offset), + }; + } +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnExternalCallStart/OnExternalCallStart.php b/src/Services/Telephony/Requests/Events/OnExternalCallStart/OnExternalCallStart.php new file mode 100644 index 00000000..a15f1318 --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnExternalCallStart/OnExternalCallStart.php @@ -0,0 +1,30 @@ +eventPayload['data']); + } + + /** + * @return \Bitrix24\SDK\Services\Telephony\Requests\Events\Auth + */ + public function getAuth(): Auth + { + return new Auth($this->eventPayload['auth']); + } +} \ No newline at end of file From a4152a624e06f7d0bb9c4014baa53b81df2ed68a Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 13:31:32 +0400 Subject: [PATCH 3/9] fix data structure in CallData Signed-off-by: mesilov --- .../Requests/Events/OnVoximplantCallInit/CallData.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php index 565ed6d7..383db9bb 100644 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallInit/CallData.php @@ -8,10 +8,13 @@ use Bitrix24\SDK\Services\Telephony\Common\CallType; /** - * @property-read string $CALL_ID - * @property-read string $CALLER_ID - * @property-read int $REST_APP_ID - * @property-read CallType $CALL_TYPE + * @property-read string|null $ACCOUNT_SEARCH_ID Line ID (numeric for leased PBX, regXXX for cloud hosted PBX, and sipXXX for office PBX). + * @property-read string $CALL_ID Call identifier. + * @property-read string|null $PHONE_NUMBER Number called by the operator (if call type is: 1 – Outbound) or number called by the subscriber (if call type is: 2 – Inbound). + * @property-read string $CALLER_ID Line identifier (if call type is: 1 – Outbound) or telephone number used to make a call to the portal (if call type is: 2 – Inbound). + * @property-read int $REST_APP_ID + * @property-read CallType $CALL_TYPE Call type (see Call Type Description). https://training.bitrix24.com/rest_help/scope_telephony/codes_and_types.php#call_type + * @link https://training.bitrix24.com/rest_help/scope_telephony/voximplant/events/onvoximplantcallInit.php */ class CallData extends AbstractItem { From 6a13fee873f4acb4c760706b431aeb77c1dbaa50 Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 13:54:23 +0400 Subject: [PATCH 4/9] add OnVoximplantCallEnd event Signed-off-by: mesilov --- CHANGELOG.md | 2 + .../Requests/Events/OnVoximplantCallEnd.php | 114 ------------------ .../Events/OnVoximplantCallEnd/CallData.php | 66 ++++++++++ .../OnVoximplantCallEnd.php | 35 ++++++ 4 files changed, 103 insertions(+), 114 deletions(-) delete mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallEnd.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php create mode 100644 src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/OnVoximplantCallEnd.php diff --git a/CHANGELOG.md b/CHANGELOG.md index fcdb5b57..77d49a4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallStart\OnVoximplantCallStart` * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnExternalCallStart` to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnExternalCallStart\OnExternalCallStart` + * from `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallEnd` + to `Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallEnd\OnVoximplantCallEnd` ### Bugfix diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd.php deleted file mode 100644 index ff0229f4..00000000 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd.php +++ /dev/null @@ -1,114 +0,0 @@ -eventPayload['data']['CALL_ID']; - } - - /** - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException - */ - public function getCallType(): CallType - { - return CallType::initByTypeCode((int)$this->eventPayload['data']['CALL_TYPE']); - } - - /** - * @return string Number used by the subscriber to make a call (if call type is: 2 – Inbound) or number called by the operator (if call type is: 1 – Outbound). - */ - public function getPhoneNumber(): string - { - return $this->eventPayload['data']['PHONE_NUMBER']; - } - - /** - * @return string Number receiving the call (if call type is: 2 – Inbound) or number from which the call was made (if call type is: 1 – Outbound). - */ - public function getPortalNumber(): string - { - return $this->eventPayload['data']['PORTAL_NUMBER']; - } - - /** - * @return int Responding operator ID (if call type is: 2 – Inbound) or identifier of the calling operator (if call type is: 1 – Outbound). - */ - public function getPortalUserId(): int - { - return (int)$this->eventPayload['data']['PORTAL_USER_ID']; - } - - /** - * @return int Call duration. - */ - public function getCallDuration(): int - { - return (int)$this->eventPayload['data']['CALL_DURATION']; - } - - /** - * @return \DateTimeImmutable Date in ISO format. - */ - public function getCallStartDate(): DateTimeImmutable - { - return DateTimeImmutable::createFromFormat(DATE_ATOM, $this->eventPayload['data']['CALL_START_DATE']); - } - - /** - * @return \Money\Money Call cost. - */ - public function getCost(): Money - { - if ($this->eventPayload['COST'] === '') { - return new Money(0, new Currency($this->eventPayload['data']['COST_CURRENCY'])); - } - - return (new DecimalMoneyParser(new ISOCurrencies()))->parse( - $this->eventPayload['data']['COST'], - $this->eventPayload['data']['COST_CURRENCY'] - ); - } - - /** - * @return int Call code (See Call Code Table). - */ - public function getCallFailedCode(): int - { - return (int)$this->eventPayload['data']['CALL_FAILED_CODE']; - } - - /** - * @return string Call code textual description (Latin letters). - */ - public function getCallFailedReason(): string - { - return $this->eventPayload['data']['CALL_FAILED_REASON']; - } - - /** - * @return int - */ - public function getCrmActivityId(): int - { - return (int)$this->eventPayload['data']['CRM_ACTIVITY_ID']; - } -} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php new file mode 100644 index 00000000..de70f004 --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php @@ -0,0 +1,66 @@ +data[$offset]); + case 'CALL_TYPE': + return CallType::initByTypeCode((int)$this->data[$offset]); + case 'CALL_DURATION': + case 'CALL_FAILED_CODE': + case 'CRM_ACTIVITY_ID': + case 'PORTAL_USER_ID': + return (int)$this->data[$offset]; + case 'COST_CURRENCY': + return new Currency($this->data[$offset]); + case 'COST': + if ($this->data[$offset] === null) { + return new Money(0, new Currency($this->data['COST_CURRENCY'])); + } + + return (new DecimalMoneyParser(new ISOCurrencies()))->parse( + $this->data[$offset], + new Currency($this->data['COST_CURRENCY']) + ); + default: + parent::__get($offset); + } + } +} \ No newline at end of file diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/OnVoximplantCallEnd.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/OnVoximplantCallEnd.php new file mode 100644 index 00000000..1b0697ad --- /dev/null +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/OnVoximplantCallEnd.php @@ -0,0 +1,35 @@ +eventPayload['auth']); + } + + /** + * @return \Bitrix24\SDK\Services\Telephony\Requests\Events\OnVoximplantCallEnd\CallData + */ + public function getCallData(): CallData + { + return new CallData($this->eventPayload['data']); + } +} \ No newline at end of file From b41b1772e7874fc8f3d23d7e50559d4a9dd206b5 Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 20:05:08 +0400 Subject: [PATCH 5/9] add OnVoximplantCallEnd event Signed-off-by: mesilov --- .../Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php index de70f004..c3a4cc1d 100644 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php @@ -39,6 +39,8 @@ class CallData extends AbstractItem public function __get($offset) { switch ($offset) { + case 'CALL_ID': + return (string)$this->data[$offset]; case 'CALL_START_DATE': return new \DateTimeImmutable((string)$this->data[$offset]); case 'CALL_TYPE': From e2aa435cf438fc26c7bc24c35b516abefec9515e Mon Sep 17 00:00:00 2001 From: mesilov Date: Wed, 23 Nov 2022 20:09:17 +0400 Subject: [PATCH 6/9] fix OnVoximplantCallEnd event Signed-off-by: mesilov --- .../Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php index c3a4cc1d..b8ddfbd0 100644 --- a/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php +++ b/src/Services/Telephony/Requests/Events/OnVoximplantCallEnd/CallData.php @@ -62,7 +62,7 @@ public function __get($offset) new Currency($this->data['COST_CURRENCY']) ); default: - parent::__get($offset); + return parent::__get($offset); } } } \ No newline at end of file From 43f0f3afb98cc2d99d2e7d6dbeb4257da6f053cf Mon Sep 17 00:00:00 2001 From: mesilov Date: Mon, 30 Jan 2023 17:30:02 +0400 Subject: [PATCH 7/9] bump php-version Signed-off-by: mesilov --- CHANGELOG.md | 1 + composer.json | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d49a4c..ea66c7ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * add [service builder factory](https://github.com/mesilov/bitrix24-php-sdk/issues/328) * add method `Bitrix24\SDK\Core\Credentials\Scope::initFromString` * add method `Bitrix24\SDK\Application\ApplicationStatus::initFromString` +* ❗️add php 8.2 support ### Changed diff --git a/composer.json b/composer.json index 82df0352..e2dc8095 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "require": { - "php": "8.1.*", + "php": "8.1.* || 8.2.*", "ext-json": "*", "ext-bcmath": "*", "ext-curl": "*", @@ -33,7 +33,7 @@ "symfony/event-dispatcher": "5.4.* || 6.*", "ramsey/uuid": "^4.2.3", "moneyphp/money": "3.* || 4.*", - "symfony/uid": "^6.0", + "symfony/uid": "6.*", "ext-intl": "*" }, "require-dev": { @@ -44,8 +44,7 @@ "phpstan/phpstan": "1.*", "phpunit/phpunit": "9.5.*", "symfony/stopwatch": "5.4.* || 6.*", - "roave/security-advisories": "dev-master", - "ext-intl": "*" + "roave/security-advisories": "dev-master" }, "autoload": { "psr-4": { From 1be62914d99487cf1d3f99772029d5dd49290b0b Mon Sep 17 00:00:00 2001 From: mesilov Date: Fri, 17 Feb 2023 16:49:58 +0400 Subject: [PATCH 8/9] bump php-version in ci Signed-off-by: mesilov --- .github/workflows/integration.yml | 3 +-- .github/workflows/phpstan.yml | 4 ++-- .github/workflows/phpunit.yml | 3 ++- .github/workflows/vendor-check.yml | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 0137cbe9..bb8210c7 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.1" dependencies: [ highest ] steps: @@ -36,7 +36,6 @@ jobs: ini-values: variables_order=EGPCS env: BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK: ${{ secrets.BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK }} - TEST2_ENV: 12345 - name: "Install dependencies" run: | diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index ea58e758..d2826503 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -13,8 +13,8 @@ jobs: fail-fast: false matrix: php-version: - - "7.4" - - "8.0" + - "8.1" + - "8.2" dependencies: - "lowest" - "highest" diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 725bb64a..e1512640 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,7 +16,8 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.1" + - "8.2" dependencies: [ highest ] steps: diff --git a/.github/workflows/vendor-check.yml b/.github/workflows/vendor-check.yml index 802c6d45..beaa80f5 100644 --- a/.github/workflows/vendor-check.yml +++ b/.github/workflows/vendor-check.yml @@ -20,6 +20,7 @@ jobs: matrix: php-version: - "8.1" + - "8.2" dependencies: [ highest ] steps: From c939de946451498ba95d57b21539ba8ee83332e8 Mon Sep 17 00:00:00 2001 From: mesilov Date: Fri, 17 Feb 2023 17:20:44 +0400 Subject: [PATCH 9/9] fix phpdoc Signed-off-by: mesilov --- src/Application/ApplicationStatus.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Application/ApplicationStatus.php b/src/Application/ApplicationStatus.php index 3fefdbc8..fc65ebc4 100644 --- a/src/Application/ApplicationStatus.php +++ b/src/Application/ApplicationStatus.php @@ -20,7 +20,7 @@ class ApplicationStatus /** * @param string $statusShortCode * - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ public function __construct(string $statusShortCode) { @@ -107,10 +107,10 @@ public function getStatusCode(): string } /** - * @param \Symfony\Component\HttpFoundation\Request $request + * @param Request $request * * @return self - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ public static function initFromRequest(Request $request): self { @@ -120,8 +120,8 @@ public static function initFromRequest(Request $request): self /** * @param string $shortStatusCode * - * @return static - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + * @return self + * @throws InvalidArgumentException */ public static function initFromString(string $shortStatusCode): self {