93 $config = $message->getConfiguration();
94 $clientId = $config->get(
'CLIENT_ID');
95 $accountId = $config->get(
'ACCOUNT_ID');
96 $duration = $config->get(
'DURATION');
97 $audienceId = $config->get(
'AUDIENCE_ID');
98 $status = $config->get(
'STATUS');
100 $service = Marketing\Configurator::getService();
101 $service->setClientId($clientId);
103 if(!$message->getRecipientCode())
105 $status = $config->set(
'STATUS', self::SEND_STATES[
'AUDIENCE_UPLOADED']);
106 $message->saveConfiguration($config);
109 if (!$audienceId && $message->getRecipientCode())
111 $audiences = Marketing\Configurator::createAudience(
112 Marketing\Services\AdCampaignFacebook::TYPE_CODE,
114 'accountId' => $accountId,
115 'duration' => $duration
118 $config->set(
'AUDIENCE_ID', $audiences[
'audienceId']);
119 $config->set(
'AUDIENCE_PHONE_ID', $audiences[
'phoneAudienceId']);
120 $config->set(
'AUDIENCE_EMAIL_ID', $audiences[
'emailAudienceId']);
122 $status = $config->set(
'STATUS', self::SEND_STATES[
'AUDIENCE_CREATED']);
123 $message->saveConfiguration($config);
126 if($status && in_array($status, [self::SEND_STATES[
'AUDIENCE_CREATED'],
127 self::SEND_STATES[
'AUDIENCE_UPLOADING']]))
129 return parent::send($message);