Skip to content

Commit bf57528

Browse files
authored
Merge pull request #12 from codeccoop/feat/woo-chat-templates
Feat/woo chat templates
2 parents 86a5487 + 0a15336 commit bf57528

File tree

7 files changed

+948
-20
lines changed

7 files changed

+948
-20
lines changed

forms-bridge/addons/rocketchat/jobs/summary.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,21 @@ function forms_bridge_rocketchat_fields_summary_md( $payload ) {
4848
* @return string
4949
*/
5050
function forms_bridge_rocketchat_content_md( $data, $leading = '' ) {
51-
$content = '**' . __( 'Fields', 'forms-bridge' ) . "**:\n";
52-
foreach ( $data as $name => $value ) {
53-
$content .= forms_bridge_rocketchat_field_md( $name, $value, $leading );
51+
$content = '';
52+
53+
if ( ! strlen( $leading ) ) {
54+
$content .= '**' . __( 'Fields', 'forms-bridge' ) . "**:\n";
55+
}
56+
57+
if ( wp_is_numeric_array( $data ) ) {
58+
$l = count( $data );
59+
for ( $i = 1; $i <= $l; $i++ ) {
60+
$content .= forms_bridge_rocketchat_field_md( $i, $data[ $i - 1 ], $leading );
61+
}
62+
} else {
63+
foreach ( $data as $name => $value ) {
64+
$content .= forms_bridge_rocketchat_field_md( $name, $value, $leading );
65+
}
5466
}
5567

5668
return $content;
@@ -69,8 +81,8 @@ function forms_bridge_rocketchat_field_md( $name, $value, $leading = '' ) {
6981
if ( is_array( $value ) || is_object( $value ) ) {
7082
$value = "\n" . forms_bridge_rocketchat_content_md( (array) $value, $leading . ' ' );
7183
} elseif ( is_string( $value ) ) {
72-
$value = preg_replace( '/\n+/', "\n{$leading} ", $value );
84+
$value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n";
7385
}
7486

75-
return "{$leading}- **{$name}**: {$value}\n";
87+
return "{$leading}* **{$name}**: {$value}";
7688
}
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
<?php
2+
/**
3+
* Rocket.Chat Wooommerce orders channel bridge template
4+
*
5+
* @package formsbridge
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit();
10+
}
11+
12+
return array(
13+
'title' => __( 'Woo Orders', 'forms-bridge' ),
14+
'description' => __(
15+
'WooCommerce orders form template. The resulting bridge will notify new woocommerce customers to Rocket.Chat channels',
16+
'forms-bridge'
17+
),
18+
'integrations' => array( 'woo' ),
19+
'fields' => array(
20+
array(
21+
'ref' => '#bridge',
22+
'name' => 'endpoint',
23+
'value' => '/api/v1/chat.postMessage',
24+
),
25+
array(
26+
'ref' => '#bridge/custom_fields[]',
27+
'name' => 'roomId',
28+
'label' => __( 'Channel', 'forms-bridge' ),
29+
'description' => __(
30+
'Name of the channel where messages will be sent',
31+
'forms-bridge'
32+
),
33+
'type' => 'select',
34+
'options' => array(
35+
'endpoint' => '/api/v1/rooms.get',
36+
'finger' => array(
37+
'value' => 'update[]._id',
38+
'label' => 'update[].name',
39+
),
40+
),
41+
'required' => true,
42+
),
43+
array(
44+
'ref' => '#form',
45+
'name' => 'title',
46+
'default' => __( 'Contacts', 'forms-bridge' ),
47+
),
48+
),
49+
'bridge' => array(
50+
'endpoint' => '/api/v1/chat.postMessage',
51+
'workflow' => array( 'summary' ),
52+
'mutations' => array(
53+
array(
54+
array(
55+
'from' => 'id',
56+
'to' => 'id',
57+
'cast' => 'null',
58+
),
59+
array(
60+
'from' => 'parent_id',
61+
'to' => 'parent_id',
62+
'cast' => 'null',
63+
),
64+
array(
65+
'from' => 'status',
66+
'to' => 'status',
67+
'cast' => 'null',
68+
),
69+
array(
70+
'from' => 'version',
71+
'to' => 'version',
72+
'cast' => 'null',
73+
),
74+
array(
75+
'from' => 'prices_include_tax',
76+
'to' => 'prices_include_tax',
77+
'cast' => 'null',
78+
),
79+
array(
80+
'from' => 'date_created',
81+
'to' => 'fields["Order Date"]',
82+
'cast' => 'string',
83+
),
84+
array(
85+
'from' => 'date_modified',
86+
'to' => 'date_modified',
87+
'cast' => 'null',
88+
),
89+
array(
90+
'from' => 'discount_total',
91+
'to' => 'discount_total',
92+
'cast' => 'null',
93+
),
94+
array(
95+
'from' => 'discount_tax',
96+
'to' => 'discount_tax',
97+
'cast' => 'null',
98+
),
99+
array(
100+
'from' => 'shipping_total',
101+
'to' => 'shipping_total',
102+
'cast' => 'null',
103+
),
104+
array(
105+
'from' => 'shipping_tax',
106+
'to' => 'shipping_tax',
107+
'cast' => 'null',
108+
),
109+
array(
110+
'from' => 'cart_total',
111+
'to' => 'cart_total',
112+
'cast' => 'null',
113+
),
114+
array(
115+
'from' => 'cart_tax',
116+
'to' => 'cart_tax',
117+
'cast' => 'null',
118+
),
119+
array(
120+
'from' => 'total',
121+
'to' => 'fields["Order Total"]',
122+
'cast' => 'string',
123+
),
124+
array(
125+
'from' => 'total_tax',
126+
'to' => 'total_tax',
127+
'cast' => 'null',
128+
),
129+
array(
130+
'from' => 'customer_id',
131+
'to' => 'customer_id',
132+
'cast' => 'null',
133+
),
134+
array(
135+
'from' => 'order_key',
136+
'to' => 'order_key',
137+
'cast' => 'null',
138+
),
139+
array(
140+
'from' => '?billing.company',
141+
'to' => 'fields.Company',
142+
'cast' => 'string',
143+
),
144+
array(
145+
'from' => '?billing.first_name',
146+
'to' => 'fields["First Name"]',
147+
'cast' => 'string',
148+
),
149+
array(
150+
'from' => 'billing.last_name',
151+
'to' => 'fields["Last Name"]',
152+
'cast' => 'string',
153+
),
154+
array(
155+
'from' => 'billing.email',
156+
'to' => 'fields.Email',
157+
'cast' => 'string',
158+
),
159+
array(
160+
'from' => '?billing.phone',
161+
'to' => 'fields.Phone',
162+
'cast' => 'string',
163+
),
164+
array(
165+
'from' => 'billing',
166+
'to' => 'billing',
167+
'cast' => 'null',
168+
),
169+
array(
170+
'from' => 'shipping',
171+
'to' => 'shipping',
172+
'cast' => 'null',
173+
),
174+
array(
175+
'from' => 'payment_method',
176+
'to' => 'payment_method',
177+
'cast' => 'null',
178+
),
179+
array(
180+
'from' => 'payment_method_title',
181+
'to' => 'payment_method_title',
182+
'cast' => 'null',
183+
),
184+
array(
185+
'from' => 'transaction_id',
186+
'to' => 'transaction_id',
187+
'cast' => 'null',
188+
),
189+
array(
190+
'from' => 'customer_ip_address',
191+
'to' => 'ip_signup',
192+
'cast' => 'null',
193+
),
194+
array(
195+
'from' => 'customer_user_agent',
196+
'to' => 'customer_user_agent',
197+
'cast' => 'null',
198+
),
199+
array(
200+
'from' => 'created_via',
201+
'to' => 'created_via',
202+
'cast' => 'null',
203+
),
204+
array(
205+
'from' => 'customer_note',
206+
'to' => 'notes',
207+
'cast' => 'null',
208+
),
209+
array(
210+
'from' => 'date_completed',
211+
'to' => 'date_completed',
212+
'cast' => 'null',
213+
),
214+
array(
215+
'from' => 'date_paid',
216+
'to' => 'date_paid',
217+
'cast' => 'null',
218+
),
219+
array(
220+
'from' => 'cart_hash',
221+
'to' => 'cart_hash',
222+
'cast' => 'null',
223+
),
224+
array(
225+
'from' => 'order_stock_reduced',
226+
'to' => 'order_stock_reduced',
227+
'cast' => 'null',
228+
),
229+
array(
230+
'from' => 'download_permissions_granted',
231+
'to' => 'download_permissions_granted',
232+
'cast' => 'null',
233+
),
234+
array(
235+
'from' => 'new_order_email_sent',
236+
'to' => 'new_order_email_sent',
237+
'cast' => 'null',
238+
),
239+
array(
240+
'from' => 'recorded_sales',
241+
'to' => 'recorded_sales',
242+
'cast' => 'null',
243+
),
244+
array(
245+
'from' => 'recorded_coupon_usage_counts',
246+
'to' => 'recorded_coupon_usage_counts',
247+
'cast' => 'null',
248+
),
249+
array(
250+
'from' => 'number',
251+
'to' => 'number',
252+
'cast' => 'null',
253+
),
254+
array(
255+
'from' => 'tax_lines',
256+
'to' => 'tax_lines',
257+
'cast' => 'null',
258+
),
259+
array(
260+
'from' => 'shipping_lines',
261+
'to' => 'shipping_lines',
262+
'cast' => 'null',
263+
),
264+
array(
265+
'from' => 'fee_lines',
266+
'to' => 'fee_lines',
267+
'cast' => 'null',
268+
),
269+
array(
270+
'from' => 'coupon_lines',
271+
'to' => 'coupon_lines',
272+
'cast' => 'null',
273+
),
274+
array(
275+
'from' => 'line_items[].name',
276+
'to' => 'fields.Products[].Name',
277+
'cast' => 'string',
278+
),
279+
array(
280+
'from' => 'line_items[].quantity',
281+
'to' => 'fields.Products[].Quantity',
282+
'cast' => 'string',
283+
),
284+
array(
285+
'from' => 'line_items',
286+
'to' => 'line_items',
287+
'cast' => 'null',
288+
),
289+
array(
290+
'from' => 'currency',
291+
'to' => 'currency',
292+
'cast' => 'null',
293+
),
294+
),
295+
),
296+
),
297+
);

forms-bridge/addons/slack/jobs/summary-md.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,21 @@ function forms_bridge_slack_fields_summary_md( $payload ) {
4848
* @return string
4949
*/
5050
function forms_bridge_slack_content_md( $data, $leading = '' ) {
51-
$content = '**' . __( 'Fields', 'forms-bridge' ) . "**:\n";
52-
foreach ( $data as $name => $value ) {
53-
$content .= forms_bridge_slack_field_md( $name, $value, $leading );
51+
$content = '';
52+
53+
if ( ! strlen( $leading ) ) {
54+
$content .= '**' . __( 'Fields', 'forms-bridge' ) . "**:\n";
55+
}
56+
57+
if ( wp_is_numeric_array( $data ) ) {
58+
$l = count( $data );
59+
for ( $i = 1; $i <= $l; $i++ ) {
60+
$content .= forms_bridge_slack_field_md( $i, $data[ $i - 1 ], $leading );
61+
}
62+
} else {
63+
foreach ( $data as $name => $value ) {
64+
$content .= forms_bridge_slack_field_md( $name, $value, $leading );
65+
}
5466
}
5567

5668
return $content;
@@ -69,8 +81,8 @@ function forms_bridge_slack_field_md( $name, $value, $leading = '' ) {
6981
if ( is_array( $value ) || is_object( $value ) ) {
7082
$value = "\n" . forms_bridge_slack_content_md( (array) $value, $leading . ' ' );
7183
} elseif ( is_string( $value ) ) {
72-
$value = preg_replace( '/\n+/', "\n{$leading} ", $value );
84+
$value = preg_replace( '/\n+/', "\n{$leading} ", $value ) . "\n";
7385
}
7486

75-
return "{$leading}- **{$name}**: {$value}\n";
87+
return "{$leading}- **{$name}**: {$value}";
7688
}

0 commit comments

Comments
 (0)