Software > Tu Web meteorológica
Script que envía email si no detecta cambios
CarlosLSev:
Veamos, llevo unas horas dandome cabezazos
El final de tu script (mas algo que le puse)
if ($lluvia == 0 or $difflluvia == 0) exit;
if ($lluviacache == 0 and $lluvia > 0) $mensaje = utf8_decode("Primera lluvia del día "). $lluvia." l a las ". $now;
if ($difflluvia > 0 and $lluviacache > 0 and $diff >= $tiemporeanudacion * 60) $mensaje = "Vuelve a llover ". $lluvia." l ha llovido a las". $now;
if ($difflluvia >= $umbraltormenta and $diff >= $tiempocomprobacion * 60) $mensaje = "Tormenta". $lluvia." l a las ". $now;
Con la siguiente linea envía el email con el mensaje correspondiente
if ($mensaje) mail($to, $mensaje, date( ""), 'From: ' . $from);
Como hago para que además lo envié a telegram
La url con los datos correctos me envía a mi el texto $mensaje copiandola y pegandola en el navegador
https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=YYYYYY&text=$mensaje
XXXX=ID el boot
YYYYY=ID del canal grupo o privado
jmviper:
file_get_contents('https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=YYYYYY&text='.$mensaje);
Prueba con file_get_contents. A fin de cuentas realiza un GET http igual que el navegador.
CarlosLSev:
Así no me lanza error, pero tampoco me envía el mensaje a telegram
Pero es algo del php. Si creo un php con esto
$token = "TuTokenAqui";
$id = "IdDelUsuariooCanalAqui";
$urlMsg = "https://api.telegram.org/bot{$token}/sendMessage";
$msg = "Tu mensaje aqui";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlMsg);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "chat_id={$id}&parse_mode=HTML&text=$msg");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
Y lo abro en el navegador tampoco va
Curioso si abro el navegador con la URL
https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=YYYYYY&text=Tu mensaje aqui si va
Voy a investigar...
jmviper:
Pues para probar he creado un bot de esos y ejecutándolo con file_get_contents envía los mensajes que le pongo.
En el terminal ejecuta php -a y te saldrá la línea de comandos de PHP.
Ponle esta línea
file_get_contents('https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=YYYYYY&text=prueba');
pon tu bot y chat_id y a ver si te da algún error.
Si no da ningún mensaje lo que has probado es porque la variable $mensaje estará vacía.
CarlosLSev:
Como es normal me da error
php > file_get_contents('https://api.telegram.org/botXxxxxxxxxxx/sendMessage?chat_id=yyyyyyy&text=Prueba');
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in php shell code on line 1
PHP Warning: file_get_contents(): Failed to enable crypto in php shell code on line 1
PHP Warning: file_get_contents(https://api.telegram.org/botXXXXXXXXXXXX/sendMessage?chat_id=YYYYYYY&text=Prueba): failed to open stream: operation failed in php shell code on line 1
Navegación
[#] Página Siguiente
[*] Página Anterior
Ir a la versión completa