示例#1
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'));
     }
 }
示例#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()]);
 }
示例#3
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);
 }
示例#4
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);
 }