Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions forms-bridge/addons/rocketchat/jobs/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}";
}
297 changes: 297 additions & 0 deletions forms-bridge/addons/rocketchat/templates/woo-orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
<?php
/**
* Rocket.Chat Wooommerce orders channel bridge template
*
* @package formsbridge
*/

if ( ! defined( 'ABSPATH' ) ) {
exit();
}

return array(
'title' => __( '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',
),
),
),
),
);
22 changes: 17 additions & 5 deletions forms-bridge/addons/slack/jobs/summary-md.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}";
}
Loading