Filter
uncanny-automator
uap_fl_support_token_value
Filters the value of a fluent-support support token before it's displayed or used.
add_filter( 'uap_fl_support_token_value', $callback, 10, 3 );
Description
This filter allows developers to modify the value of a Fluent Support token before it's displayed in an automation. It's applied when a 'CONVERSATION' token is being processed, letting you alter the retrieved conversation data. Use it to format or conditionally change token output.
Usage
add_filter( 'uap_fl_support_token_value', 'your_function_name', 10, 3 );
Parameters
-
$value(mixed) - This parameter represents the value that will be returned and used by the filter.
-
$trigger_id(mixed) - The value to be filtered or replaced.
-
$pieces(mixed) - This parameter contains the ID of the trigger being processed.
Return Value
The filtered value.
Examples
// Prevent exceeding limits for token values when dealing with potentially large amounts of data.
add_filter( 'uap_fl_support_token_value', function( $value, $trigger_id, $pieces ) {
// Check if the value is a string and if its length exceeds a reasonable limit.
if ( is_string( $value ) && strlen( $value ) > 500 ) {
// Truncate the value to prevent performance issues or display problems.
$value = substr( $value, 0, 500 ) . '...';
}
return $value;
}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/fluent-support/tokens/flsupport-tokens.php:285
public function parse_flsupport_trigger_tokens( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
if ( $pieces ) {
if ( ! isset( $pieces[2] ) ) {
return $value;
}
if ( stristr( $pieces[2], 'FLSUPPORT-' ) ) {
global $wpdb;
$trigger_id = isset( $replace_args['trigger_id'] ) ? $replace_args['trigger_id'] : 0;
$trigger_log_id = isset( $replace_args['trigger_log_id'] ) ? $replace_args['trigger_log_id'] : 0;
if ( 0 === (int) $trigger_id || 0 === (int) $trigger_log_id ) {
return $value;
}
$trigger_code = $pieces[1];
$token_identifier = strtoupper( $pieces[2] );
$identifier = trim( str_replace( 'FLSUPPORT-', '', $token_identifier ), '-' );
$identifier_parts = explode( '-', $identifier );
$object_type = $identifier_parts[0];
$token_field = strtolower( str_replace( $object_type . '-', '', $identifier ) );
$ticket_id = intval( Automator()->helpers->recipe->get_form_data_from_trigger_meta( 'FLSUPPORTTICKETID', $trigger_id, $trigger_log_id, $user_id ) );
if ( 0 === (int) $ticket_id ) {
return $value;
}
$person_id = intval( Automator()->helpers->recipe->get_form_data_from_trigger_meta( 'FLSUPPORTPERSONID', $trigger_id, $trigger_log_id, $user_id ) );
$cache_key = $trigger_id . '-' . $ticket_id;
if ( ! isset( $this->trigger_tickets[ $cache_key ] ) ) {
// Only query ticket object once per trigger request.
$this->trigger_tickets[ $cache_key ] = $this->get_ticket_object( $ticket_id );
}
$ticket = $this->trigger_tickets[ $cache_key ];
switch ( $object_type ) {
case 'TICKET':
$value = $this->get_object_field( $token_field, $ticket );
break;
case 'AGENT':
$value = $this->get_object_field( $token_field, $this->get_person_object( $ticket->agent_id ) );
break;
case 'CUSTOMER':
$value = $this->get_object_field( $token_field, $this->get_person_object( $ticket->customer_id ) );
break;
case 'CONVERSATION':
$response_id = intval( Automator()->helpers->recipe->get_form_data_from_trigger_meta( 'FLSUPPORTRESPONSEID', $trigger_id, $trigger_log_id, $user_id ) );
$value = $this->get_object_field( $token_field, $this->get_response_object( $response_id ) );
break;
default:
$value = apply_filters( 'uap_fl_support_token_value', $value, $trigger_id, $pieces );
}
}
}
return $value;
}