public static function pull() { foreach (sms::byType('sms') as $eqLogic) { try { if ($eqLogic->getIsEnable() == 1) { $cmds = $eqLogic->getCmd(); foreach ($eqLogic->readInbox() as $message) { $eqLogic->deleteSms($message['id']); $autorized = false; foreach ($cmds as $cmd) { $formatedPhoneNumber = '+33' . substr($cmd->getConfiguration('phonenumber'), 1); if ($cmd->getConfiguration('phonenumber') == $message['phonenumber'] || $formatedPhoneNumber == $message['phonenumber']) { $autorized = true; break; } } $reply = ''; if ($autorized) { $reply = interactQuery::tryToReply(trim($message['message']), array()); if (trim($reply) != '') { $eqLogic->sendSMS($message['phonenumber'], self::cleanSMS($reply)); } } log::add('sms', 'info', 'Message venant de ' . $formatedPhoneNumber . ' : ' . trim($message['message']) . "\nRéponse : " . $reply); } } } catch (Exception $e) { $eqLogic->setIsEnable(0); $eqLogic->save(); throw $e; } } }
public static function generateXmlGrammar() { $xmlWildcard = ''; $xml = "<grammar version=\"1.0\" xml:lang=\"fr-FR\" mode=\"voice\" root=\"ruleJeedom\" xmlns=\"http://www.w3.org/2001/06/grammar\" tag-format=\"semantics/1.0\">\r\n"; $xml .= "<rule id=\"ruleJeedom\" scope=\"public\">\r\n"; $xml .= "<tag>out.action=new Object(); </tag>\r\n"; $xml .= "<item>Sarah</item>\r\n"; $xml .= "<one-of>\r\n"; foreach (interactQuery::all() as $interactQuery) { if ($interactQuery->getEnable() == 1) { $query = $interactQuery->getQuery(); preg_match_all("/#(.*?)#/", $query, $matches); $matches = $matches[1]; if (count($matches) > 0) { $xmlWildcard .= "<rule id=\"ruleJeedom_" . $interactQuery->getId() . "\" scope=\"public\">\r\n"; $xmlWildcard .= "<tag>out.action=new Object();</tag>\r\n"; foreach ($matches as $match) { $beforeMatch = substr($query, 0, strpos($query, "#" . $match . "#")); $query = substr($query, strpos($query, "#" . $match . "#") + strlen("#" . $match . "#")); $xmlWildcard .= "<item>" . $beforeMatch . "</item>\r\n"; $xmlWildcard .= "<ruleref special=\"GARBAGE\" />\r\n"; } if (strlen($query) > 0) { $xmlWildcard .= "<item>" . $query . "</item>\r\n"; } $xmlWildcard .= "</rule>\r\n"; $xml .= "<item><ruleref uri=\"#ruleJeedom_" . $interactQuery->getId() . "\"/><tag>out._attributes.dictation=\"true\";out.action.id=\"" . $interactQuery->getId() . "\"; out.action.method=\"execute\"</tag></item>\r\n"; } else { $xml .= "<item>" . $interactQuery->getQuery() . "<tag>out.action.id=\"" . $interactQuery->getId() . "\"; out.action.method=\"execute\"</tag></item>\r\n"; } } } $xml .= "</one-of>\r\n"; $xml .= "<tag>out.action._attributes.uri=\"http://127.0.0.1:8080/sarah/jeedom\";</tag>\r\n"; $xml .= "</rule>\r\n"; $xml .= $xmlWildcard; $xml .= "</grammar>\r\n"; return $xml; }
public function preRemove() { interactQuery::removeByInteractDefId($this->getId()); }
public static function tryToReply($_query, $_parameters = array()) { $_parameters['dictation'] = $_query; if (isset($_parameters['profile'])) { $_parameters['profile'] = strtolower($_parameters['profile']); } $reply = ''; $interactQuery = interactQuery::recognize($_query); if (is_object($interactQuery)) { $reply = $interactQuery->executeAndReply($_parameters); } if (trim($reply) == '' && config::byKey('interact::noResponseIfEmpty', 'core', 0) == 0 && (!isset($_parameters['emptyReply']) || $_parameters['emptyReply'] == 0)) { $reply = self::dontUnderstand($_parameters); } if (is_object($interactQuery)) { log::add('interact', 'debug', 'J\'ai reçu : ' . $_query . "\nJ'ai compris : " . $interactQuery->getQuery() . "\nJ'ai répondu : " . $reply); } else { log::add('interact', 'debug', 'J\'ai reçu : ' . $_query . "\nJe n'ai rien compris\nJ'ai répondu : " . $reply); } return ucfirst($reply); }
$return['scenario'] = '#' . $scenario->getHumanName() . '#'; switch ($interactDef->getOptions('scenario_action')) { case 'start': $return['action'] = __('lancer', __FILE__); break; case 'stop': $return['action'] = __('arrêter', __FILE__); break; case 'activate': $return['action'] = __('activer', __FILE__); break; case 'deactivate': $return['action'] = __('désactiver', __FILE__); break; default: $return['action'] = __('erreur', __FILE__); break; } $reply = $interactDef->selectReply(); if (trim($reply) == '') { $reply = interactQuery::replyOk(); } $return['reply'] = $reply; } ajax::success($return); } throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action')); /* * *********Catch exeption*************** */ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); }
} $interact->remove(); ajax::success(); } if (init('action') == 'changeState') { $interactQuery = interactQuery::byId(init('id')); if (!is_object($interactQuery)) { throw new Exception(__('InteractQuery ID inconnu', __FILE__)); } $interactQuery->setEnable(init('enable')); $interactQuery->save(); ajax::success(); } if (init('action') == 'changeAllState') { $interactQueries = interactQuery::byInteractDefId(init('id')); if (is_array($interactQueries)) { foreach ($interactQueries as $interactQuery) { $interactQuery->setEnable(init('enable')); $interactQuery->save(); } } ajax::success(); } if (init('action') == 'execute') { ajax::success(interactQuery::tryToReply(init('query'))); } throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action')); /* * *********Catch exeption*************** */ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); }
$jsonrpc->makeSuccess(log::clear($params['log'])); } if ($jsonrpc->getMethod() == 'log::remove') { $jsonrpc->makeSuccess(log::remove($params['log'])); } /* * ************************Messages*************************** */ if ($jsonrpc->getMethod() == 'message::removeAll') { message::removeAll(); $jsonrpc->makeSuccess('ok'); } if ($jsonrpc->getMethod() == 'message::all') { $jsonrpc->makeSuccess(utils::o2a(message::all())); } /* * ************************Interact*************************** */ if ($jsonrpc->getMethod() == 'interact::tryToReply') { $jsonrpc->makeSuccess(interactQuery::tryToReply($params['query'])); } /* * ************************USB mapping*************************** */ if ($jsonrpc->getMethod() == 'jeedom::getUsbMapping') { $name = isset($params['name']) ? $params['name'] : ''; $gpio = isset($params['gpio']) ? $params['gpio'] : false; $jsonrpc->makeSuccess(jeedom::getUsbMapping($name, $gpio)); } /* * ************************Plugin*************************** */ if ($jsonrpc->getMethod() == 'plugin::install') { try { $market = market::byId($params['plugin_id']); } catch (Exception $e) { $market = market::byLogicalId($params['plugin_id']); } if (!is_object($market)) {
<?php if (!isConnect('admin')) { throw new Exception('{{401 - Accès non autorisé}}'); } if (init('interactDef_id') == '') { throw new Exception('{{Interact Def ID ne peut être vide}}'); } $interactQueries = interactQuery::byInteractDefId(init('interactDef_id')); sendVarToJS('interactDisplay_interactDef_id', init('interactDef_id')); if (count($interactQueries) == 0) { throw new Exception('{{Aucune phrase trouvée}}'); } ?> <div style="display: none;" id="md_displayInteractQueryAlert"></div> <a class='btn btn-success pull-right btn-sm bt_changeAllInteractState' data-state="1"><i class="fa fa-check"></i> Tout activer</a> <a class='btn btn-danger pull-right btn-sm bt_changeAllInteractState' data-state="0"><i class="fa fa-times"></i> Tout désactiver</a> <br/><br/> <table class="table table-bordered table-condensed tablesorter" id="table_interactQuery"> <thead> <tr> <th>{{Phrase}}</th> <th>{{Commande}}</th> <th>{{Action}}</th> </tr> </thead> <tbody> <?php foreach ($interactQueries as $interactQuery) { $trClass = $interactQuery->getEnable() == 1 ? 'success' : 'danger';
/* This file is part of Jeedom. * * Jeedom is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Jeedom is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see <http://www.gnu.org/licenses/>. */ require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php'; global $jsonrpc; if (!is_object($jsonrpc)) { throw new Exception('JSONRPC object not defined', -32699); } $params = $jsonrpc->getParams(); if ($jsonrpc->getMethod() == 'updateXml') { $jsonrpc->makeSuccess(sarah::generateXmlGrammar()); } if ($jsonrpc->getMethod() == 'execute') { $interactQuery = interactQuery::byId($params['id']); if (!is_object($interactQuery)) { throw new Exception('Aucune correspondance pour l\'id ' . $params['id'] . ' (veuillez mettre à jour le xml)', -32605); } $jsonrpc->makeSuccess($interactQuery->executeAndReply($params)); }
* * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see <http://www.gnu.org/licenses/>. */ header('Content-type: application/json'); require_once dirname(__FILE__) . "/../../../../core/php/core.inc.php"; if (init('apikey') != config::byKey('api') || config::byKey('api') == '') { connection::failed(); echo 'Clef API non valide, vous n\'etes pas autorisé à effectuer cette action (jeeApi)'; die; } if (init('user_name') == 'slackbot' || init('user_id') == 'USLACKBOT') { echo json_encode(array('text' => '')); die; } $eqLogic = slack::byLogicalId(init('team_domain'), 'slack'); if (!is_object($eqLogic)) { echo json_encode(array('text' => __('Domaine inconnue : ', __FILE__) . init('team_domain'))); die; } $parameters = array(); $user = user::byLogin(init('user_name')); if (is_object($user)) { $parameters['profile'] = init('user_name'); } $cmd_text = $eqLogic->getCmd('info', 'text'); $cmd_text->event(trim(init('text'))); $cmd_sender = $eqLogic->getCmd('info', 'sender'); $cmd_sender->event(init('user_name')); $reply = interactQuery::tryToReply(trim(init('text')), $parameters); echo json_encode(array('text' => $reply));