Skip to content

Commit 293dc88

Browse files
committed
Add 14.1 migration to make webhook nodes split on @webhook
1 parent 3665840 commit 293dc88

14 files changed

+267
-14
lines changed

flows/definition/flow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const (
2828
)
2929

3030
// CurrentSpecVersion is the flow spec version supported by this library
31-
var CurrentSpecVersion = semver.MustParse("14.0.0")
32-
var CurrentSupportedSpecs, _ = semver.NewConstraint(">= 11.0.0, < 14.1.0")
31+
var CurrentSpecVersion = semver.MustParse("14.1.0")
32+
var CurrentSupportedSpecs, _ = semver.NewConstraint(">= 11.0.0, < 14.2.0")
3333

3434
// IsVersionSupported checks the given version is supported
3535
func IsVersionSupported(v *semver.Version) bool {

flows/definition/flow_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func TestIsVersionSupported(t *testing.T) {
3232
assert.True(t, definition.IsVersionSupported(semver.MustParse("11.9")))
3333
assert.True(t, definition.IsVersionSupported(semver.MustParse("13.0.0")))
3434
assert.True(t, definition.IsVersionSupported(semver.MustParse("13.3.0")))
35-
assert.True(t, definition.IsVersionSupported(semver.MustParse("14.0.0")))
36-
assert.False(t, definition.IsVersionSupported(semver.MustParse("14.1.0")))
35+
assert.True(t, definition.IsVersionSupported(semver.MustParse("14.1.0")))
36+
assert.False(t, definition.IsVersionSupported(semver.MustParse("14.2.0")))
3737
assert.False(t, definition.IsVersionSupported(semver.MustParse("15.0.0")))
3838
}
3939

flows/definition/migrations/13_x.go flows/definition/migrations/migrations.go

+35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package migrations
33
import (
44
"encoding/json"
55
"fmt"
6+
"slices"
67
"strings"
78

89
"github.com/Masterminds/semver"
@@ -14,6 +15,7 @@ import (
1415
)
1516

1617
func init() {
18+
registerMigration(semver.MustParse("14.1.0"), Migrate14_1)
1719
registerMigration(semver.MustParse("14.0.0"), Migrate14_0)
1820
registerMigration(semver.MustParse("13.6.1"), Migrate13_6_1)
1921
registerMigration(semver.MustParse("13.6.0"), Migrate13_6)
@@ -24,6 +26,39 @@ func init() {
2426
registerMigration(semver.MustParse("13.1.0"), Migrate13_1)
2527
}
2628

29+
// Migrate14.1 changes webhook nodes to split on @webhook instead of the action's result.
30+
//
31+
// @version 14_1 "14.1"
32+
func Migrate14_1(f Flow, cfg *Config) (Flow, error) {
33+
webhookActions := []string{"call_webhook", "call_resthook"}
34+
35+
for _, node := range f.Nodes() {
36+
actions := node.Actions()
37+
router := node.Router()
38+
39+
// ignore if this isn't a webhook or resthook split
40+
if len(actions) != 1 || !slices.Contains(webhookActions, actions[0].Type()) || router == nil || router.Type() != "switch" {
41+
continue
42+
}
43+
44+
operand, _ := router["operand"].(string)
45+
cases, _ := router["cases"].([]any)
46+
47+
// ignore if it already isn't splitting on a result
48+
if !strings.HasPrefix(operand, "@results.") || len(cases) == 0 {
49+
continue
50+
}
51+
52+
router["operand"] = "@webhook.status"
53+
54+
case0, _ := cases[0].(map[string]any)
55+
case0["type"] = "has_number_between"
56+
case0["arguments"] = []any{"200", "299"}
57+
}
58+
59+
return f, nil
60+
}
61+
2762
// Migrate14.0 fixes invalid expires values and categories with missing names.
2863
// Note that this is a major version change because of other additions to the flow spec that don't require migration.
2964
//

flows/definition/migrations/specdata/templates.json

+96
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,100 @@
11
{
2+
"14.1.0": {
3+
"actions": {
4+
"add_contact_groups": [
5+
".groups[*].name_match"
6+
],
7+
"add_contact_urn": [
8+
".path"
9+
],
10+
"add_input_labels": [
11+
".labels[*].name_match"
12+
],
13+
"call_classifier": [
14+
".input"
15+
],
16+
"call_llm": [
17+
".input",
18+
".instructions"
19+
],
20+
"call_resthook": [],
21+
"call_webhook": [
22+
".body",
23+
".headers.*",
24+
".url"
25+
],
26+
"enter_flow": [],
27+
"open_ticket": [
28+
".assignee.email_match",
29+
".body"
30+
],
31+
"play_audio": [
32+
".audio_url"
33+
],
34+
"remove_contact_groups": [
35+
".groups[*].name_match"
36+
],
37+
"request_optin": [],
38+
"say_msg": [
39+
".text"
40+
],
41+
"send_broadcast": [
42+
".attachments[*]",
43+
".contact_query",
44+
".groups[*].name_match",
45+
".legacy_vars[*]",
46+
".quick_replies[*]",
47+
".text"
48+
],
49+
"send_email": [
50+
".addresses[*]",
51+
".body",
52+
".subject"
53+
],
54+
"send_msg": [
55+
".attachments[*]",
56+
".quick_replies[*]",
57+
".template_variables[*]",
58+
".text"
59+
],
60+
"set_contact_channel": [],
61+
"set_contact_field": [
62+
".value"
63+
],
64+
"set_contact_language": [
65+
".language"
66+
],
67+
"set_contact_name": [
68+
".name"
69+
],
70+
"set_contact_status": [],
71+
"set_contact_timezone": [
72+
".timezone"
73+
],
74+
"set_run_local": [
75+
".value"
76+
],
77+
"set_run_result": [
78+
".value"
79+
],
80+
"start_session": [
81+
".contact_query",
82+
".groups[*].name_match",
83+
".legacy_vars[*]"
84+
],
85+
"transfer_airtime": []
86+
},
87+
"routers": {
88+
"random": [
89+
".operand",
90+
".cases[*].arguments[*]"
91+
],
92+
"switch": [
93+
".operand",
94+
".cases[*].arguments[*]"
95+
]
96+
}
97+
},
298
"14.0.0": {
399
"actions": {
4100
"add_contact_groups": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
[
2+
{
3+
"description": "flow with webhook split on result",
4+
"original": {
5+
"uuid": "25a2d8b2-ae7c-4fed-964a-506fb8c3f0c0",
6+
"name": "Test Flow",
7+
"spec_version": "14.0.0",
8+
"language": "eng",
9+
"type": "messaging",
10+
"localization": {},
11+
"nodes": [
12+
{
13+
"uuid": "4eab7a66-0b55-45f6-803f-129a6f49e723",
14+
"actions": [
15+
{
16+
"uuid": "c766e805-da3a-46f4-97c4-7ce54b16bf71",
17+
"headers": {},
18+
"type": "call_webhook",
19+
"url": "http://temba.io/",
20+
"method": "GET",
21+
"result_name": "Call 2"
22+
}
23+
],
24+
"router": {
25+
"type": "switch",
26+
"operand": "@results.call_2.category",
27+
"cases": [
28+
{
29+
"uuid": "ff810df6-23c2-4dff-9be1-eebffae2bb9d",
30+
"type": "has_only_text",
31+
"arguments": [
32+
"Success"
33+
],
34+
"category_uuid": "be4ad508-3afb-4c4a-80ba-86b61518411c"
35+
}
36+
],
37+
"categories": [
38+
{
39+
"uuid": "be4ad508-3afb-4c4a-80ba-86b61518411c",
40+
"name": "Success",
41+
"exit_uuid": "24493dc0-687e-4d16-98e5-6e422624729b"
42+
},
43+
{
44+
"uuid": "501fc0c1-28a8-45b2-84f1-b6f9ea17d551",
45+
"name": "Failure",
46+
"exit_uuid": "09f2e979-e6d2-4d0c-b28d-88a836a41d2e"
47+
}
48+
],
49+
"default_category_uuid": "501fc0c1-28a8-45b2-84f1-b6f9ea17d551"
50+
},
51+
"exits": [
52+
{
53+
"uuid": "24493dc0-687e-4d16-98e5-6e422624729b"
54+
},
55+
{
56+
"uuid": "09f2e979-e6d2-4d0c-b28d-88a836a41d2e"
57+
}
58+
]
59+
}
60+
]
61+
},
62+
"migrated": {
63+
"uuid": "25a2d8b2-ae7c-4fed-964a-506fb8c3f0c0",
64+
"name": "Test Flow",
65+
"spec_version": "14.1.0",
66+
"language": "eng",
67+
"type": "messaging",
68+
"localization": {},
69+
"nodes": [
70+
{
71+
"uuid": "4eab7a66-0b55-45f6-803f-129a6f49e723",
72+
"actions": [
73+
{
74+
"uuid": "c766e805-da3a-46f4-97c4-7ce54b16bf71",
75+
"headers": {},
76+
"type": "call_webhook",
77+
"url": "http://temba.io/",
78+
"method": "GET",
79+
"result_name": "Call 2"
80+
}
81+
],
82+
"router": {
83+
"type": "switch",
84+
"operand": "@webhook.status",
85+
"cases": [
86+
{
87+
"uuid": "ff810df6-23c2-4dff-9be1-eebffae2bb9d",
88+
"type": "has_number_between",
89+
"arguments": [
90+
"200",
91+
"299"
92+
],
93+
"category_uuid": "be4ad508-3afb-4c4a-80ba-86b61518411c"
94+
}
95+
],
96+
"categories": [
97+
{
98+
"uuid": "be4ad508-3afb-4c4a-80ba-86b61518411c",
99+
"name": "Success",
100+
"exit_uuid": "24493dc0-687e-4d16-98e5-6e422624729b"
101+
},
102+
{
103+
"uuid": "501fc0c1-28a8-45b2-84f1-b6f9ea17d551",
104+
"name": "Failure",
105+
"exit_uuid": "09f2e979-e6d2-4d0c-b28d-88a836a41d2e"
106+
}
107+
],
108+
"default_category_uuid": "501fc0c1-28a8-45b2-84f1-b6f9ea17d551"
109+
},
110+
"exits": [
111+
{
112+
"uuid": "24493dc0-687e-4d16-98e5-6e422624729b"
113+
},
114+
{
115+
"uuid": "09f2e979-e6d2-4d0c-b28d-88a836a41d2e"
116+
}
117+
]
118+
}
119+
]
120+
}
121+
}
122+
]

flows/definition/testdata/TestChangeLanguage_change_language_to_ara.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"uuid": "19cad1f2-9110-4271-98d4-1b968bf19410",
33
"name": "Change Language",
4-
"spec_version": "14.0.0",
4+
"spec_version": "14.1.0",
55
"language": "ara",
66
"type": "messaging",
77
"revision": 16,

flows/definition/testdata/TestChangeLanguage_change_language_to_kin.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"uuid": "19cad1f2-9110-4271-98d4-1b968bf19410",
33
"name": "Change Language",
4-
"spec_version": "14.0.0",
4+
"spec_version": "14.1.0",
55
"language": "kin",
66
"type": "messaging",
77
"revision": 16,

flows/definition/testdata/TestChangeLanguage_change_language_to_spa.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"uuid": "19cad1f2-9110-4271-98d4-1b968bf19410",
33
"name": "Change Language",
4-
"spec_version": "14.0.0",
4+
"spec_version": "14.1.0",
55
"language": "spa",
66
"type": "messaging",
77
"revision": 16,

flows/definition/testdata/change_language.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"uuid": "19cad1f2-9110-4271-98d4-1b968bf19410",
55
"name": "Change Language",
6-
"spec_version": "14.0.0",
6+
"spec_version": "14.1.0",
77
"language": "eng",
88
"type": "messaging",
99
"revision": 16,

test/testdata/runner/legacy_webhook.test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"exit_uuid": "dd9f9855-46fd-42e9-9dc0-6694439594b3",
5858
"flow_uuid": "0256c9fc-8194-4567-b4ab-6965c2b7d791",
5959
"node_uuid": "30c97f0e-e537-4940-ad1f-85599d3634b3",
60-
"operand": "Success",
60+
"operand": "200",
6161
"time": "2018-07-06T12:30:10.123456789Z"
6262
}
6363
],

test/testdata/runner/resthook.test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"exit_uuid": "cffd72b4-0b30-41a8-ae2b-b8e5019a164d",
112112
"flow_uuid": "76f0a02f-3b75-4b86-9064-e9195e1b3a02",
113113
"node_uuid": "10e483a8-5ffb-4c4f-917b-d43ce86c1d65",
114-
"operand": "Failure",
114+
"operand": "400",
115115
"time": "2018-07-06T12:30:16.123456789Z"
116116
}
117117
],

test/testdata/runner/webhook_migrated.test.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"exit_uuid": "96a1ff26-af04-4698-a4bd-40939bf2e7ab",
168168
"flow_uuid": "76f0a02f-3b75-4b86-9064-e9195e1b3a02",
169169
"node_uuid": "d02536d0-7e86-47ab-8c60-fcf2678abc2b",
170-
"operand": "Success",
170+
"operand": "200",
171171
"time": "2018-07-06T12:30:23.123456789Z"
172172
}
173173
],

test/testdata/runner/webhook_noresult.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Webhook Results",
55
"uuid": "68dae09d-db22-4879-90a7-a89395e3167b",
6-
"spec_version": "14.0.0",
6+
"spec_version": "14.1.0",
77
"language": "eng",
88
"type": "messaging",
99
"nodes": [

test/testdata/runner/webhook_results.test.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"exit_uuid": "b0c4e70e-ecee-4103-a755-3877f11e5801",
6161
"flow_uuid": "68dae09d-db22-4879-90a7-a89395e3167b",
6262
"node_uuid": "03eec86c-190c-48a2-bdaa-bbe07b36bd2f",
63-
"operand": "Success",
63+
"operand": "200",
6464
"time": "2018-07-06T12:30:10.123456789Z"
6565
},
6666
{
@@ -301,7 +301,7 @@
301301
"exit_uuid": "24493dc0-687e-4d16-98e5-6e422624729b",
302302
"flow_uuid": "68dae09d-db22-4879-90a7-a89395e3167b",
303303
"node_uuid": "4eab7a66-0b55-45f6-803f-129a6f49e723",
304-
"operand": "Success",
304+
"operand": "200",
305305
"time": "2018-07-06T12:30:43.123456789Z"
306306
},
307307
{

0 commit comments

Comments
 (0)