send message to telegram bot automatically

1.7k Views Asked by At

see this code

    if($items['favorite_count'] > 10) {echo "تاریخ و زمان: ".$items['created_at']."<br />";}
if($items['favorite_count'] > 10) {echo "توئیت: ". $items['text']."<br />";}
if($items['favorite_count'] > 10) {echo "توسط: ". $items['user']['name']."<br />";}
if($items['favorite_count'] > 10) {echo "نام کاربری: ". $items['user']['screen_name']."<br />";}
if($items['favorite_count'] > 10) {echo "لینک: "."https://twitter.com/". $items['user']['screen_name']."<br />";}
if($items['favorite_count'] > 10) {echo "تعداد فالوور: ". $items['user']['followers_count']."<br />";}
if($items['favorite_count'] > 10) {echo "دوستان: ". $items['user']['friends_count']."<br />";}
if($items['favorite_count'] > 10) {echo "ریتوئیت ها: ". $items['retweet_count']."<br />";}
if($items['favorite_count'] > 10) {echo "فیو: ". $items['favorite_count']."<br />";}
if($items['favorite_count'] > 10) {echo "مدیا: ". $items['entities']['media']."<br />";}
if($items['favorite_count'] > 10) {echo "لیست شده: ". $items['user']['listed_count']."<br /><hr />";}

its output is the user timeline tweets and the informations about it. so see this code

$username= $items['user']['screen_name'];
$botToken = "312446774:AAGNg694xqAQmV34mg2g1Qs4Aib1QcsiR80";

$chat_id = "@TweetKon";
$message = $items['text'];
$usar = $items['user']['name'];
$br = "\n";
$linkesh= "https://twitter.com/$username";
$bot_url    = "https://api.telegram.org/bot$botToken/";
$url = $bot_url."sendMessage?chat_id=".$chat_id."&text=".urlencode($message.$br.$usar);
file_get_contents($url);

i used it to send the tweets to telegram channel but there is a big problem. in php output (the first code which i shared with you first) it just shows the tweets which were favorited more that 10 times. it checks the timeline ever and ever but when there is no new tweet, it dosn't copy and show the old tweets again. but the telegram bot is not like it. if there were no new tweets it copy and post the old tweet ever and ever up to a time that the new tweets becomes. how can i solve it whit the telegram bot codes?

1

There are 1 best solutions below

1
On BEST ANSWER

have you tried comparing the string of the last tweet with the new one? adding a condition that write when the string is different with the last one.