Last active
April 16, 2018 21:01
-
-
Save OliPassey/f9871906cf286970acfe8af24bf82046 to your computer and use it in GitHub Desktop.
Simple PHP script to send push notifications to Alexa / Amazon Echo via NotifyMe
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
// Takes CLI arguments, or $_GET requests (in the form `http://host.name/path/filename.php?notification=whaddup`). | |
<?php | |
if (isset($argv) && count($argv) > 1) { | |
array_shift($argv); | |
$notificationText = implode(' ', $argv); | |
} else if (isset($_GET['notification'])) { | |
$notificationText = $_GET['notification']; | |
} else { | |
$notificationText = 'Hey Oli'; | |
} | |
$accessCode = "API-KEY-REMOVED"; | |
$path = 'https://api.notifymyecho.com/v1/NotifyMe'; | |
// ---- DONUT TOUCH --------------------------------------- | |
$data = [ | |
'notification' => $notificationText, | |
'accessCode' => $accessCode | |
]; | |
$dataString = json_encode($data); | |
$curl = curl_init($path); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($curl, CURLOPT_POST, TRUE); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, [ | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($dataString), | |
]); | |
$output = json_decode(curl_exec($curl)); | |
echo(print_r($output, true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment