Developer hooks

The plugin is extensible by design: every important step of the pipeline runs through a WordPress filter or action. This is the same API the Pro add-on builds on.

Filters

FilterPurpose
b418_wp_tg_cf7_should_sendLast-chance veto before a connection fires
b418_wp_tg_cf7_message_textModify the final rendered message text
b418_wp_tg_cf7_placeholdersAdd or change template placeholder values
b418_wp_tg_cf7_default_templateChange the built-in default template body
b418_wp_tg_cf7_send_argsModify the Telegram API request arguments
b418_wp_tg_cf7_log_max_entriesChange how many activity-log entries are kept (default 50)

Actions

ActionPurpose
b418_wp_tg_cf7_loadedFires once the plugin has fully booted — the entry point for add-ons
b418_wp_tg_cf7_after_sendFires after each Telegram delivery attempt

Examples

Conditionally skip sending

b418_wp_tg_cf7_should_send receives the routing rule, the form, and the submission — return false to skip that connection for this submission:

add_filter( 'b418_wp_tg_cf7_should_send', function ( $send, $rule, $contact_form, $submission ) {
    // Skip Telegram notifications for a specific form outside business hours.
    if ( 123 === (int) $contact_form->id() && (int) wp_date( 'G' ) < 9 ) {
        return false;
    }

    return $send;
}, 10, 4 );

Add a custom template placeholder

Values returned from b418_wp_tg_cf7_placeholders become [tag] replacements in every template:

add_filter( 'b418_wp_tg_cf7_placeholders', function ( $placeholders, $form, $submission ) {
    $placeholders['_referrer'] = (string) $submission->get_meta( 'referer' );

    return $placeholders;
}, 10, 3 );

Now [_referrer] works in any template.

Modify the final message text

add_filter( 'b418_wp_tg_cf7_message_text', function ( $text, $rule, $contact_form, $submission ) {
    return $text . "\n\n#leads";
}, 10, 4 );

React to a delivery

b418_wp_tg_cf7_after_send fires for every chat a message was attempted to, with the raw Telegram API response and full context:

add_action( 'b418_wp_tg_cf7_after_send', function ( $result, $rule, $chat, $bot, $submission, $context ) {
    if ( empty( $result['ok'] ) ) {
        error_log( sprintf(
            'Telegram delivery failed for "%s" → %s: %s',
            $context['form_title'],
            $chat['name'],
            $result['description'] ?? 'unknown error'
        ) );
    }
}, 10, 6 );

The $context array contains the rendered text, parse_mode, form_id, and form_title — enough to record or resend the delivery without holding a submission reference.

Tweak the Telegram API request

b418_wp_tg_cf7_send_args filters the argument array passed to the Telegram sendMessage call — for example, to disable link previews:

add_filter( 'b418_wp_tg_cf7_send_args', function ( $args, $chat, $context ) {
    $args['disable_web_page_preview'] = true;

    return $args;
}, 10, 3 );

Keep a longer activity log

add_filter( 'b418_wp_tg_cf7_log_max_entries', fn () => 200 );

Boot order

If your extension needs the plugin's classes, hook b418_wp_tg_cf7_loaded — it fires once the plugin has fully initialized:

add_action( 'b418_wp_tg_cf7_loaded', function () {
    // Safe to register your filters/actions here.
} );