/**
  * Send Clockwork request message
  *
  * @param   Message|\Model $objMessage
  * @param   array          $arrTokens
  * @param   string         $strLanguage
  *
  * @return  bool
  */
 public function send(Message $objMessage, array $arrTokens, $strLanguage = '')
 {
     if ($this->objModel->clockwork_api_key == '') {
         \System::log(sprintf('Please provide the Clockwork API key for message ID "%s"', $objMessage->id), __METHOD__, TL_ERROR);
         return false;
     }
     /** @var ClockworkSmsMessageDraft $objDraft */
     $objDraft = $this->createDraft($objMessage, $arrTokens, $strLanguage);
     // return false if no language found for BC
     if ($objDraft === null) {
         return false;
     }
     $arrMessages = array();
     //@todo We're waiting for a proper official composer integration of Clockwork. While so, a fork (used below) does it too
     $objClockwork = new \Clockwork($this->objModel->clockwork_api_key, array('from' => $objDraft->getFrom(), 'long' => (bool) $objMessage->long, 'truncate' => (bool) $objMessage->truncate));
     foreach ($objDraft->getRecipients() as $recipient) {
         $arrMessages[] = array('to' => $recipient, 'message' => $objDraft->getText());
     }
     try {
         $result = $objClockwork->send($arrMessages);
     } catch (\ClockworkException $e) {
         \System::log(sprintf('Error with message "%s" (Code %s) while sending the Clockwork request for message ID "%s" occurred.', $e->getMessage(), $e->getCode(), $objMessage->id), __METHOD__, TL_ERROR);
         return false;
     }
     $blnError = false;
     foreach ($result as $message) {
         if (!$message['success']) {
             \System::log(sprintf('Error with message "%s" (Code %s) while sending the Clockwork request for message ID "%s" occurred.', $message['error_message'], $message['error_code'], $objMessage->id), __METHOD__, TL_ERROR);
             $blnError = true;
         }
     }
     return !$blnError;
 }
 public function send_sms($api, $args)
 {
     try {
         $error_array = $this->validate_args($args);
         if (!is_null($error_array)) {
             return $error_array;
         }
         $api_key = $this->getApiKeyFromConfig();
         $sms_body = $args['message'];
         $from_name = isset($args['from_name']) ? $args['from_name'] : 'SugarCRM';
         $GLOBALS['log']->fatal("The value of api_key is: {$api_key}");
         $clockwork = new Clockwork($api_key);
         $message = array('to' => $args['to_number'], 'message' => $sms_body, 'from' => $from_name);
         $result = $clockwork->send($message);
         return $result;
     } catch (ClockworkException $e) {
         //            $GLOBALS['log']->fatal("$e->getMessage()");
         return $e->getMessage();
     }
 }
Пример #3
0
    $flockTable = new FlockTable();
    $flockID = $_POST['flockID'];
    $flock = $flockTable->getFlockUsingFlockID($flockID);
    $sheepMobile = '44' . substr($_POST['mobile'], 1);
    $sheepID = $flockID . $sheepMobile;
    // Composite Key
    $sheep = new Sheep($sheepID, $sheepMobile, $_POST['sheepName'], NULL, NULL, false, false, false, $flockID);
    // FlockID
    if ($sheepTable->addSheep($sheep)) {
        http_response_code(200);
        $messageForSheep = "You have been added to the '" . $flock->getFlockName() . "' Flock by " . $flock->getShepherd()->getSheepName() . ". To enable tracking permission, text \"FLOCKME\" to 84433 (Texts cost 10p). Confused? Find out more at www.flockbuddy.com";
        try {
            // Create a Clockwork object using your API key
            $clockwork = new Clockwork('787b4673e0ac4b043aab8a4764f0205ab06dc309');
            // Setup and send the message
            $message = array('to' => $sheepMobile, 'message' => $messageForSheep);
            $result = $clockwork->send($message);
            // Check if the send was successful
            if ($result['success']) {
                echo 'Message sent - ID: ' . $result['id'];
            } else {
                echo 'Message failed - Error: ' . $result['error_message'];
            }
        } catch (ClockworkException $e) {
            echo 'Exception sending SMS: ' . $e->getMessage();
        }
    } else {
        http_response_code(400);
        echo " FAILED to add sheep to flock.";
    }
}
Пример #4
0
            $message = array('to' => $lostSheepNumber, 'message' => $lostSheepMessage);
            $result = $clockwork->send($message);
            // Check if the send was successful
            if ($result['success']) {
                echo 'Message sent - ID: ' . $result['id'] . ' ';
            } else {
                echo 'Message failed - Error: ' . $result['error_message'] . ' ';
            }
        } catch (ClockworkException $e) {
            echo 'Exception sending SMS: ' . $e->getMessage() . ' ';
        }
        $shepherdNumber = $shepherd->getSheepMobile();
        // TODO limit to 160 characters
        $shepherdMessage = "You have lost one of your sheep! " . $sheep->getSheepName() . " is currently " . $distanceFromShepherd . "m away! He is currently here: " . "www.google.com/maps/place/" . $newY . "," . $newX . ". You could give them a ring on " . $sheep->getSheepMobile() . " so you can explain what a silly Sheep they are. To stop tracking your flock, reply to this number and write \"FLOCKMENOT\".";
        try {
            // Create a Clockwork object using your API key
            $clockwork2 = new Clockwork('787b4673e0ac4b043aab8a4764f0205ab06dc309');
            // Setup and send a message
            $message2 = array('to' => $shepherdNumber, 'message' => $shepherdMessage);
            $result2 = $clockwork2->send($message2);
            // Check if the send was successful
            if ($result2['success']) {
                echo 'Message sent - ID: ' . $result2['id'] . ' ';
            } else {
                echo 'Message failed - Error: ' . $result2['error_message'] . ' ';
            }
        } catch (ClockworkException $e) {
            echo 'Exception sending SMS: ' . $e->getMessage() . ' ';
        }
    }
}
Пример #5
0
<?php

echo "Hello";
require "safest_route.php";
require_once "key.php";
require "clockwork/class-Clockwork.php";
function interpretClockwork($text)
{
    $message = substr($text, 9);
    $arr = explode(" to ", $message);
    return array("start" => urlencode($arr[0]), "end" => urlencode($arr[1]));
}
$phone = $_GET["from"];
$locations = interpretClockwork($_GET["content"]);
$clockwork = new Clockwork($clock_key);
$route = getSafestRoute($locations["start"], $locations["end"], true, true)[0];
$message = "(1 / 2)";
foreach ($route["instructions"] as $instruction) {
    $message .= " " . strip_tags($instruction) . "\n";
}
echo $message;
var_dump($clockwork->send(array(array("to" => $phone, "message" => "(2 / 2) The rest of your journey and a map can be viewed at http://pedalplan.tk/results.php?start={$locations['start']}&end={$locations['end']}&congestion=on&safest=on."), array("to" => $phone, "message" => $message))));