• Resolved frostengine

    (@frostengine)


    Good afternoon! I own a site on WordPress and a couple of bots in telegram, I planned to add my site as a WebAPP application in bots, but ran into a problem. The thing is, your plugin is installed on the site, which calls comments.app, if the plugin works, any time I click on articles in the WebApp telegram is redirected to my telegram channel, to which comments.app is tied.

    When you disable the plugin, everything works fine, can you tell me how to fix it? I like your plugin and it’s very handy, but I also have a need to add the site to the WebApps bot:)

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Irshad Ahmad

    (@irshadahmad21)

    You can solve the problem in a few different ways. One of the easiest ways is to not load the Telegram comments when it’s a WebApp. You can add some query param to the WebApp URL like ?isWebApp=1 and then use the wptelegram_comments_post_rules_apply filter to avoid loading the Telegram comments as follows:

    add_filter( 'wptelegram_comments_post_rules_apply', function ( $rules_apply ) {
    	if ( isset( $_GET['isWebApp'] ) && $_GET['isWebApp'] ) {
    		return false;
    	}
    	return $rules_apply;
    }, 10, 1 );
    Thread Starter frostengine

    (@frostengine)

    Thank you for your decision! I understand correctly that my telegram URL should look like this https://www.zefgame.ru/?isWebApp=1

    And I should add a filter to the function.php file?

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    I understand correctly that my telegram URL should look like this https://www.zefgame.ru/?isWebApp=1

    And I should add a filter to the function.php file?

    Correct.

    Thread Starter frostengine

    (@frostengine)

    Made a Webapps link, added a filter. The home page runs, but as soon as I go to the entries that have comments.app, I still get redirected to the feed. I recorded a short video – https://vimeo.com/820446406?share=copy

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Yeah, it’s because the isWebApp query param is removed on further navigations.

    An alternate solution would be to make use of cookies:

    add_action( 'init', function () {
    	// Set a cookie for Telegram web app browser
    	if ( isset( $_GET['isWebApp'] ) && $_GET['isWebApp'] ) {
    		setcookie( 'isWebApp', '1', 0, '/' );
    	}
    });
    
    add_filter( 'wptelegram_comments_post_rules_apply', function ( $rules_apply ) {
    	// Check if the webapp cookie is set to avoid rendering Telegram comments
    	if ( isset( $_COOKIE['isWebApp'] ) && $_COOKIE['isWebApp'] ) {
    		return false;
    	}
    	return $rules_apply;
    }, 10, 1 );
    Thread Starter frostengine

    (@frostengine)

    It’s working! Thank you so much;)

    Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Great!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Redirect WebAPP telegram’ is closed to new replies.