From a22bd9d2d158c387c149059be1de9bd4183eb7ba Mon Sep 17 00:00:00 2001 From: spervuhina Date: Wed, 24 Jun 2026 12:30:00 +0300 Subject: [PATCH 1/3] feat(talks): add get talks method ticket: INTEGR-3586 --- .../Collections/Talks/TalksCollection.php | 27 +++ src/AmoCRM/EntitiesServices/Talks.php | 16 +- src/AmoCRM/Filters/TalksFilter.php | 164 ++++++++++++++++++ src/AmoCRM/Models/TalkModel.php | 42 ++++- 4 files changed, 241 insertions(+), 8 deletions(-) create mode 100644 src/AmoCRM/Collections/Talks/TalksCollection.php create mode 100644 src/AmoCRM/Filters/TalksFilter.php diff --git a/src/AmoCRM/Collections/Talks/TalksCollection.php b/src/AmoCRM/Collections/Talks/TalksCollection.php new file mode 100644 index 00000000..1781962e --- /dev/null +++ b/src/AmoCRM/Collections/Talks/TalksCollection.php @@ -0,0 +1,27 @@ +|null */ + private $talkIds = null; + + /** @var array|null */ + private $entityIds = null; + + /** @var array|null */ + private $entityTypes = null; + + /** @var array|null */ + private $contactIds = null; + + /** @var bool|null */ + private $onlyInWork = null; + + /** + * @return array|null + */ + public function getTalkIds(): ?array + { + return $this->talkIds; + } + + /** + * @param array|int $talkIds + * + * @return self + */ + public function setTalkIds($talkIds): self + { + $this->talkIds = $this->parseArrayOrNumberFilter($talkIds); + + return $this; + } + + /** + * @return array|null + */ + public function getEntityIds(): ?array + { + return $this->entityIds; + } + + /** + * @param array|int $entityIds + * + * @return self + */ + public function setEntityIds($entityIds): self + { + $this->entityIds = $this->parseArrayOrNumberFilter($entityIds); + + return $this; + } + + /** + * @return array|null + */ + public function getEntityTypes(): ?array + { + return $this->entityTypes; + } + + /** + * @param array|string $entityTypes + * + * @return self + */ + public function setEntityTypes($entityTypes): self + { + $this->entityTypes = $this->parseArrayOrStringFilter($entityTypes); + + return $this; + } + + /** + * @return array|null + */ + public function getContactIds(): ?array + { + return $this->contactIds; + } + + /** + * @param array|int $contactIds + * + * @return self + */ + public function setContactIds($contactIds): self + { + $this->contactIds = $this->parseArrayOrNumberFilter($contactIds); + + return $this; + } + + /** + * @return bool|null + */ + public function getOnlyInWork(): ?bool + { + return $this->onlyInWork; + } + + /** + * @param bool $onlyInWork + * + * @return self + */ + public function setOnlyInWork(bool $onlyInWork): self + { + $this->onlyInWork = $onlyInWork; + + return $this; + } + + /** + * @return array + */ + public function buildFilter(): array + { + $filter = []; + + if (!is_null($this->getTalkIds())) { + $filter['filter']['talk_id'] = $this->getTalkIds(); + } + + if (!is_null($this->getEntityIds())) { + $filter['filter']['entity_id'] = $this->getEntityIds(); + } + + if (!is_null($this->getEntityTypes())) { + $filter['filter']['entity_type'] = $this->getEntityTypes(); + } + + if (!is_null($this->getContactIds())) { + $filter['filter']['contact_id'] = $this->getContactIds(); + } + + if (!is_null($this->getOnlyInWork())) { + $filter['filter']['only_in_work'] = $this->getOnlyInWork(); + } + + return $this->buildPagesFilter($filter); + } +} diff --git a/src/AmoCRM/Models/TalkModel.php b/src/AmoCRM/Models/TalkModel.php index 920edfab..f644abbf 100644 --- a/src/AmoCRM/Models/TalkModel.php +++ b/src/AmoCRM/Models/TalkModel.php @@ -8,6 +8,12 @@ class TalkModel extends BaseApiModel { + public const STATUS_IN_WORK = 'in_work'; + public const STATUS_CLOSED = 'closed'; + public const STATUS_WITH_ERROR = 'with_error'; + public const STATUS_NPS_SCHEDULED = 'nps_scheduled'; + public const STATUS_NPS_IN_PROGRESS = 'nps_in_progress'; + /** @var int */ protected $talkId; /** @var int */ @@ -24,6 +30,8 @@ class TalkModel extends BaseApiModel protected $entityId; /** @var string|null */ protected $entityType; + /** @var string|null */ + protected $status; /** @var bool */ protected $isInWork; /** @var bool */ @@ -31,6 +39,8 @@ class TalkModel extends BaseApiModel /** @var string */ protected $origin; /** @var int|null */ + protected $sourceId; + /** @var int|null */ protected $missedAt; /** @var int */ protected $accountId; @@ -49,11 +59,13 @@ public static function fromArray(array $talk): self ->setRate((int)$talk['rate']) ->setContactId((int)$talk['contact_id']) ->setChatId(empty($talk['chat_id']) ? null : (string)$talk['chat_id']) - ->setEntityId(empty($talk['entity_id']) ?: (int)$talk['entity_id']) - ->setEntityType(empty($talk['entity_type']) ?: (string)$talk['entity_type']) + ->setEntityId(empty($talk['entity_id']) ? null : (int)$talk['entity_id']) + ->setEntityType(empty($talk['entity_type']) ? null : (string)$talk['entity_type']) + ->setStatus($talk['status'] ?? null) ->setIsInWork(!empty($talk['is_in_work'])) ->setIsRead(!empty($talk['is_read'])) ->setOrigin((string)($talk['origin'] ?? '')) + ->setSourceId(($talk['source_id'] ?? null) !== null ? (int)$talk['source_id'] : null) ->setMissedAt(empty($talk['missed_at']) ? null : (int)$talk['missed_at']) ->setAccountId((int)$talk['account_id']); } @@ -154,6 +166,18 @@ public function setEntityType(?string $entityType): self return $this; } + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(?string $status): self + { + $this->status = $status; + + return $this; + } + public function isInWork(): bool { return $this->isInWork; @@ -190,6 +214,18 @@ public function setOrigin(string $origin): self return $this; } + public function getSourceId(): ?int + { + return $this->sourceId; + } + + public function setSourceId(?int $sourceId): self + { + $this->sourceId = $sourceId; + + return $this; + } + public function getMissedAt(): ?int { return $this->missedAt; @@ -228,9 +264,11 @@ public function toArray(): array 'chat_id' => $this->getChatId(), 'entity_id' => $this->getEntityId(), 'entity_type' => $this->getEntityType(), + 'status' => $this->getStatus(), 'is_in_work' => $this->isInWork(), 'is_read' => $this->isRead(), 'origin' => $this->getOrigin(), + 'source_id' => $this->getSourceId(), 'missed_at' => $this->getMissedAt(), 'account_id' => $this->getAccountId(), ]; From ecdce6a25d1ff76c4959f39dfc2ffe9c678bdce8 Mon Sep 17 00:00:00 2001 From: spervuhina Date: Wed, 24 Jun 2026 14:06:05 +0300 Subject: [PATCH 2/3] fix(talks-filter): fix entity type filter ticket: INTEGR-3586 --- src/AmoCRM/Filters/TalksFilter.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/AmoCRM/Filters/TalksFilter.php b/src/AmoCRM/Filters/TalksFilter.php index b1c71082..f1e5516d 100644 --- a/src/AmoCRM/Filters/TalksFilter.php +++ b/src/AmoCRM/Filters/TalksFilter.php @@ -6,7 +6,6 @@ use AmoCRM\Filters\Interfaces\HasPagesInterface; use AmoCRM\Filters\Traits\ArrayOrNumericFilterTrait; -use AmoCRM\Filters\Traits\ArrayOrStringFilterTrait; use AmoCRM\Filters\Traits\PagesFilterTrait; use function is_null; @@ -15,7 +14,6 @@ class TalksFilter extends BaseEntityFilter implements HasPagesInterface { use PagesFilterTrait; use ArrayOrNumericFilterTrait; - use ArrayOrStringFilterTrait; /** @var array|null */ private $talkIds = null; @@ -23,8 +21,8 @@ class TalksFilter extends BaseEntityFilter implements HasPagesInterface /** @var array|null */ private $entityIds = null; - /** @var array|null */ - private $entityTypes = null; + /** @var string|null */ + private $entityType = null; /** @var array|null */ private $contactIds = null; @@ -73,21 +71,21 @@ public function setEntityIds($entityIds): self } /** - * @return array|null + * @return string|null */ - public function getEntityTypes(): ?array + public function getEntityType(): ?string { - return $this->entityTypes; + return $this->entityType; } /** - * @param array|string $entityTypes + * @param string $entityType * * @return self */ - public function setEntityTypes($entityTypes): self + public function setEntityType(string $entityType): self { - $this->entityTypes = $this->parseArrayOrStringFilter($entityTypes); + $this->entityType = $entityType; return $this; } @@ -132,9 +130,6 @@ public function setOnlyInWork(bool $onlyInWork): self return $this; } - /** - * @return array - */ public function buildFilter(): array { $filter = []; @@ -147,8 +142,8 @@ public function buildFilter(): array $filter['filter']['entity_id'] = $this->getEntityIds(); } - if (!is_null($this->getEntityTypes())) { - $filter['filter']['entity_type'] = $this->getEntityTypes(); + if (!is_null($this->getEntityType())) { + $filter['filter']['entity_type'] = $this->getEntityType(); } if (!is_null($this->getContactIds())) { From 5b7dcbce3d1059403f21c57697afd767ec90b4ab Mon Sep 17 00:00:00 2001 From: spervuhina Date: Wed, 24 Jun 2026 16:21:37 +0300 Subject: [PATCH 3/3] fix(talks-filter): fix only_in_work filter ticket: INTEGR-3586 --- src/AmoCRM/Filters/TalksFilter.php | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/AmoCRM/Filters/TalksFilter.php b/src/AmoCRM/Filters/TalksFilter.php index f1e5516d..18741643 100644 --- a/src/AmoCRM/Filters/TalksFilter.php +++ b/src/AmoCRM/Filters/TalksFilter.php @@ -27,8 +27,8 @@ class TalksFilter extends BaseEntityFilter implements HasPagesInterface /** @var array|null */ private $contactIds = null; - /** @var bool|null */ - private $onlyInWork = null; + /** @var bool */ + private $onlyInWork = false; /** * @return array|null @@ -70,19 +70,11 @@ public function setEntityIds($entityIds): self return $this; } - /** - * @return string|null - */ public function getEntityType(): ?string { return $this->entityType; } - /** - * @param string $entityType - * - * @return self - */ public function setEntityType(string $entityType): self { $this->entityType = $entityType; @@ -110,19 +102,11 @@ public function setContactIds($contactIds): self return $this; } - /** - * @return bool|null - */ - public function getOnlyInWork(): ?bool + public function getOnlyInWork(): bool { return $this->onlyInWork; } - /** - * @param bool $onlyInWork - * - * @return self - */ public function setOnlyInWork(bool $onlyInWork): self { $this->onlyInWork = $onlyInWork; @@ -150,8 +134,8 @@ public function buildFilter(): array $filter['filter']['contact_id'] = $this->getContactIds(); } - if (!is_null($this->getOnlyInWork())) { - $filter['filter']['only_in_work'] = $this->getOnlyInWork(); + if ($this->getOnlyInWork()) { + $filter['filter']['only_in_work'] = true; } return $this->buildPagesFilter($filter);