From f3f7e64e077a339e786e345ebe491225ed972ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Fri, 21 Nov 2025 21:20:23 +0100 Subject: [PATCH 1/2] feat: add chat addons woocommerce templates --- .../rocketchat/templates/woo-orders.php | 297 +++++++++++++++++ .../addons/slack/templates/woo-orders.php | 279 ++++++++++++++++ .../addons/zulip/templates/woo-orders.php | 304 ++++++++++++++++++ 3 files changed, 880 insertions(+) create mode 100644 forms-bridge/addons/rocketchat/templates/woo-orders.php create mode 100644 forms-bridge/addons/slack/templates/woo-orders.php create mode 100644 forms-bridge/addons/zulip/templates/woo-orders.php diff --git a/forms-bridge/addons/rocketchat/templates/woo-orders.php b/forms-bridge/addons/rocketchat/templates/woo-orders.php new file mode 100644 index 0000000..5054fc7 --- /dev/null +++ b/forms-bridge/addons/rocketchat/templates/woo-orders.php @@ -0,0 +1,297 @@ + __( 'Woo Orders', 'forms-bridge' ), + 'description' => __( + 'WooCommerce orders form template. The resulting bridge will notify new woocommerce customers to Rocket.Chat channels', + 'forms-bridge' + ), + 'integrations' => array( 'woo' ), + 'fields' => array( + array( + 'ref' => '#bridge', + 'name' => 'endpoint', + 'value' => '/api/v1/chat.postMessage', + ), + array( + 'ref' => '#bridge/custom_fields[]', + 'name' => 'roomId', + 'label' => __( 'Channel', 'forms-bridge' ), + 'description' => __( + 'Name of the channel where messages will be sent', + 'forms-bridge' + ), + 'type' => 'select', + 'options' => array( + 'endpoint' => '/api/v1/rooms.get', + 'finger' => array( + 'value' => 'update[]._id', + 'label' => 'update[].name', + ), + ), + 'required' => true, + ), + array( + 'ref' => '#form', + 'name' => 'title', + 'default' => __( 'Contacts', 'forms-bridge' ), + ), + ), + 'bridge' => array( + 'endpoint' => '/api/v1/chat.postMessage', + 'workflow' => array( 'summary' ), + 'mutations' => array( + array( + array( + 'from' => 'id', + 'to' => 'id', + 'cast' => 'null', + ), + array( + 'from' => 'parent_id', + 'to' => 'parent_id', + 'cast' => 'null', + ), + array( + 'from' => 'status', + 'to' => 'status', + 'cast' => 'null', + ), + array( + 'from' => 'version', + 'to' => 'version', + 'cast' => 'null', + ), + array( + 'from' => 'prices_include_tax', + 'to' => 'prices_include_tax', + 'cast' => 'null', + ), + array( + 'from' => 'date_created', + 'to' => 'fields["Order Date"]', + 'cast' => 'string', + ), + array( + 'from' => 'date_modified', + 'to' => 'date_modified', + 'cast' => 'null', + ), + array( + 'from' => 'discount_total', + 'to' => 'discount_total', + 'cast' => 'null', + ), + array( + 'from' => 'discount_tax', + 'to' => 'discount_tax', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_total', + 'to' => 'shipping_total', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_tax', + 'to' => 'shipping_tax', + 'cast' => 'null', + ), + array( + 'from' => 'cart_total', + 'to' => 'cart_total', + 'cast' => 'null', + ), + array( + 'from' => 'cart_tax', + 'to' => 'cart_tax', + 'cast' => 'null', + ), + array( + 'from' => 'total', + 'to' => 'fields["Order Total"]', + 'cast' => 'string', + ), + array( + 'from' => 'total_tax', + 'to' => 'total_tax', + 'cast' => 'null', + ), + array( + 'from' => 'customer_id', + 'to' => 'customer_id', + 'cast' => 'null', + ), + array( + 'from' => 'order_key', + 'to' => 'order_key', + 'cast' => 'null', + ), + array( + 'from' => '?billing.company', + 'to' => 'fields.Company', + 'cast' => 'string', + ), + array( + 'from' => '?billing.first_name', + 'to' => 'fields["First Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.last_name', + 'to' => 'fields["Last Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.email', + 'to' => 'fields.Email', + 'cast' => 'string', + ), + array( + 'from' => '?billing.phone', + 'to' => 'fields.Phone', + 'cast' => 'string', + ), + array( + 'from' => 'billing', + 'to' => 'billing', + 'cast' => 'null', + ), + array( + 'from' => 'shipping', + 'to' => 'shipping', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method', + 'to' => 'payment_method', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method_title', + 'to' => 'payment_method_title', + 'cast' => 'null', + ), + array( + 'from' => 'transaction_id', + 'to' => 'transaction_id', + 'cast' => 'null', + ), + array( + 'from' => 'customer_ip_address', + 'to' => 'ip_signup', + 'cast' => 'null', + ), + array( + 'from' => 'customer_user_agent', + 'to' => 'customer_user_agent', + 'cast' => 'null', + ), + array( + 'from' => 'created_via', + 'to' => 'created_via', + 'cast' => 'null', + ), + array( + 'from' => 'customer_note', + 'to' => 'notes', + 'cast' => 'null', + ), + array( + 'from' => 'date_completed', + 'to' => 'date_completed', + 'cast' => 'null', + ), + array( + 'from' => 'date_paid', + 'to' => 'date_paid', + 'cast' => 'null', + ), + array( + 'from' => 'cart_hash', + 'to' => 'cart_hash', + 'cast' => 'null', + ), + array( + 'from' => 'order_stock_reduced', + 'to' => 'order_stock_reduced', + 'cast' => 'null', + ), + array( + 'from' => 'download_permissions_granted', + 'to' => 'download_permissions_granted', + 'cast' => 'null', + ), + array( + 'from' => 'new_order_email_sent', + 'to' => 'new_order_email_sent', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_sales', + 'to' => 'recorded_sales', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_coupon_usage_counts', + 'to' => 'recorded_coupon_usage_counts', + 'cast' => 'null', + ), + array( + 'from' => 'number', + 'to' => 'number', + 'cast' => 'null', + ), + array( + 'from' => 'tax_lines', + 'to' => 'tax_lines', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_lines', + 'to' => 'shipping_lines', + 'cast' => 'null', + ), + array( + 'from' => 'fee_lines', + 'to' => 'fee_lines', + 'cast' => 'null', + ), + array( + 'from' => 'coupon_lines', + 'to' => 'coupon_lines', + 'cast' => 'null', + ), + array( + 'from' => 'line_items[].name', + 'to' => 'fields.Products[].Name', + 'cast' => 'string', + ), + array( + 'from' => 'line_items[].quantity', + 'to' => 'fields.Products[].Quantity', + 'cast' => 'string', + ), + array( + 'from' => 'line_items', + 'to' => 'line_items', + 'cast' => 'null', + ), + array( + 'from' => 'currency', + 'to' => 'currency', + 'cast' => 'null', + ), + ), + ), + ), +); diff --git a/forms-bridge/addons/slack/templates/woo-orders.php b/forms-bridge/addons/slack/templates/woo-orders.php new file mode 100644 index 0000000..46c9d34 --- /dev/null +++ b/forms-bridge/addons/slack/templates/woo-orders.php @@ -0,0 +1,279 @@ + __( 'Woo Orders', 'forms-bridge' ), + 'description' => __( + 'WooCommerce orders form template. The resulting bridge will notify new woocommerce customers to Slack channels', + 'forms-bridge' + ), + 'integrations' => array( 'woo' ), + 'fields' => array( + array( + 'ref' => '#bridge', + 'name' => 'endpoint', + 'value' => '/api/chat.postMessage', + ), + array( + 'ref' => '#form', + 'name' => 'title', + 'default' => __( 'Contacts', 'forms-bridge' ), + ), + ), + 'bridge' => array( + 'endpoint' => '/api/chat.postMessage', + 'workflow' => array( 'summary-md' ), + 'mutations' => array( + array( + array( + 'from' => 'id', + 'to' => 'id', + 'cast' => 'null', + ), + array( + 'from' => 'parent_id', + 'to' => 'parent_id', + 'cast' => 'null', + ), + array( + 'from' => 'status', + 'to' => 'status', + 'cast' => 'null', + ), + array( + 'from' => 'version', + 'to' => 'version', + 'cast' => 'null', + ), + array( + 'from' => 'prices_include_tax', + 'to' => 'prices_include_tax', + 'cast' => 'null', + ), + array( + 'from' => 'date_created', + 'to' => 'fields["Order Date"]', + 'cast' => 'string', + ), + array( + 'from' => 'date_modified', + 'to' => 'date_modified', + 'cast' => 'null', + ), + array( + 'from' => 'discount_total', + 'to' => 'discount_total', + 'cast' => 'null', + ), + array( + 'from' => 'discount_tax', + 'to' => 'discount_tax', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_total', + 'to' => 'shipping_total', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_tax', + 'to' => 'shipping_tax', + 'cast' => 'null', + ), + array( + 'from' => 'cart_total', + 'to' => 'cart_total', + 'cast' => 'null', + ), + array( + 'from' => 'cart_tax', + 'to' => 'cart_tax', + 'cast' => 'null', + ), + array( + 'from' => 'total', + 'to' => 'fields["Order Total"]', + 'cast' => 'string', + ), + array( + 'from' => 'total_tax', + 'to' => 'total_tax', + 'cast' => 'null', + ), + array( + 'from' => 'customer_id', + 'to' => 'customer_id', + 'cast' => 'null', + ), + array( + 'from' => 'order_key', + 'to' => 'order_key', + 'cast' => 'null', + ), + array( + 'from' => '?billing.company', + 'to' => 'fields.Company', + 'cast' => 'string', + ), + array( + 'from' => '?billing.first_name', + 'to' => 'fields["First Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.last_name', + 'to' => 'fields["Last Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.email', + 'to' => 'fields.Email', + 'cast' => 'string', + ), + array( + 'from' => '?billing.phone', + 'to' => 'fields.Phone', + 'cast' => 'string', + ), + array( + 'from' => 'billing', + 'to' => 'billing', + 'cast' => 'null', + ), + array( + 'from' => 'shipping', + 'to' => 'shipping', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method', + 'to' => 'payment_method', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method_title', + 'to' => 'payment_method_title', + 'cast' => 'null', + ), + array( + 'from' => 'transaction_id', + 'to' => 'transaction_id', + 'cast' => 'null', + ), + array( + 'from' => 'customer_ip_address', + 'to' => 'ip_signup', + 'cast' => 'null', + ), + array( + 'from' => 'customer_user_agent', + 'to' => 'customer_user_agent', + 'cast' => 'null', + ), + array( + 'from' => 'created_via', + 'to' => 'created_via', + 'cast' => 'null', + ), + array( + 'from' => 'customer_note', + 'to' => 'notes', + 'cast' => 'null', + ), + array( + 'from' => 'date_completed', + 'to' => 'date_completed', + 'cast' => 'null', + ), + array( + 'from' => 'date_paid', + 'to' => 'date_paid', + 'cast' => 'null', + ), + array( + 'from' => 'cart_hash', + 'to' => 'cart_hash', + 'cast' => 'null', + ), + array( + 'from' => 'order_stock_reduced', + 'to' => 'order_stock_reduced', + 'cast' => 'null', + ), + array( + 'from' => 'download_permissions_granted', + 'to' => 'download_permissions_granted', + 'cast' => 'null', + ), + array( + 'from' => 'new_order_email_sent', + 'to' => 'new_order_email_sent', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_sales', + 'to' => 'recorded_sales', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_coupon_usage_counts', + 'to' => 'recorded_coupon_usage_counts', + 'cast' => 'null', + ), + array( + 'from' => 'number', + 'to' => 'number', + 'cast' => 'null', + ), + array( + 'from' => 'tax_lines', + 'to' => 'tax_lines', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_lines', + 'to' => 'shipping_lines', + 'cast' => 'null', + ), + array( + 'from' => 'fee_lines', + 'to' => 'fee_lines', + 'cast' => 'null', + ), + array( + 'from' => 'coupon_lines', + 'to' => 'coupon_lines', + 'cast' => 'null', + ), + array( + 'from' => 'line_items[].name', + 'to' => 'fields.Products[].Name', + 'cast' => 'string', + ), + array( + 'from' => 'line_items[].quantity', + 'to' => 'fields.Products[].Quantity', + 'cast' => 'string', + ), + array( + 'from' => 'line_items', + 'to' => 'line_items', + 'cast' => 'null', + ), + array( + 'from' => 'currency', + 'to' => 'currency', + 'cast' => 'null', + ), + ), + ), + ), +); diff --git a/forms-bridge/addons/zulip/templates/woo-orders.php b/forms-bridge/addons/zulip/templates/woo-orders.php new file mode 100644 index 0000000..6109807 --- /dev/null +++ b/forms-bridge/addons/zulip/templates/woo-orders.php @@ -0,0 +1,304 @@ + __( 'Woo Orders', 'forms-bridge' ), + 'description' => __( + 'WooCommerce orders form template. The resulting bridge will notify new woocommerce customers to Zulip streams', + 'forms-bridge' + ), + 'integrations' => array( 'woo' ), + 'fields' => array( + array( + 'ref' => '#form', + 'name' => 'title', + 'value' => __( 'Woo Checkout', 'forms-bridge' ), + ), + array( + 'ref' => '#bridge', + 'name' => 'endpoint', + 'value' => '/api/v1/messages', + ), + array( + 'ref' => '#bridge/custom_fields[]', + 'name' => 'topic', + 'label' => __( 'Topic', 'forms-bridge' ), + 'description' => __( 'Topic under which the messages will be notified', 'forms-bridge' ), + 'type' => 'text', + 'default' => 'WooCommerce', + 'required' => true, + ), + ), + 'bridge' => array( + 'endpoint' => '/api/v1/messages', + 'workflow' => array( 'summary' ), + 'custom_fields' => array( + array( + 'name' => 'type', + 'value' => 'stream', + ), + ), + 'mutations' => array( + array( + array( + 'from' => 'to[]', + 'to' => 'to[]', + 'cast' => 'integer', + ), + array( + 'from' => 'to', + 'to' => 'to', + 'cast' => 'json', + ), + array( + 'from' => 'id', + 'to' => 'id', + 'cast' => 'null', + ), + array( + 'from' => 'parent_id', + 'to' => 'parent_id', + 'cast' => 'null', + ), + array( + 'from' => 'status', + 'to' => 'status', + 'cast' => 'null', + ), + array( + 'from' => 'version', + 'to' => 'version', + 'cast' => 'null', + ), + array( + 'from' => 'prices_include_tax', + 'to' => 'prices_include_tax', + 'cast' => 'null', + ), + array( + 'from' => 'date_created', + 'to' => 'fields["Order Date"]', + 'cast' => 'null', + ), + array( + 'from' => 'date_modified', + 'to' => 'date_modified', + 'cast' => 'null', + ), + array( + 'from' => 'discount_total', + 'to' => 'discount_total', + 'cast' => 'null', + ), + array( + 'from' => 'discount_tax', + 'to' => 'discount_tax', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_total', + 'to' => 'shipping_total', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_tax', + 'to' => 'shipping_tax', + 'cast' => 'null', + ), + array( + 'from' => 'cart_total', + 'to' => 'cart_total', + 'cast' => 'null', + ), + array( + 'from' => 'cart_tax', + 'to' => 'cart_tax', + 'cast' => 'null', + ), + array( + 'from' => 'total', + 'to' => 'fields["Order Total"]', + 'cast' => 'string', + ), + array( + 'from' => 'total_tax', + 'to' => 'total_tax', + 'cast' => 'null', + ), + array( + 'from' => 'customer_id', + 'to' => 'customer_id', + 'cast' => 'null', + ), + array( + 'from' => 'order_key', + 'to' => 'order_key', + 'cast' => 'null', + ), + array( + 'from' => '?billing.company', + 'to' => 'fields.Company', + 'cast' => 'string', + ), + array( + 'from' => '?billing.first_name', + 'to' => 'fields["First Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.last_name', + 'to' => 'fields["Last Name"]', + 'cast' => 'string', + ), + array( + 'from' => 'billing.email', + 'to' => 'fields.Email', + 'cast' => 'string', + ), + array( + 'from' => '?billing.phone', + 'to' => 'fields.Phone', + 'cast' => 'string', + ), + array( + 'from' => 'billing', + 'to' => 'billing', + 'cast' => 'null', + ), + array( + 'from' => 'shipping', + 'to' => 'shipping', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method', + 'to' => 'payment_method', + 'cast' => 'null', + ), + array( + 'from' => 'payment_method_title', + 'to' => 'payment_method_title', + 'cast' => 'null', + ), + array( + 'from' => 'transaction_id', + 'to' => 'transaction_id', + 'cast' => 'null', + ), + array( + 'from' => 'customer_ip_address', + 'to' => 'ip_signup', + 'cast' => 'null', + ), + array( + 'from' => 'customer_user_agent', + 'to' => 'customer_user_agent', + 'cast' => 'null', + ), + array( + 'from' => 'created_via', + 'to' => 'created_via', + 'cast' => 'null', + ), + array( + 'from' => 'customer_note', + 'to' => 'notes', + 'cast' => 'null', + ), + array( + 'from' => 'date_completed', + 'to' => 'date_completed', + 'cast' => 'null', + ), + array( + 'from' => 'date_paid', + 'to' => 'date_paid', + 'cast' => 'null', + ), + array( + 'from' => 'cart_hash', + 'to' => 'cart_hash', + 'cast' => 'null', + ), + array( + 'from' => 'order_stock_reduced', + 'to' => 'order_stock_reduced', + 'cast' => 'null', + ), + array( + 'from' => 'download_permissions_granted', + 'to' => 'download_permissions_granted', + 'cast' => 'null', + ), + array( + 'from' => 'new_order_email_sent', + 'to' => 'new_order_email_sent', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_sales', + 'to' => 'recorded_sales', + 'cast' => 'null', + ), + array( + 'from' => 'recorded_coupon_usage_counts', + 'to' => 'recorded_coupon_usage_counts', + 'cast' => 'null', + ), + array( + 'from' => 'number', + 'to' => 'number', + 'cast' => 'null', + ), + array( + 'from' => 'tax_lines', + 'to' => 'tax_lines', + 'cast' => 'null', + ), + array( + 'from' => 'shipping_lines', + 'to' => 'shipping_lines', + 'cast' => 'null', + ), + array( + 'from' => 'fee_lines', + 'to' => 'fee_lines', + 'cast' => 'null', + ), + array( + 'from' => 'coupon_lines', + 'to' => 'coupon_lines', + 'cast' => 'null', + ), + array( + 'from' => 'line_items[].name', + 'to' => 'fields.Products[].Name', + 'cast' => 'string', + ), + array( + 'from' => 'line_items[].quantity', + 'to' => 'fields.Products[].Quantity', + 'cast' => 'string', + ), + array( + 'from' => 'line_items', + 'to' => 'line_items', + 'cast' => 'null', + ), + array( + 'from' => 'currency', + 'to' => 'currency', + 'cast' => 'null', + ), + ), + ), + ), +); From 0a153367f4be52ce9b73cb9828804a7d0b453ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Fri, 21 Nov 2025 21:21:54 +0100 Subject: [PATCH 2/2] fix: chat summary jobs on nested payloads --- .../addons/rocketchat/jobs/summary.php | 22 ++++++++++++++----- forms-bridge/addons/slack/jobs/summary-md.php | 22 ++++++++++++++----- .../addons/slack/jobs/summary-txt.php | 22 ++++++++++++++----- forms-bridge/addons/zulip/jobs/summary.php | 22 ++++++++++++++----- 4 files changed, 68 insertions(+), 20 deletions(-) diff --git a/forms-bridge/addons/rocketchat/jobs/summary.php b/forms-bridge/addons/rocketchat/jobs/summary.php index f0d711b..6ea0aeb 100644 --- a/forms-bridge/addons/rocketchat/jobs/summary.php +++ b/forms-bridge/addons/rocketchat/jobs/summary.php @@ -48,9 +48,21 @@ function forms_bridge_rocketchat_fields_summary_md( $payload ) { * @return string */ function forms_bridge_rocketchat_content_md( $data, $leading = '' ) { - $content = '**' . __( 'Fields', 'forms-bridge' ) . "**:\n"; - foreach ( $data as $name => $value ) { - $content .= forms_bridge_rocketchat_field_md( $name, $value, $leading ); + $content = ''; + + if ( ! strlen( $leading ) ) { + $content .= '**' . __( 'Fields', 'forms-bridge' ) . "**:\n"; + } + + if ( wp_is_numeric_array( $data ) ) { + $l = count( $data ); + for ( $i = 1; $i <= $l; $i++ ) { + $content .= forms_bridge_rocketchat_field_md( $i, $data[ $i - 1 ], $leading ); + } + } else { + foreach ( $data as $name => $value ) { + $content .= forms_bridge_rocketchat_field_md( $name, $value, $leading ); + } } return $content; @@ -69,8 +81,8 @@ function forms_bridge_rocketchat_field_md( $name, $value, $leading = '' ) { if ( is_array( $value ) || is_object( $value ) ) { $value = "\n" . forms_bridge_rocketchat_content_md( (array) $value, $leading . ' ' ); } elseif ( is_string( $value ) ) { - $value = preg_replace( '/\n+/', "\n{$leading} ", $value ); + $value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n"; } - return "{$leading}- **{$name}**: {$value}\n"; + return "{$leading}* **{$name}**: {$value}"; } diff --git a/forms-bridge/addons/slack/jobs/summary-md.php b/forms-bridge/addons/slack/jobs/summary-md.php index c837727..5327898 100644 --- a/forms-bridge/addons/slack/jobs/summary-md.php +++ b/forms-bridge/addons/slack/jobs/summary-md.php @@ -48,9 +48,21 @@ function forms_bridge_slack_fields_summary_md( $payload ) { * @return string */ function forms_bridge_slack_content_md( $data, $leading = '' ) { - $content = '**' . __( 'Fields', 'forms-bridge' ) . "**:\n"; - foreach ( $data as $name => $value ) { - $content .= forms_bridge_slack_field_md( $name, $value, $leading ); + $content = ''; + + if ( ! strlen( $leading ) ) { + $content .= '**' . __( 'Fields', 'forms-bridge' ) . "**:\n"; + } + + if ( wp_is_numeric_array( $data ) ) { + $l = count( $data ); + for ( $i = 1; $i <= $l; $i++ ) { + $content .= forms_bridge_slack_field_md( $i, $data[ $i - 1 ], $leading ); + } + } else { + foreach ( $data as $name => $value ) { + $content .= forms_bridge_slack_field_md( $name, $value, $leading ); + } } return $content; @@ -69,8 +81,8 @@ function forms_bridge_slack_field_md( $name, $value, $leading = '' ) { if ( is_array( $value ) || is_object( $value ) ) { $value = "\n" . forms_bridge_slack_content_md( (array) $value, $leading . ' ' ); } elseif ( is_string( $value ) ) { - $value = preg_replace( '/\n+/', "\n{$leading} ", $value ); + $value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n"; } - return "{$leading}- **{$name}**: {$value}\n"; + return "{$leading}- **{$name}**: {$value}"; } diff --git a/forms-bridge/addons/slack/jobs/summary-txt.php b/forms-bridge/addons/slack/jobs/summary-txt.php index c707171..66dc190 100644 --- a/forms-bridge/addons/slack/jobs/summary-txt.php +++ b/forms-bridge/addons/slack/jobs/summary-txt.php @@ -48,9 +48,21 @@ function forms_bridge_slack_fields_summary_txt( $payload ) { * @return string */ function forms_bridge_slack_content_txt( $data, $leading = '' ) { - $content = __( 'Fields', 'forms-bridge' ) . ":\n"; - foreach ( $data as $name => $value ) { - $content .= forms_bridge_slack_field_txt( $name, $value, $leading ); + $content = ''; + + if ( ! strlen( $leading ) ) { + $content = __( 'Fields', 'forms-bridge' ) . ":\n"; + } + + if ( wp_is_numeric_array( $data ) ) { + $l = count( $data ); + for ( $i = 1; $i <= $l; $i++ ) { + $content .= forms_bridge_slack_field_txt( $i, $data[ $i - 1 ], $leading ); + } + } else { + foreach ( $data as $name => $value ) { + $content .= forms_bridge_slack_field_txt( $name, $value, $leading ); + } } return $content; @@ -69,8 +81,8 @@ function forms_bridge_slack_field_txt( $name, $value, $leading = '' ) { if ( is_array( $value ) || is_object( $value ) ) { $value = "\n" . forms_bridge_slack_content_txt( (array) $value, $leading . ' ' ); } elseif ( is_string( $value ) ) { - $value = preg_replace( '/\n+/', "\n{$leading} ", $value ); + $value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n"; } - return "{$leading}- {$name}: {$value}\n"; + return "{$leading}- {$name}: {$value}"; } diff --git a/forms-bridge/addons/zulip/jobs/summary.php b/forms-bridge/addons/zulip/jobs/summary.php index d254358..c57a2a6 100644 --- a/forms-bridge/addons/zulip/jobs/summary.php +++ b/forms-bridge/addons/zulip/jobs/summary.php @@ -48,9 +48,21 @@ function forms_bridge_zulip_payload_summary_md( $payload ) { * @return string */ function forms_bridge_zulip_content_md( $data, $leading = '' ) { - $content = "---\n**" . __( 'Fields', 'forms-bridge' ) . "**:\n"; - foreach ( $data as $name => $value ) { - $content .= forms_bridge_zulip_field_md( $name, $value, $leading ); + $content = ''; + + if ( ! strlen( $leading ) ) { + $content .= "---\n**" . __( 'Fields', 'forms-bridge' ) . "**:\n"; + } + + if ( wp_is_numeric_array( $data ) ) { + $l = count( $data ); + for ( $i = 1; $i <= $l; $i++ ) { + $content .= forms_bridge_zulip_field_md( $i, $data[ $i - 1 ], $leading ); + } + } else { + foreach ( $data as $name => $value ) { + $content .= forms_bridge_zulip_field_md( $name, $value, $leading ); + } } return $content; @@ -69,8 +81,8 @@ function forms_bridge_zulip_field_md( $name, $value, $leading = '' ) { if ( is_array( $value ) || is_object( $value ) ) { $value = "\n" . forms_bridge_zulip_content_md( (array) $value, $leading . ' ' ); } elseif ( is_string( $value ) ) { - $value = preg_replace( '/\n+/', "\n{$leading} ", $value ); + $value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n"; } - return "{$leading}- **{$name}**: {$value}\n"; + return "{$leading}* **{$name}**: {$value}"; }