Example #1
0
 /**
  * TwilioApi constructor.
  *
  * @param TrackableModel    $pageTrackableModel
  * @param \Services_Twilio  $client
  * @param PhoneNumberHelper $phoneNumberHelper
  * @param                   $sendingPhoneNumber
  * @param Logger            $logger
  */
 public function __construct(TrackableModel $pageTrackableModel, \Services_Twilio $client, PhoneNumberHelper $phoneNumberHelper, $sendingPhoneNumber, Logger $logger)
 {
     $this->client = $client;
     $this->logger = $logger;
     if ($sendingPhoneNumber) {
         $this->sendingPhoneNumber = $phoneNumberHelper->format($sendingPhoneNumber);
     }
     parent::__construct($pageTrackableModel);
 }
Example #2
0
 public function unsubscribe($number)
 {
     $number = $this->phoneNumberHelper->format($number, PhoneNumberFormat::E164);
     /** @var \Mautic\LeadBundle\Entity\LeadRepository $repo */
     $repo = $this->em->getRepository('MauticLeadBundle:Lead');
     $args = ['filter' => ['force' => [['column' => 'mobile', 'expr' => 'eq', 'value' => $number]]]];
     $leads = $repo->getEntities($args);
     if (!empty($leads)) {
         $lead = array_shift($leads);
     } else {
         // Try to find the lead based on the given phone number
         $args['filter']['force'][0]['column'] = 'phone';
         $leads = $repo->getEntities($args);
         if (!empty($leads)) {
             $lead = array_shift($leads);
         } else {
             return false;
         }
     }
     return $this->leadModel->addDncForLead($lead, 'sms', null, DoNotContact::UNSUBSCRIBED);
 }