From 030b6c25c0e76faa6dac1a3892435a437bfdedc5 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sat, 7 Apr 2018 00:49:17 +0530 Subject: [PATCH] Add pin_message and pins message --- update_chain.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/update_chain.php b/update_chain.php index 2bdd0dc..af90b73 100644 --- a/update_chain.php +++ b/update_chain.php @@ -25,6 +25,24 @@ function send_text($post_message) { return $result; } +# Pin Message +function pin_message($message_id) { + global $bot_api; + global $chat_id; + $url = 'https://api.telegram.org/bot' . $bot_api . '/pinChatMessage'; + $post_msg = array('chat_id' => $chat_id, 'message_id' => $message_id, 'disable_notification' => 'true' ); + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($post_msg) + ) + ); + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + return $result; +} + # Takes a user array as input. Checks who follows him/her and adds # him/her to $output array. Exits when a user is followed by no one. function get_chain_from_user($user) { @@ -135,7 +153,9 @@ $chain_string = chain_to_string($chain); $saved_chain = include('chain.php'); if ($saved_chain != $chain_string) { $send_message = "Chain Length: " . count($chain) . "\n\n" . $chain_string; - send_text($send_message); + $reply = send_text($send_message); + $json = json_decode($reply); + pin_message($reply->{'result'}->{"message_id"}); $file = fopen('chain.php', 'w'); $contents = ""; fwrite($file, $contents);