Title: Using WP Telegram with Supportcandy
Last modified: March 9, 2020

---

# Using WP Telegram with Supportcandy

 *  Resolved [af3](https://wordpress.org/support/users/af3/)
 * (@af3)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/)
 * Thank you for a great plugin.
    I am using this with Supportcandy, so new support
   tickets / replies are sent to Telegram.
 * a) 1st issue — after installing, the RULES does not show wpsc_ticket_thread post.
   When I changed class-wptelegram-p2tg-admin.php line 695: $post_types = get_post_types(
   array( ‘public’ => false ), ‘objects’ ); then the cpt for wpsc shows up in the
   rule lists. Looks ok so far. How to put this in a filter instead of changing 
   the core?
 * b) 2nd issue — after I am able to select wpsc_ticket_thread cpt, I can receive
   new ticket/replies in Telegram channel! However, the url used by wptelegram for
   wpsc support ticket is incorrect: it uses the post ID and not the ticket_id which
   in in the wp_postmeta. I used this code in class-wptelegram-p2tg-post-data.php
   but it gives empty results:
 *     ```
       case 'full_url':
       	$post_ID = get_post_meta($this->post->ID,'ticket_id',true);
               // $value = urldecode( get_permalink( $this->post->ID ) );
               $value = 'http://myserver.com/helpdesk?support_page=open_ticket&ticket_id='.$post_ID;
       ```
   
 * c) 3rd Issue — the image used by wpsc in the ticket is in the format of: [http://myserver.com/?wpsc_img_attachment=923](http://myserver.com/?wpsc_img_attachment=923)—
   the actual file path is in wp_termmeta under the term_id = 923. I am trying to
   send the img to telegram with the actuall url, by getting the file_path using
   get_term_meta, but I am not good in php.
 * I dont know how other users using supportcandy is using WP Telegram; i think 
   both are well matched to have a good combined notification.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Manzoor Wani](https://wordpress.org/support/users/manzoorwanijk/)
 * (@manzoorwanijk)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12525327)
 * Hello,
    You can use custom code to change the behaviour without changing the 
   plugin code:
 * **a)**
 *     ```
       /* Modify WP Telegram settings fields */
       add_action( 'cmb2_init_before_hookup', function () {
   
       	$meta_box = cmb2_get_metabox( 'wptelegram_p2tg' );
   
       	if ( ! ( $meta_box instanceof CMB2 ) ) {
       		return;
       	}
   
       	$meta_box->update_field_property(
       		'post_types',
       		'options_cb',
       		'get_all_post_types_for_wptelegram'
       	);
       } );
   
       function get_all_post_types_for_wptelegram() {
   
       	$options = array();
       	$post_types = get_post_types( array(), 'objects' );
   
       	foreach ( $post_types as $post_type ) {
       		if ( 'attachment' !== $post_type->name ) {
   
       			$label = "{$post_type->labels->singular_name} ({$post_type->name})";
   
       			$options[ $post_type->name ] = $label;
       		}
       	}
       	return $options;
       }
       /* Modify WP Telegram settings fields */
       ```
   
 * **b)**
 *     ```
       /* WP Telegram - modify post URL */
       add_filter( 'wptelegram_p2tg_post_data_full_url_value', function ( $url, $post ) {
   
       	if ('wpsc_ticket_thread' === $post->post_type ) {
   
       		$post_ID = get_post_meta($post->ID,'ticket_id',true);
   
       		// Get the URL somehow.
       		$url = get_permalink( $post_ID );
       	}
   
       	return $url;
       }, 10, 2 );
       /* WP Telegram - modify post URL */
       ```
   
 * **c)**
 *     ```
       /* WP Telegram - use custom image */
       add_filter( 'wptelegram_p2tg_post_data_featured_image_url_value', function ( $url, $post ) {
   
       	if ('wpsc_ticket_thread' === $post->post_type ) {
   
       		// Get the URL somehow.
       		$url = get_term_meta( 'term_id_here', 'file_path', true );
       	}
   
       	return $url;
       }, 10, 2 );
       /* WP Telegram - use custom image */
       ```
   
 *  Thread Starter [af3](https://wordpress.org/support/users/af3/)
 * (@af3)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12529025)
 * Thank you so much!!!
 * a) This works okay — thanks.
    b) This still give empty $post_ID, not sure why
   it is not returning the $post_ID c) the image in the post is in the form of img
   src=http://myserver.com/?wpsc_img_attachment=923 – i tried this to get term_id
   = 923 — havent tested
 *     ```
       /* WP Telegram - use custom image */
       add_filter( 'wptelegram_p2tg_post_data_featured_image_url_value', function ( $url, $post ) {
   
       	if ('wpsc_ticket_thread' === $post->post_type ) {
                       // Get the term id from featured_img url 
                       $url_components = parse_url($url); 
                       parse_str($url_components['query'], $term_query);
                       $term_ID = $term_query['wpsc_img_attachment']; 
   
                       // This will give the full file path and not url
       		$url_path = get_term_meta( $term_ID, 'file_path', true );
                       // Convert file path to url
                       $url = 'http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', $url_path);
   
       	}
   
       	return $url;
       }, 10, 2 );
       /* WP Telegram - use custom image */
       ```
   
 * d) Also added this to get the ticket title — but i cant get the topic title.
 *     ```
       /* WP Telegram - use custom topic */
       add_filter( 'wptelegram_p2tg_post_data_post_title_value', function ( $post_title, $post ) {
   
       	if ('wpsc_ticket_thread' === $post->post_type ) {
                       global $wpdb;
                       $ticket_subject = $wpdb->get_var( "SELECT ticket_subject FROM ".$wpdb->prefix."wpsc_ticket WHERE historyId = " . $post->ID );
                       $post_title = $ticket_subject;
       	}
       	return $post_title;
       }, 10, 2 );
       /* WP Telegram - use custom topic */
       ```
   
 *  [Manzoor Wani](https://wordpress.org/support/users/manzoorwanijk/)
 * (@manzoorwanijk)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12529207)
 * The code I gave you is just a demonstration of how to do it without modifying
   the plugin, the actual working of the code still needs to be figured out by you
   or your developer.
 *  Thread Starter [af3](https://wordpress.org/support/users/af3/)
 * (@af3)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12531922)
 * For whatever reason, this seemingly straight fwd get_post_meta function keeps
   returning empty $post_ID , any ideas?
 *     ```
       /* WP Telegram - modify post URL */
       add_filter( 'wptelegram_p2tg_post_data_full_url_value', function ( $url, $post ) {
   
       	if ('wpsc_ticket_thread' === $post->post_type ) {
       		$post_ID = get_post_meta($post->ID,'ticket_id',true);
       		// Get the URL somehow.
       		$url = get_permalink( $post_ID );
       	}
       	return $url;
       }, 10, 2 );
       /* WP Telegram - modify post URL */
       ```
   
 *  Thread Starter [af3](https://wordpress.org/support/users/af3/)
 * (@af3)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12568497)
 * Just for those using SC, if you add delay in WP Telegram setting for 1 min, the
   above should now work ..

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using WP Telegram with Supportcandy’ is closed to new replies.

 * ![](https://ps.w.org/wptelegram/assets/icon-256x256.png?rev=2500018)
 * [WP Telegram (Auto Post and Notifications)](https://wordpress.org/plugins/wptelegram/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wptelegram/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wptelegram/)
 * [Active Topics](https://wordpress.org/support/plugin/wptelegram/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wptelegram/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wptelegram/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [af3](https://wordpress.org/support/users/af3/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/using-wp-telegram-with-supportcandy/#post-12568497)
 * Status: resolved