formatNumbers(\array_map( fn ($to) => $to, $message->getTo() )); $response = new Response($this->getType()); $result = $this->request( method: 'POST', url: 'https://rest-ww.telesign.com/v1/verify/bulk_sms', headers: [ 'Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic '.base64_encode("{$this->customerId}:{$this->apiKey}"), ], body: [ 'template' => $message->getContent(), 'recipients' => $to, ], ); if ($result['statusCode'] === 200) { $response->setDeliveredTo(\count($message->getTo())); foreach ($message->getTo() as $to) { $response->addResult($to); } } else { foreach ($message->getTo() as $to) { if (!\is_null($result['response']['errors'][0]['description'] ?? null)) { $response->addResult($to, $result['response']['errors'][0]['description']); } else { $response->addResult($to, 'Unknown error'); } } } return $response->toArray(); } /** * @param array $numbers */ private function formatNumbers(array $numbers): string { $formatted = \array_map( fn ($number) => $number.':'.\uniqid(), $numbers ); return implode(',', $formatted); } }