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
4 changes: 2 additions & 2 deletions flows/definition/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

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

// IsVersionSupported checks the given version is supported
func IsVersionSupported(v *semver.Version) bool {
Expand Down
4 changes: 2 additions & 2 deletions flows/definition/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestIsVersionSupported(t *testing.T) {
assert.True(t, definition.IsVersionSupported(semver.MustParse("11.9")))
assert.True(t, definition.IsVersionSupported(semver.MustParse("13.0.0")))
assert.True(t, definition.IsVersionSupported(semver.MustParse("13.3.0")))
assert.True(t, definition.IsVersionSupported(semver.MustParse("14.0.0")))
assert.False(t, definition.IsVersionSupported(semver.MustParse("14.1.0")))
assert.True(t, definition.IsVersionSupported(semver.MustParse("14.1.0")))
assert.False(t, definition.IsVersionSupported(semver.MustParse("14.2.0")))
assert.False(t, definition.IsVersionSupported(semver.MustParse("15.0.0")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"encoding/json"
"fmt"
"slices"
"strings"

"github.com/Masterminds/semver"
Expand All @@ -14,6 +15,7 @@
)

func init() {
registerMigration(semver.MustParse("14.1.0"), Migrate14_1)
registerMigration(semver.MustParse("14.0.0"), Migrate14_0)
registerMigration(semver.MustParse("13.6.1"), Migrate13_6_1)
registerMigration(semver.MustParse("13.6.0"), Migrate13_6)
Expand All @@ -24,6 +26,40 @@
registerMigration(semver.MustParse("13.1.0"), Migrate13_1)
}

// Migrate14.1 changes webhook nodes to split on @webhook instead of the action's result.
//
// @version 14_1 "14.1"
func Migrate14_1(f Flow, cfg *Config) (Flow, error) {
webhookActions := []string{"call_webhook", "call_resthook"}

for _, node := range f.Nodes() {
actions := node.Actions()
router := node.Router()

// ignore if this isn't a webhook or resthook split
if len(actions) != 1 || !slices.Contains(webhookActions, actions[0].Type()) || router == nil || router.Type() != "switch" {
continue
}

operand, _ := router["operand"].(string)
cases, _ := router["cases"].([]any)

// ignore if it already isn't splitting on a result
if !strings.HasPrefix(operand, "@results.") || len(cases) == 0 {
continue

Check warning on line 49 in flows/definition/migrations/migrations.go

View check run for this annotation

Codecov / codecov/patch

flows/definition/migrations/migrations.go#L49

Added line #L49 was not covered by tests
}

case0, _ := cases[0].(map[string]any)
case0["type"] = "has_number_between"
case0["arguments"] = []any{"200", "299"}

router["operand"] = "@webhook.status"
router["cases"] = []any{case0}
}

return f, nil
}

// Migrate14.0 fixes invalid expires values and categories with missing names.
// Note that this is a major version change because of other additions to the flow spec that don't require migration.
//
Expand Down
96 changes: 96 additions & 0 deletions flows/definition/migrations/specdata/templates.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,100 @@
{
"14.1.0": {
"actions": {
"add_contact_groups": [
".groups[*].name_match"
],
"add_contact_urn": [
".path"
],
"add_input_labels": [
".labels[*].name_match"
],
"call_classifier": [
".input"
],
"call_llm": [
".input",
".instructions"
],
"call_resthook": [],
"call_webhook": [
".body",
".headers.*",
".url"
],
"enter_flow": [],
"open_ticket": [
".assignee.email_match",
".body"
],
"play_audio": [
".audio_url"
],
"remove_contact_groups": [
".groups[*].name_match"
],
"request_optin": [],
"say_msg": [
".text"
],
"send_broadcast": [
".attachments[*]",
".contact_query",
".groups[*].name_match",
".legacy_vars[*]",
".quick_replies[*]",
".text"
],
"send_email": [
".addresses[*]",
".body",
".subject"
],
"send_msg": [
".attachments[*]",
".quick_replies[*]",
".template_variables[*]",
".text"
],
"set_contact_channel": [],
"set_contact_field": [
".value"
],
"set_contact_language": [
".language"
],
"set_contact_name": [
".name"
],
"set_contact_status": [],
"set_contact_timezone": [
".timezone"
],
"set_run_local": [
".value"
],
"set_run_result": [
".value"
],
"start_session": [
".contact_query",
".groups[*].name_match",
".legacy_vars[*]"
],
"transfer_airtime": []
},
"routers": {
"random": [
".operand",
".cases[*].arguments[*]"
],
"switch": [
".operand",
".cases[*].arguments[*]"
]
}
},
"14.0.0": {
"actions": {
"add_contact_groups": [
Expand Down
Loading