Plugin Hooks (Filters and Actions)

List of Filters (3)

  1. fluentchat_message_new

    This filters is triggered when a new message is about to be recorded. The return string of this filters is the modified message text. You can return false to prevent the message from being recorded.

    Parameters:

    • $messageText (string)
    • $chatID (int)
    • $customerID (string)
    • $operatorID (int)
    • $sender (string) (‘operator’ || ‘customer’)

    Example Usage:

    // Turn message text to lowercase if sender is operator
    
    add_filter('fluentchat_message_new', 'message_to_lowercase', 10, 5);
    function message_to_lowercase($messageText, $chatID, $customerID, $operatorID, $sender) {
      if ($sender === 'operator') {
        return strtolower($messageText);
      }
    }
  2. fluentchat_widget_show

    You can use this filter to overwrite the settings to show / hide the chat widget.

    Parameters:

    • $showWidget (boolean)
      Current state of the chat widget. True equals show widget on current page. False equals don’t show widget.

    Example Usage:

    // Always show chat widget if URL contains the string 'help'
    
    add_filter('fluentchat_widget_show', 'show_chat_help', 10, 1);
    function show_chat_help($showWidget) {
      $URL = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
      if (strpos($URL, 'help')) {
        return true;
      }
      return $showWidget;
    }
    
  3. fluentchat_customer_update

    This filters is triggered when the customer info is updated in the system. Customer info can be updated by the customer when he first enters his name and email on the chat widget, or by the operator in the back-end.

    Parameters:

    • $customerInfo (array)
      The customer information to be updated.

      // var_dump($customerInfo);
      
      array(5) {
        ["name"]=>
        string(4) "Mark"
        ["email"]=>
        string(16) "mark@example.com"
        ["location"]=>
        string(23) "Wellington, New Zealand"
        ["browser"]=>
        string(34) "Chrome 60.0.3112.113, OS X (en-US)"
        ["notes"]=>
        string(68) "[{"operator":"admin","created":1504214899,"body":"Loyal customer."}]"
      }
      
    • $customerID (string)
    • $updater (string) (‘operator’ || ‘customer’)

    Example Usage:

    // Turn customer name to uppercase
    
    add_filter('fluentchat_customer_update', 'on_update_customer', 10, 1);
    function update_customer($customerInfo, $customerID, $updater) {
      if (isset($customerInfo['name'])) {
        $customerInfo['name'] = strtoupper($customerInfo['name']);
      }
      return $customerInfo;
    }
    

List of Actions (3)

  1. fluentchat_feedback_new

    Parameters:

    • $chatID (int)
    • $customerID (string)
    • $rating (int)
    • $comment (string)

    Example Usage:

    // Bully customers by not accepting a rating under 3
    
    add_action('fluentchat_feedback_new', 'feedback_bully', 10, 4);
    function feedback_bully($chatID, $customerID, $rating, $comment) {
      if ($rating < 3) { echo json_encode(array('failed' => 'Please try again.'));
        die();
      }
    }
  2. fluentchat_chat_assign

    Parameters:

    • $chatID (int)
    • $customerID (string)
    • $operatorID (int)
    • $messages (array)
      Contains all the messages sent by the customer so far

    Example Usage:

    // Do something when an operator picks up a chat
    
    add_action('fluentchat_chat_assign', 'create_ticket', 10, 4);
    function create_ticket($chatID, $customerID, $operatorID, $messages) {
      // Do something
    }
  3. fluentchat_chat_archive

    Parameters:

    • $chatID (int)
    • $customerID (string)
    • $operatorID (int)
    • $initiator (string) (‘customer’ || ‘operator’)

    Example Usage:

    // Do something when a chat is archvied
    
    add_action('fluentchat_chat_archive', 'close_ticket', 10, 4);
    function close_ticket($chatID, $customerID, $operatorID, $initiator) {
      // Close ticket in XYZ ticketing app
    }