This commit is contained in:
Marko Jovanovic 2025-10-02 16:23:42 +02:00
parent 986fa1d901
commit 2d265c76d2

View File

@ -70,7 +70,7 @@ class ContactUncontactedCommand extends Command
$io->progressStart(count($phoneNumbersToContact));
// 2. Loop through each eligible phone number
foreach ($phoneNumbersToContact as $phoneNumber) {
foreach ($phoneNumbersToContact as $phoneContact) {
$io->progressAdvance();
// 3. Contact the HTTP REST API
@ -79,7 +79,7 @@ class ContactUncontactedCommand extends Command
'query' => [
'producttoken' => $this->sms_gateway_api_key,
'body' => 'Bitte starten Sie die Umfrage jetzt: https://umfragetool.ukbonn.de/login?id=QMBEFR_TEST Ihr UKB.',
'to' => $phoneNumber,
'to' => $phoneContact->getPhoneNumber(),
'from' => 'UKB',
'reference' => 'Test-Reference'
]
@ -88,16 +88,16 @@ class ContactUncontactedCommand extends Command
// 4. Check the API response status
if ($response->getStatusCode() === 200) {
// 5. If successful, update the row in the database
$phoneNumber->setContacted(true);
$phoneNumber->setGatewayResponse(trim($response->getStatusCode() . ' ' . $response->getContent()));
$phoneNumber->setContactedAt(new DateTimeImmutable());
$this->entityManager->persist($phoneNumber);
$io->note(sprintf('Successfully contacted number %s', $phoneNumber->getPhoneNumber()));
$phoneContact->setContacted(true);
$phoneContact->setGatewayResponse(trim($response->getStatusCode() . ' ' . $response->getContent()));
$phoneContact->setContactedAt(new DateTimeImmutable());
$this->entityManager->persist($phoneContact);
$io->note(sprintf('Successfully contacted number %s', $phoneContact->getPhoneNumber()));
} else {
$io->warning(sprintf('API call for number %s failed with status code %s', $phoneNumber->getPhoneNumber(), $response->getStatusCode()));
$io->warning(sprintf('API call for number %s failed with status code %s', $phoneContact->getPhoneNumber(), $response->getStatusCode()));
}
} catch (Exception $e) {
$io->error(sprintf('An error occurred contacting the API for number %s: %s', $phoneNumber->getPhoneNumber(), $e->getMessage()));
$io->error(sprintf('An error occurred contacting the API for number %s: %s', $phoneContact->getPhoneNumber(), $e->getMessage()));
}
}