Exemplo n.º 1
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerActionChangeStage(CampaignExecutionEvent $event)
 {
     $stageChange = false;
     $lead = $event->getLead();
     $leadStage = null;
     if ($lead instanceof Lead) {
         $leadStage = $lead->getStage();
     }
     $stageId = (int) $event->getConfig()['stage'];
     $stageToChangeTo = $this->stageModel->getEntity($stageId);
     if ($stageToChangeTo != null && $stageToChangeTo->isPublished()) {
         if ($leadStage && $leadStage->getWeight() <= $stageToChangeTo->getWeight()) {
             $stageChange = true;
         } elseif (!$leadStage) {
             $stageChange = true;
         }
     }
     if ($stageChange) {
         $parsed = explode('.', $stageToChangeTo->getName());
         $lead->stageChangeLogEntry($parsed[0], $stageToChangeTo->getId() . ": " . $stageToChangeTo->getName(), $event->getName());
         $lead->setStage($stageToChangeTo);
         $this->leadModel->saveEntity($lead);
     }
     return $event->setResult($stageChange);
 }
Exemplo n.º 2
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $lead = $event->getLead();
     if ($this->leadModel->isContactable($lead, 'sms') !== DoNotContact::IS_CONTACTABLE) {
         return $event->setFailed('mautic.sms.campaign.failed.not_contactable');
     }
     $leadPhoneNumber = $lead->getFieldValue('mobile');
     if (empty($leadPhoneNumber)) {
         $leadPhoneNumber = $lead->getFieldValue('phone');
     }
     if (empty($leadPhoneNumber)) {
         return $event->setFailed('mautic.sms.campaign.failed.missing_number');
     }
     $smsId = (int) $event->getConfig()['sms'];
     $sms = $this->smsModel->getEntity($smsId);
     if ($sms->getId() !== $smsId) {
         return $event->setFailed('mautic.sms.campaign.failed.missing_entity');
     }
     $smsEvent = new SmsSendEvent($sms->getMessage(), $lead);
     $smsEvent->setSmsId($smsId);
     $this->dispatcher->dispatch(SmsEvents::SMS_ON_SEND, $smsEvent);
     $tokenEvent = $this->dispatcher->dispatch(SmsEvents::TOKEN_REPLACEMENT, new TokenReplacementEvent($smsEvent->getContent(), $lead, ['channel' => ['sms', $sms->getId()]]));
     $metadata = $this->smsApi->sendSms($leadPhoneNumber, $tokenEvent->getContent());
     $defaultFrequencyNumber = $this->factory->getParameter('sms_frequency_number');
     $defaultFrequencyTime = $this->factory->getParameter('sms_frequency_time');
     /** @var \Mautic\LeadBundle\Entity\FrequencyRuleRepository $frequencyRulesRepo */
     $frequencyRulesRepo = $this->leadModel->getFrequencyRuleRepository();
     $leadIds = $lead->getId();
     $dontSendTo = $frequencyRulesRepo->getAppliedFrequencyRules('sms', $leadIds, null, $defaultFrequencyNumber, $defaultFrequencyTime);
     if (!empty($dontSendTo) and $dontSendTo[0]['lead_id'] != $lead->getId()) {
         $metadata = $this->smsApi->sendSms($leadPhoneNumber, $smsEvent->getContent());
     }
     // If there was a problem sending at this point, it's an API problem and should be requeued
     if ($metadata === false) {
         return $event->setResult(false);
     }
     $this->smsModel->createStatEntry($sms, $lead);
     $this->smsModel->getRepository()->upCount($smsId);
     $event->setChannel('sms', $sms->getId());
     $event->setResult(['type' => 'mautic.sms.sms', 'status' => 'mautic.sms.timeline.status.delivered', 'id' => $sms->getId(), 'name' => $sms->getName(), 'content' => $tokenEvent->getContent()]);
 }
Exemplo n.º 3
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $config = $event->getConfig();
     $lead = $event->getLead();
     $integration = !empty($config['integration']) ? $config['integration'] : null;
     $feature = empty($integration) ? 'push_lead' : null;
     $services = $this->integrationHelper->getIntegrationObjects($integration, $feature);
     $success = false;
     foreach ($services as $name => $s) {
         $settings = $s->getIntegrationSettings();
         if (!$settings->isPublished()) {
             continue;
         }
         if (method_exists($s, 'pushLead')) {
             if ($s->pushLead($lead, $config)) {
                 $success = true;
             }
         }
     }
     return $event->setResult($success);
 }
Exemplo n.º 4
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $lead = $event->getLead();
     if ($this->leadModel->isContactable($lead, 'notification') !== DoNotContact::IS_CONTACTABLE) {
         return $event->setFailed('mautic.notification.campaign.failed.not_contactable');
     }
     // If lead has subscribed on multiple devices, get all of them.
     /** @var \Mautic\NotificationBundle\Entity\PushID[] $pushIDs */
     $pushIDs = $lead->getPushIDs();
     $playerID = [];
     foreach ($pushIDs as $pushID) {
         $playerID[] = $pushID->getPushID();
     }
     if (empty($playerID)) {
         return $event->setFailed('mautic.notification.campaign.failed.not_subscribed');
     }
     $notificationId = (int) $event->getConfig()['notification'];
     /** @var \Mautic\NotificationBundle\Entity\Notification $notification */
     $notification = $this->notificationModel->getEntity($notificationId);
     if ($notification->getId() !== $notificationId) {
         return $event->setFailed('mautic.notification.campaign.failed.missing_entity');
     }
     if ($url = $notification->getUrl()) {
         $url = $this->notificationApi->convertToTrackedUrl($url, ['notification' => $notification->getId(), 'lead' => $lead->getId()]);
     }
     $tokenEvent = $this->dispatcher->dispatch(NotificationEvents::TOKEN_REPLACEMENT, new TokenReplacementEvent($notification->getMessage(), $lead, ['channel' => ['notification', $notification->getId()]]));
     $sendEvent = $this->dispatcher->dispatch(NotificationEvents::NOTIFICATION_ON_SEND, new NotificationSendEvent($tokenEvent->getContent(), $notification->getHeading(), $lead));
     $response = $this->notificationApi->sendNotification($playerID, $sendEvent->getMessage(), $sendEvent->getHeading(), $url);
     $event->setChannel('notification', $notification->getId());
     // If for some reason the call failed, tell mautic to try again by return false
     if ($response->code !== 200) {
         return $event->setResult(false);
     }
     $this->notificationModel->createStatEntry($notification, $lead);
     $this->notificationModel->getRepository()->upCount($notificationId);
     $result = ['status' => 'mautic.notification.timeline.status.delivered', 'type' => 'mautic.notification.notification', 'id' => $notification->getId(), 'name' => $notification->getName(), 'heading' => $event->getHeading(), 'content' => $event->getMessage()];
     $event->setResult($result);
 }
Exemplo n.º 5
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignAction(CampaignExecutionEvent $event)
 {
     $event->setChannel('social.twitter');
     if ($response = $this->helper->sendTweetAction($event->getLead(), $event->getEvent())) {
         $event->setResult($response);
     } else {
         $event->setFailed($this->translator->trans('mautic.social.twitter.error.handle_not_found'));
     }
 }
Exemplo n.º 6
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerDecision(CampaignExecutionEvent $event)
 {
     $eventDetails = $event->getEventDetails();
     if ($eventDetails == null) {
         return $event->setResult(true);
     }
     $assetId = $eventDetails->getId();
     $limitToAssets = $event->getConfig()['assets'];
     if (!empty($limitToAssets) && !in_array($assetId, $limitToAssets)) {
         //no points change
         return $event->setResult(false);
     }
     $event->setResult(true);
 }
Exemplo n.º 7
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerDecision(CampaignExecutionEvent $event)
 {
     $eventDetails = $event->getEventDetails();
     $config = $event->getConfig();
     if ($eventDetails == null) {
         return true;
     }
     $pageHit = $eventDetails->getPage();
     // Check Landing Pages
     if ($pageHit instanceof Page) {
         list($parent, $children) = $pageHit->getVariants();
         //use the parent (self or configured parent)
         $pageHitId = $parent->getId();
     } else {
         $pageHitId = 0;
     }
     $limitToPages = $config['pages'];
     $urlMatches = [];
     // Check Landing Pages URL or Tracing Pixel URL
     if (isset($config['url']) && $config['url']) {
         $pageUrl = $eventDetails->getUrl();
         $limitToUrls = explode(',', $config['url']);
         foreach ($limitToUrls as $url) {
             $url = trim($url);
             $urlMatches[$url] = fnmatch($url, $pageUrl);
         }
     }
     // **Page hit is true if:**
     // 1. no landing page is set and no URL rule is set
     $applyToAny = empty($config['url']) && empty($limitToPages);
     // 2. some landing pages are set and page ID match
     $langingPageIsHit = !empty($limitToPages) && in_array($pageHitId, $limitToPages);
     // 3. URL rule is set and match with URL hit
     $urlIsHit = !empty($config['url']) && in_array(true, $urlMatches);
     if ($applyToAny || $langingPageIsHit || $urlIsHit) {
         return $event->setResult(true);
     }
     return $event->setResult(false);
 }
Exemplo n.º 8
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $eventConfig = $event->getConfig();
     $lead = $event->getLead();
     $slot = $this->session->get('dwc.slot_name.lead.' . $lead->getId());
     $dwc = $this->dynamicContentModel->getRepository()->getEntity($eventConfig['dynamicContent']);
     if ($dwc instanceof DynamicContent) {
         // Use translation if available
         list($ignore, $dwc) = $this->dynamicContentModel->getTranslatedEntity($dwc, $lead);
         if ($slot) {
             $this->dynamicContentModel->setSlotContentForLead($dwc, $lead, $slot);
         }
         $this->dynamicContentModel->createStatEntry($dwc, $lead, $slot);
         $tokenEvent = new TokenReplacementEvent($dwc->getContent(), $lead, ['slot' => $slot, 'dynamic_content_id' => $dwc->getId()]);
         $this->dispatcher->dispatch(DynamicContentEvents::TOKEN_REPLACEMENT, $tokenEvent);
         $content = $tokenEvent->getContent();
         $event->stopPropagation();
         $result = $event->setResult($content);
         $event->setChannel('dynamicContent', $dwc->getId());
         return $result;
     }
 }
Exemplo n.º 9
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $emailSent = false;
     $lead = $event->getLead();
     $leadCredentials = $lead instanceof Lead ? $lead->getProfileFields() : $lead;
     $leadCredentials['owner_id'] = $lead instanceof Lead && ($owner = $lead->getOwner()) ? $owner->getId() : 0;
     if (!empty($leadCredentials['email'])) {
         $config = $event->getConfig();
         $emailId = (int) $config['email'];
         $email = $this->emailModel->getEntity($emailId);
         if ($email != null && $email->isPublished()) {
             // Determine if this email is transactional/marketing
             $type = isset($config['email_type']) ? $config['email_type'] : 'transactional';
             if ('marketing' == $type) {
                 // Determine if this lead has received the email before
                 $stats = $this->emailModel->getStatRepository()->findContactEmailStats($leadCredentials['id'], $emailId);
                 if (count($stats)) {
                     // Already sent
                     return $event->setResult(true);
                 }
             }
             $eventDetails = $event->getEventDetails();
             $options = ['source' => ['campaign', $eventDetails['campaign']['id']]];
             $emailSent = $this->emailModel->sendEmail($email, $leadCredentials, $options);
         }
         $event->setChannel('email', $emailId);
     }
     return $event->setResult($emailSent);
 }
Exemplo n.º 10
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerCondition(CampaignExecutionEvent $event)
 {
     $lead = $event->getLead();
     if (!$lead || !$lead->getId()) {
         return $event->setResult(false);
     }
     $operators = $this->leadModel->getFilterExpressionFunctions();
     $result = $this->leadFieldModel->getRepository()->compareValue($lead->getId(), $event->getConfig()['field'], $event->getConfig()['value'], $operators[$event->getConfig()['operator']]['expr']);
     return $event->setResult($result);
 }
Exemplo n.º 11
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerCondition(CampaignExecutionEvent $event)
 {
     $lead = $event->getLead();
     if (!$lead || !$lead->getId()) {
         return $event->setResult(false);
     }
     $operators = $this->formModel->getFilterExpressionFunctions();
     $form = $this->formModel->getRepository()->findOneById($event->getConfig()['form']);
     if (!$form || !$form->getId()) {
         return $event->setResult(false);
     }
     $result = $this->formSubmissionModel->getRepository()->compareValue($lead->getId(), $form->getId(), $form->getAlias(), $event->getConfig()['field'], $event->getConfig()['value'], $operators[$event->getConfig()['operator']]['expr']);
     $event->setChannel('form', $form->getId());
     return $event->setResult($result);
 }
Exemplo n.º 12
0
 /**
  * @param CampaignExecutionEvent $event
  */
 public function onCampaignTriggerAction(CampaignExecutionEvent $event)
 {
     $emailSent = false;
     $lead = $event->getLead();
     $leadCredentials = $lead instanceof Lead ? $lead->getProfileFields() : $lead;
     $leadCredentials['owner_id'] = $lead instanceof Lead && ($owner = $lead->getOwner()) ? $owner->getId() : 0;
     if (!empty($leadCredentials['email'])) {
         $config = $event->getConfig();
         $emailId = (int) $config['email'];
         $email = $this->emailModel->getEntity($emailId);
         $type = isset($config['email_type']) ? $config['email_type'] : 'transactional';
         $options = ['source' => ['campaign.event', $event->getEvent()['id']], 'email_attempts' => isset($config['attempts']) ? $config['attempts'] : 3, 'email_priority' => isset($config['priority']) ? $config['priority'] : 2, 'email_type' => $type];
         $event->setChannel('email', $emailId);
         if ($email != null && $email->isPublished()) {
             // Determine if this email is transactional/marketing
             $stats = [];
             if ('marketing' == $type) {
                 // Determine if this lead has received the email before
                 $leadIds = implode(',', [$leadCredentials['id']]);
                 $stats = $this->emailModel->getStatRepository()->checkContactsSentEmail($leadIds, $emailId);
                 $emailSent = true;
                 // Assume it was sent to prevent the campaign event from getting rescheduled over and over
             }
             if (empty($stats)) {
                 $emailSent = $this->emailModel->sendEmail($email, $leadCredentials, $options);
             }
         } else {
             return $event->setFailed('Email not found or published');
         }
     } else {
         return $event->setFailed('Contact does not have an email');
     }
     return $event->setResult($emailSent);
 }