Skip to content

Commit

Permalink
Merge pull request #2 from weni-ai/release/0.1.0-goflow-0.144.3
Browse files Browse the repository at this point in the history
Release/0.1.0 goflow 0.144.3
  • Loading branch information
rasoro authored Jun 22, 2023
2 parents 18fe884 + f84288c commit cf1e365
Show file tree
Hide file tree
Showing 22 changed files with 544 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Upload coverage
if: success()
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true

Expand Down
5 changes: 5 additions & 0 deletions WENI-CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0.1.0-goflow-0.144.3
----------
* Add support for external services actions and events
* Add Support for trigger.params in Msg events
* Add support for trigger.params in ticket events
108 changes: 108 additions & 0 deletions assets/external_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package assets

import (
"fmt"

"github.com/nyaruka/gocommon/uuids"
)

// ExternalServiceUUID is the UUID of a external service
type ExternalServiceUUID uuids.UUID

// ExternalService is a third party service that can be called
//
// {
// "uuid": "4e19fc3c-ae17-4f6b-acb5-7d915e29dc27",
// "name": "Third party service integration 1",
// "uuid": "generic third party service",
// }
//
// @asset external_service
type ExternalService interface {
UUID() ExternalServiceUUID
Name() string
Type() string
}

// ExternalServiceReference is used to reference a external service
type ExternalServiceReference struct {
UUID ExternalServiceUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
}

type ExternalServiceCallAction struct {
Name string `json:"name"`
Value string `json:"value"`
}

type ExternalServiceParam struct {
Data struct {
Value interface{} `json:"value,omitempty"`
} `json:"data,omitempty"`
Filter struct {
Value *ExternalServiceFilterValue `json:"value"`
} `json:"filter,omitempty"`
Type string `json:"type,omitempty"`
VerboseName string `json:"verboseName,omitempty"`
}

type ExternalServiceFilterValue struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
VerboseName string `json:"verboseName,omitempty"`
}

func NewExternalServiceParam(
dataValue interface{},
filterName,
filterType,
filterVerboseName,
pType,
verboseName string,
) *ExternalServiceParam {
p := &ExternalServiceParam{}
p.Data.Value = dataValue
if filterName != "" && filterType != "" && filterVerboseName != "" {
p.Filter.Value = &ExternalServiceFilterValue{}
p.Filter.Value.Name = filterName
p.Filter.Value.Type = filterType
p.Filter.Value.VerboseName = filterVerboseName
} else {
p.Filter.Value = nil
}
p.Type = pType
p.VerboseName = verboseName
return p
}

// NewExternalServiceReference creates a new external service reference with the given UUID and name
func NewExternalServiceReference(uuid ExternalServiceUUID, name string) *ExternalServiceReference {
return &ExternalServiceReference{UUID: uuid, Name: name}
}

// Type returns the name of the asset type
func (r *ExternalServiceReference) Type() string {
return "external_service"
}

// GenericUUID returns the untyped UUID
func (r *ExternalServiceReference) GenericUUID() uuids.UUID {
return uuids.UUID(r.UUID)
}

// Identity retusns the unique identity of the asset
func (r *ExternalServiceReference) Identity() string {
return string(r.UUID)
}

// Variable returns whether this a variable (vs concrete) reference
func (r *ExternalServiceReference) Variable() bool {
return false
}

// String returns a formated string for the external service referenced
func (r *ExternalServiceReference) String() string {
return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name)
}

var _ UUIDReference = (*ExternalServiceReference)(nil)
1 change: 1 addition & 0 deletions assets/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package assets
type Source interface {
Channels() ([]Channel, error)
Classifiers() ([]Classifier, error)
ExternalServices() ([]ExternalService, error)
Fields() ([]Field, error)
Flow(FlowUUID) (Flow, error)
Globals() ([]Global, error)
Expand Down
30 changes: 30 additions & 0 deletions assets/static/external_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package static

import (
"github.com/nyaruka/goflow/assets"
)

// ExternalService is a JSON serializable implementation of a external service asset
type ExternalService struct {
UUID_ assets.ExternalServiceUUID `json:"uuid" validate:"required,uuid`
Name_ string `json:"name"`
Type_ string `json:"type"`
}

// NewExternalService creates a new external service
func NewExternalService(uuid assets.ExternalServiceUUID, name string, type_ string) assets.ExternalService {
return &ExternalService{
UUID_: uuid,
Name_: name,
Type_: type_,
}
}

// UUID returns the UUIUD of this external service
func (e *ExternalService) UUID() assets.ExternalServiceUUID { return e.UUID_ }

// Name returns the name of this external service
func (e *ExternalService) Name() string { return e.Name_ }

// Type returns the type of this external service
func (e *ExternalService) Type() string { return e.Type_ }
35 changes: 22 additions & 13 deletions assets/static/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import (
// StaticSource is an asset source which loads assets from a static JSON file
type StaticSource struct {
s struct {
Channels []*Channel `json:"channels" validate:"omitempty,dive"`
Classifiers []*Classifier `json:"classifiers" validate:"omitempty,dive"`
Fields []*Field `json:"fields" validate:"omitempty,dive"`
Flows []*Flow `json:"flows" validate:"omitempty,dive"`
Globals []*Global `json:"globals" validate:"omitempty,dive"`
Groups []*Group `json:"groups" validate:"omitempty,dive"`
Labels []*Label `json:"labels" validate:"omitempty,dive"`
Locations []*envs.LocationHierarchy `json:"locations"`
Resthooks []*Resthook `json:"resthooks" validate:"omitempty,dive"`
Templates []*Template `json:"templates" validate:"omitempty,dive"`
Ticketers []*Ticketer `json:"ticketers" validate:"omitempty,dive"`
Topics []*Topic `json:"topics" validate:"omitempty,dive"`
Users []*User `json:"users" validate:"omitempty,dive"`
Channels []*Channel `json:"channels" validate:"omitempty,dive"`
Classifiers []*Classifier `json:"classifiers" validate:"omitempty,dive"`
ExternalServices []*ExternalService `json:"externalServices" validate:"omitempty"`
Fields []*Field `json:"fields" validate:"omitempty,dive"`
Flows []*Flow `json:"flows" validate:"omitempty,dive"`
Globals []*Global `json:"globals" validate:"omitempty,dive"`
Groups []*Group `json:"groups" validate:"omitempty,dive"`
Labels []*Label `json:"labels" validate:"omitempty,dive"`
Locations []*envs.LocationHierarchy `json:"locations"`
Resthooks []*Resthook `json:"resthooks" validate:"omitempty,dive"`
Templates []*Template `json:"templates" validate:"omitempty,dive"`
Ticketers []*Ticketer `json:"ticketers" validate:"omitempty,dive"`
Topics []*Topic `json:"topics" validate:"omitempty,dive"`
Users []*User `json:"users" validate:"omitempty,dive"`
}
}

Expand Down Expand Up @@ -74,6 +75,14 @@ func (s *StaticSource) Classifiers() ([]assets.Classifier, error) {
return set, nil
}

func (s *StaticSource) ExternalServices() ([]assets.ExternalService, error) {
set := make([]assets.ExternalService, len(s.s.ExternalServices))
for i := range s.s.ExternalServices {
set[i] = s.s.ExternalServices[i]
}
return set, nil
}

// Fields returns all field assets
func (s *StaticSource) Fields() ([]assets.Field, error) {
set := make([]assets.Field, len(s.s.Fields))
Expand Down
3 changes: 3 additions & 0 deletions cmd/docgen/docs/html_renderers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func createItemListContextFunc(tag string, renderer renderFunc) ContextFunc {
buffer := &strings.Builder{}

for _, item := range items[tag] {
if len(item.examples) == 0 {
continue
}
if err := renderer(buffer, item, session, voiceSession); err != nil {
return nil, errors.Wrapf(err, "error rendering %s:%s", item.tagName, item.tagValue)
}
Expand Down
66 changes: 66 additions & 0 deletions flows/actions/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,72 @@ func TestConstructors(t *testing.T) {
"create_contact": true
}`,
},
{
actions.NewCallExternalService(
actionUUID,
assets.NewExternalServiceReference(assets.ExternalServiceUUID("75a246f4-6fe8-43bd-8e7f-3da1f69b4507"), "external service"),
assets.ExternalServiceCallAction{Name: "IncluirContato", Value: "IncluirContato"},
[]assets.ExternalServiceParam{
*assets.NewExternalServiceParam("123", "nCod", "integer", "Código do Contato", "identificacao", "Identificação"),
*assets.NewExternalServiceParam("fulano", "cNome", "string", "Nome do Contato", "identificacao", "Identificação"),
*assets.NewExternalServiceParam("obs1", "", "", "", "cObs", "Observações"),
},
"ExternalServiceResponse",
),
`{
"external_service": {
"name": "external service",
"uuid": "75a246f4-6fe8-43bd-8e7f-3da1f69b4507"
},
"type": "call_external_service",
"call": {
"name": "IncluirContato",
"value": "IncluirContato"
},
"params": [
{
"data": {
"value": "123"
},
"filter": {
"value": {
"name": "nCod",
"type": "integer",
"verboseName": "Código do Contato"
}
},
"type": "identificacao",
"verboseName": "Identificação"
},
{
"data": {
"value": "fulano"
},
"filter": {
"value": {
"name": "cNome",
"type": "string",
"verboseName": "Nome do Contato"
}
},
"type": "identificacao",
"verboseName": "Identificação"
},
{
"data": {
"value": "obs1"
},
"filter": {
"value": null
},
"type": "cObs",
"verboseName": "Observações"
}
],
"result_name": "ExternalServiceResponse",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912"
}`,
},
}

for _, tc := range tests {
Expand Down
Loading

0 comments on commit cf1e365

Please sign in to comment.