Send status report
This commit is contained in:
parent
81147ad032
commit
849f97d56a
|
|
@ -69,9 +69,12 @@ class ContactUncontactedCommand extends Command
|
|||
|
||||
$io->progressStart(count($phoneNumbersToContact));
|
||||
|
||||
$countSent = 0;
|
||||
$countTotal = 0;
|
||||
// 2. Loop through each eligible phone number
|
||||
foreach ($phoneNumbersToContact as $phoneContact) {
|
||||
$io->progressAdvance();
|
||||
$countTotal++;
|
||||
|
||||
// 3. Contact the HTTP REST API
|
||||
try {
|
||||
|
|
@ -111,11 +114,42 @@ class ContactUncontactedCommand extends Command
|
|||
} else {
|
||||
$io->warning(sprintf('API call for number %s failed with status code %s', $phoneContact->getPhoneNumber(), $response->getStatusCode()));
|
||||
}
|
||||
$countSent++;
|
||||
} catch (Exception $e) {
|
||||
$io->error(sprintf('An error occurred contacting the API for number %s: %s', $phoneContact->getPhoneNumber(), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$responseStatus = $this->httpClient->request('POST', self::$apiEndpoint, [
|
||||
'headers' => [
|
||||
'X-CM-PRODUCTTOKEN' => $this->sms_gateway_api_key,
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json'
|
||||
],
|
||||
|
||||
'body' => "{
|
||||
'messages': { 'msg': [{
|
||||
'allowedChannels': ['SMS'],
|
||||
'from': 'UKB',
|
||||
'to': [
|
||||
{ 'number': '004917672121270' }
|
||||
],
|
||||
'body': {
|
||||
'type': 'auto',
|
||||
'content': 'SMS-Versand-Update: Insg. {$countSent} versendet. Total versucht: {$countTotal}.'
|
||||
},
|
||||
'minimumNumberOfMessageParts': 1,
|
||||
'maximumNumberOfMessageParts': 8,
|
||||
'reference': 'UKB'
|
||||
}] }}"
|
||||
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
$io->error(sprintf('An error occurred contacting the API for number %s: %s', '004917672121270', $e->getMessage()));
|
||||
}
|
||||
|
||||
|
||||
// Finalize all database changes
|
||||
$this->entityManager->flush();
|
||||
$io->progressFinish();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user