готовый сценарий отправляет все значения объекта и дату измения (или прошедшее время с даты измения). Для добавление новой кнопки просто добавьте в команды телеграмм.
Код:
$telegram_module->buildInlineKeyboardButton($text="имя объекта","", "Callback_sensor_имя объекта","")
Команда телеграм:
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
// $option[] = $telegram_module->buildInlineKeyboardButton($text=$state." ".$obj,"","Callback_fm_".$dir."/".$obj,"");
$option = array(
$telegram_module->buildInlineKeyboardButton($text="all_in_one","", "Callback_sensor_all_in_one",""),
$telegram_module->buildInlineKeyboardButton($text="current","", "Callback_sensor_current","")
) ;
$count_row = 3;
$option = array_chunk($option, $count_row);
$keyb = $telegram_module->buildInlineKeyBoard($option);
$content = array('chat_id' => $chat_id, 'text' => "Датчики: ".$dir, 'reply_markup' => $keyb, 'parse_mode' => 'HTML');
$telegram_module->sendContent($content);
callback:
Код:
//$telegram_module->sendMessageToAll($callback);
//$telegram_module->sendMessageToAll(substr($callback,9,6));
//$telegram_module->sendMessageToAll(substr($callback,16));
if (substr($callback,9,6) == 'sensor')
{
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
rs('sensor2telega', array('zapros' =>substr($callback,16)));
}
сценарий:
function get_dt($prop)
{
$sql='SELECT max(h.added ) dt, unix_timestamp(h.added) unx FROM `phistory` h WHERE h.value_ID = (SELECT `ID` FROM `pvalues` WHERE `PROPERTY_NAME` = "'.$prop.'")';
$rec = SQLSelect($sql);
return $rec[0][dt];
}
function get_props($obj)
{
//$sql='SELECT title FROM `properties` where object_id = (SELECT id FROM `objects` where title="'.$obj.'")';
$sql='SELECT substring(PROPERTY_NAME, POSITION("." in PROPERTY_NAME)+1) title FROM `pvalues` where PROPERTY_NAME like "'.$obj.'%"';
$rec = SQLSelect($sql);
foreach ($rec as $prop)
{
//print_r($prop)[title];
$ar2[] = $prop[title];
}
return $ar2;
}
function get_unx($prop)
{
$sql='SELECT max(h.added ) dt, unix_timestamp(h.added) unx FROM `phistory` h WHERE h.value_ID = (SELECT `ID` FROM `pvalues` WHERE `PROPERTY_NAME` = "'.$prop.'")';
$rec = SQLSelect($sql);
return $rec[0][unx];
}
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$obj=$params['zapros'];
if ($obj==""){$obj="all_in_one";}
$text='';
//$obj="current";
//$objprops=getObjectsByProperty($obj,">","0");
$objprops=get_props($obj);
//print_r($objprops);
foreach ($objprops as $prop)
{
if (is_numeric (gg($obj.".".$prop ))) {$value=round(gg($obj.".".$prop),2);}
else {$value=gg($obj.".".$prop);}
if (gmdate('i',trim(time()-get_unx($obj.".".$prop)))<120)
{$text.=$obj.".".$prop.":".$value." (".preg_replace("|\b[0]+([1-9][\d]*)|is", "\\1", (gmdate('i',trim(time()-get_unx($obj.".".$prop)))))." минут назад)\n";}
else
{$text.=$obj.".".$prop.":".$value." ".preg_replace("|\b[0]+([1-9][\d]*)|is", "\\1", (gmdate('i',trim(time()-get_unx($obj.".".$prop)))))." минут назад (".get_dt($obj.'.'.$prop).")\n";}
}
$telegram_module->sendMessageToAll($text);
echo $text;
Екатеринбург, Россия
На форуме: directman66