Skip to content

Instantly share code, notes, and snippets.

@OliPassey
Last active April 16, 2018 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliPassey/f9871906cf286970acfe8af24bf82046 to your computer and use it in GitHub Desktop.
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
// 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