📜 ⬆️ ⬇️

Conclusion of the Telegram channel on your website

We will hammer one more nail in a cover of a coffin of Roskomnadzor.

You cannot directly access the messages of your channel to display them on a web page. But you can write a bot, which will send incoming messages to where you need to process them and display them on the site. And you can use ready.

It is strange that this wonderful bot - Journalist (@JournalistBot) has not yet been mentioned on Habré. The site indicated that beta, but works more than stable.

After a simple installation of the bot and setting up a new journalist channel in it, you get the widget code from it, which you need to put on your website in some kind of div or something like this, which will output the adaptive vertical tape of your messages:
')
<p class="center"><a href="https://t.me/channelname" target="_blank"></a></p> <script id="journalist-broadcast-353945930" async defer src="https://journali.st/broadcasts/353945930-widget-10.js"></script> 

Where 353945930 is your channel id in JournalistBot. The number 10 in “widget-10” is the number of last displayed messages. It can be changed.

New messages for your channel are added to JournalistBot either directly or by redirecting to it from other channels. Sometimes (the only bug noticed) message, in which there is both a picture and text, does not reach completely - either a picture or a text. Otherwise, everything is quite on the level. Channels can be done several.

The main charms of the widget:


You can make a small hack - proxy channel data (https://journali.st/broadcasts/353945930-widget-10.js) through your website. Then there will be an opportunity to edit them a little.

For example, I have implemented such a proxy caching for 5 minutes, which reduces the size of all pictures with a separate /misc/image.php script.

Code journalist proxy
 <?php $file = "journalist.cache.js"; $LastModified_unix = filemtime($file); $LastModified = gmdate("D, d MYH:i:s \G\M\T", $LastModified_unix); $IfModifiedSince = false; if (isset($_ENV['HTTP_IF_MODIFIED_SINCE'])) $IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5)); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5)); if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) { header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); exit; } header('Last-Modified: '. $LastModified); if (!file_exists($file) || (time() - filemtime($file)) > 1200) { $data = file_get_contents("https://journali.st/broadcasts/353945930-widget-10.js"); $data = str_replace("https://images-onepick-opensocial.googleusercontent.com/gadgets/proxy?container=onepick&url=", "/misc/image.php?size=310&url=", $data); file_put_contents($file, $data); } readfile($file); ?> 


In the above script src you need to change the link to our proxy. New messages come to the client, of course, directly, bypassing the proxy.

Another recommended file tweaking: scrollbar (standard or jQuery plugin) for blocks with limited height, hook to lightbox images (or on the server side by adding a class-a, or client-side javascript), folding the block with click messages (so as not to interfere).

For lightbox, one should take into account the dynamic flow of new pictures (messages). For this case, you can run image processing in the channel block every 10 seconds, for example, or hang an event handler on the journalist code.

In general, Journalist is a very pleasant and stable application that allows you to quickly and conveniently add information to your site from a computer or phone — broadcast, for example. As a separate telegram channel, the channel in journalist does not work, therefore, if necessary, it is necessary to duplicate messages.

Free, no ads.

Source: https://habr.com/ru/post/354642/


All Articles