-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tylercd100/clickatell
Clickatell Support
- Loading branch information
Showing
10 changed files
with
238 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
build | ||
composer.lock | ||
vendor | ||
run.php | ||
run.php | ||
ubuntu-xenial-16.04-cloudimg-console.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Tylercd100\Monolog\Handler; | ||
|
||
use Exception; | ||
use Monolog\Logger; | ||
|
||
/** | ||
* Clickatell - Monolog Handler | ||
* @url https://www.clickatell.com/developers/api-documentation/rest-api-request-parameters | ||
*/ | ||
class ClickatellHandler extends SMSHandler | ||
{ | ||
/** | ||
* API version 1 | ||
*/ | ||
const API_V1 = '2010-04-01'; | ||
|
||
/** | ||
* @param string $secret Twilio API Secret Token | ||
* @param string $fromNumber The phone number that will be shown as the sender ID | ||
* @param string $toNumber The phone number to which the message will be sent | ||
* @param int $level The minimum logging level at which this handler will be triggered | ||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not | ||
* @param bool $useSSL Whether to connect via SSL. | ||
* @param string $host The Twilio server hostname. | ||
* @param string $version The Twilio API version (default ClickatellHandler::API_V1) | ||
* @param int $limit The character limit | ||
*/ | ||
public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) | ||
{ | ||
if ($version !== self::API_V1) { | ||
throw new Exception("API Version \'{$version}\' is not supported!"); | ||
} | ||
parent::__construct($secret, null, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param array $record | ||
* @return string | ||
*/ | ||
protected function buildContent($record) | ||
{ | ||
if (strlen($record['formatted']) > $this->limit) { | ||
$record['formatted'] = substr($record['formatted'], 0, $this->limit); | ||
} | ||
|
||
$dataArray = [ | ||
'content' => $record['formatted'], | ||
'to' => (!is_array($this->toNumber)? [$this->toNumber] : $this->toNumber) | ||
]; | ||
|
||
($this->fromNumber)? $dataArray['from'] = $this->fromNumber : false; | ||
|
||
return json_encode($dataArray); | ||
} | ||
|
||
/** | ||
* Builds the URL for the API call | ||
* | ||
* @return string | ||
*/ | ||
protected function buildRequestUrl() | ||
{ | ||
return "POST /messages HTTP/1.1\r\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.