nikstar/blog

Instant View for Custom Domain

As you may know, Telegram does not accept new domains in between Instant View contests. I am happy to present a way anyone can add IV support for their standalone website.

TLDR: We will create a copy of our website on WordPress.com subdomain and redirect Telegram crawler to it.

I will go through the steps I've taken to add Instant View for this blog post on my personal domain. This method requires modifications to server configuration, so you must have access to website's host: this will not work for a website you do not fully control.

Create a mirror of your site on WordPress.com

WordPress.com was chosen because it is the only website I could find that supports setting custom site_name. If this is not critical, you might be better off hosting your mirror on Medium or Telegraph: both are much nicer to use than WP.

During signup, your username will map to your subdomain (username.wordpress.com); site name will map to site_name. Choose wisely. Setup process is pretty infuriating, but it is possible to avoid paying anything. If you see a checkout screen, just remove everything in your cart.

Next, create a WP blog post with permalink exactly matching that on your standalone (/blog/instant-view-for-custom-domain for this article). If links do not line up exactly, server configuration on the next step will be more difficult. It is definitely possible, but out of scope for this guide.

In real life, you would need to set up automatic cross-posting from your standalone to WP. This is also out of scope for this article; I have just manually copied contents over.

Redirect crawler's requests

Set up your server so that requests coming from TelegramBot are redirected to WP version, but all other traffic is left intact. We will do this based on user agent string.

If you have a nginx server, add following if statement to a location block:

...
if ( $http_user_agent ~ 'TelegramBot' ) {
    return 301 https://%username%.wordpress.com$request_uri;
}
...
Remember to reload server config
sudo nginx -s reload

And this is it! Now Telegram crawler will be redirected to the version of your article on WP that supports IV, but anyone else following a link will still go to your custom domain.

Next steps

Procedure described above is just a proof of concept. For it to be practical, you will have to set up cross-posting to WP and only do redirects for articles but not utility pages.

Normal users can still get to WP version of your article by selecting 'Open in...' while viewing IV. WP version should direct readers back to your standalone.

Original idea was to redirect Telegram bot to t.me/iv?... address but I could not make it work. Please tell me if you find a way.


Thanks for reading. Get in touch on Telegram.

P.S. At this point you are probably thinking you don't need IV that much :)