public function handleRequest($skill) { $response = "This request is not configured"; $app = $this->getApp(); file_put_contents("/var/tmp/alexa", $app->request->getBody()); $data = json_decode($app->request->getBody(), TRUE); $type = $data['request']['type']; $alexa_jobs = $app->config('alexa'); foreach ($alexa_jobs as $an_alexa_job) { if ($an_alexa_job['skill'] == $skill && $an_alexa_job['type'] == $type) { if ($an_alexa_job['type'] == 'LaunchRequest') { require_once 'lib/Jobs.php'; $job_runner = new \HomeData\Jobs(); if ($job_runner->runJob($an_alexa_job['job'])) { $response = $an_alexa_job['response']; } else { $response = "Error running job"; } } elseif ($an_alexa_job['type'] == 'IntentRequest') { $intent_data = $data['request']['intent']; if ($intent_data['name'] == $an_alexa_job['name']) { require_once 'lib/Jobs.php'; $job_runner = new \HomeData\Jobs(); if ($job_runner->runJob($an_alexa_job['job'], $intent_data)) { $response = $an_alexa_job['response']; } else { $response = "Error running job"; } } } } } $app->response->headers->set('Content-Type', 'application/json'); $app->response->write(json_encode(array('version' => "1.0", 'shouldEndSession' => true, 'response' => array('outputSpeech' => array('type' => 'PlainText', 'text' => $response))))); }
public function changeLocationForPerson($username, $action, $location) { if (!in_array(strtolower($action), $this->getAllowableActions())) { $this->returnError(400, "{$action} is not a valid action"); } if (!in_array(strtolower($location), $this->getAllowableLocations())) { $this->returnError(400, "{$location} is not a valid location"); } $app = $this->getApp(); $person_dao = $this->getPersonDAO(); $person = $person_dao->getPerson($username); if (!empty($person)) { $this->doPreChecks(); $data = array('location_action' => $action, 'location_name' => $location, 'location_timestamp' => time()); $person_dao->updatePerson($username, $data); $state = $app->config('state'); if (is_null($state)) { $state = array(); } $state['who_last_action'] = $username; $state['action_last_action'] = $action; $state['location_last_action'] = $location; $app->config('state', $state); $this->doPostChecks(); //ExecuteJobs $job_runner = new \HomeData\Jobs(); $executed_jobs = $job_runner->checkAll(); $return_data = ['success' => true, 'state' => $app->config('state')]; if (!empty($executed_jobs)) { $return_data['executed_jobs'] = $executed_jobs; } $app->response->headers->set('Content-Type', 'application/json'); $app->response->write(json_encode($return_data)); } else { $this->return404("Person {$username}, does not exist"); } }