Skip to content

Instantly share code, notes, and snippets.

@AdryDev92
Last active March 22, 2019 10:58
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 AdryDev92/8c4290b063c41f8b225b59686cece19d to your computer and use it in GitHub Desktop.
Save AdryDev92/8c4290b063c41f8b225b59686cece19d to your computer and use it in GitHub Desktop.
file request to connect with telegram bot
<?php
//api token bot
$botToken = " ";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$chatId = $update["message"]["chat"]["id"];
$chatType = $update["message"]["chat"]["type"];
$message = $update["message"]["text"];
switch ($message) {
case '/command':
$response = "Este es el mensaje del bot al comando.";
sendMessage($chatId, $response);
break;
case '/noticias':
getNews($chatId);
break;
}
function sendMessage($chatId, $message){
$url = $GLOBALS[website].'/command?chat_id'.$chatId.'&parse_mode=HTML'.urlencode($response);
file_get_contents($url);
}
function getNews($chatId){
include("simple_html_dom.php");
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = "http://feeds.weblogssl.com/genbeta";
$xmlstring = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json, TRUE);
for ($i=0; $i < 9 ; $i++) {
$titulos = $titulos."\n\n".$array['channel']['item'][$i]['title']."<a href='".$array['channel']['item'][$i]['link']."'>
+info</a>";
}
sendMessage($chatId, $titulos);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment