Skip to content

Commit

Permalink
Update to latest goflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 5, 2021
1 parent fa7145b commit 33ecd1b
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 24 deletions.
4 changes: 2 additions & 2 deletions core/goflow/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ type simulatorTicketService struct {
ticketer *flows.Ticketer
}

func (s *simulatorTicketService) Open(session flows.Session, subject, body string, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, subject, body), nil
func (s *simulatorTicketService) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, topic, subject, body, assignee), nil
}

func simulatorAirtimeServiceFactory(session flows.Session) (flows.AirtimeService, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/goflow/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestSimulatorTicket(t *testing.T) {
svc, err := goflow.Simulator(rt.Config).Services().Ticket(nil, flows.NewTicketer(ticketer))
assert.NoError(t, err)

ticket, err := svc.Open(nil, "New ticket", "Where are my cookies?", nil)
ticket, err := svc.Open(nil, nil, "New ticket", "Where are my cookies?", nil, nil)
assert.NoError(t, err)
assert.Equal(t, testdata.Mailgun.UUID, ticket.Ticketer().UUID())
assert.Equal(t, "New ticket", ticket.Subject())
Expand Down
25 changes: 23 additions & 2 deletions core/handlers/ticket_opened_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,26 @@ func TestTicketOpened(t *testing.T) {
{
Actions: handlers.ContactActionMap{
testdata.Cathy: []flows.Action{
actions.NewOpenTicket(handlers.NewActionUUID(), assets.NewTicketerReference(testdata.Mailgun.UUID, "Mailgun (IT Support)"), "Need help", "Where are my cookies?", "Email Ticket"),
actions.NewOpenTicket(
handlers.NewActionUUID(),
assets.NewTicketerReference(testdata.Mailgun.UUID, "Mailgun (IT Support)"),
nil,
"Need help",
"Where are my cookies?",
assets.NewUserReference(testdata.Admin.Email, "Admin"),
"Email Ticket",
),
},
testdata.Bob: []flows.Action{
actions.NewOpenTicket(handlers.NewActionUUID(), assets.NewTicketerReference(testdata.Zendesk.UUID, "Zendesk (Nyaruka)"), "Interesting", "I've found some cookies", "Zen Ticket"),
actions.NewOpenTicket(
handlers.NewActionUUID(),
assets.NewTicketerReference(testdata.Zendesk.UUID, "Zendesk (Nyaruka)"),
nil,
"Interesting",
"I've found some cookies",
nil,
"Zen Ticket",
),
},
},
SQLAssertions: []handlers.SQLAssertion{
Expand Down Expand Up @@ -94,6 +110,11 @@ func TestTicketOpened(t *testing.T) {
SQL: "select count(*) from tickets_ticketevent where event_type = 'O'",
Count: 2,
},
{ // one of our tickets is assigned to admin
SQL: "select count(*) from tickets_ticket where assignee_id = $1",
Args: []interface{}{testdata.Admin.ID},
Count: 1,
},
},
},
}
Expand Down
7 changes: 6 additions & 1 deletion core/models/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ const (
RefreshLabels = Refresh(1 << 12)
RefreshFlows = Refresh(1 << 13)
RefreshTicketers = Refresh(1 << 14)
RefreshUsers = Refresh(1 << 15)
RefreshTopics = Refresh(1 << 15)
RefreshUsers = Refresh(1 << 16)
)

// GetOrgAssets creates or gets org assets for the passed in org
Expand Down Expand Up @@ -629,6 +630,10 @@ func (a *OrgAssets) TicketerByUUID(uuid assets.TicketerUUID) *Ticketer {
return a.ticketersByUUID[uuid]
}

func (a *OrgAssets) Topics() ([]assets.Topic, error) {
return nil, nil // TODO
}

func (a *OrgAssets) Users() ([]assets.User, error) {
return a.users, nil
}
Expand Down
1 change: 1 addition & 0 deletions core/models/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (t *Ticket) FlowTicket(oa *OrgAssets) (*flows.Ticket, error) {
return flows.NewTicket(
t.UUID(),
oa.SessionAssets().Ticketers().Get(modelTicketer.UUID()),
nil, // TODO
t.Subject(),
t.Body(),
string(t.ExternalID()),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.13.0
github.com/nyaruka/goflow v0.131.1
github.com/nyaruka/goflow v0.132.0
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0=
github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw=
github.com/nyaruka/gocommon v1.13.0 h1:WPL//ekajA30KinYRr6IrdP1igNZpcUAfABleHCuxPQ=
github.com/nyaruka/gocommon v1.13.0/go.mod h1:Jn7UIE8zwIr4JaviDf4PZrrQlN8r6QGVhOuaF/JoKus=
github.com/nyaruka/goflow v0.131.1 h1:jgwxO+A/FK1YtL7cDndiLpMIB15/IkI+hXnmuAIu41I=
github.com/nyaruka/goflow v0.131.1/go.mod h1:Xp1p21TyYiMM/fVQNWQRok/fZ1ZeNoeQGUd//LvYxq4=
github.com/nyaruka/goflow v0.132.0 h1:8dtnwWFJgGElSJl7r6XPtiWq8Vy6j9Lq4qMAm54gjBk=
github.com/nyaruka/goflow v0.132.0/go.mod h1:Xp1p21TyYiMM/fVQNWQRok/fZ1ZeNoeQGUd//LvYxq4=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/intern/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func NewService(rtCfg *config.Config, httpClient *http.Client, httpRetries *http
}

// Open just returns a new ticket - no external service to notify
func (s *service) Open(session flows.Session, subject, body string, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, subject, body), nil
func (s *service) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
return flows.OpenTicket(s.ticketer, topic, subject, body, assignee), nil
}

// Forward is a noop
Expand Down
2 changes: 1 addition & 1 deletion services/tickets/intern/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestOpenAndForward(t *testing.T) {

logger := &flows.HTTPLogger{}

ticket, err := svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
ticket, err := svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.NoError(t, err)
assert.Equal(t, flows.TicketUUID("e7187099-7d38-4f60-955c-325957214c42"), ticket.UUID())
assert.Equal(t, "Need help", ticket.Subject())
Expand Down
8 changes: 6 additions & 2 deletions services/tickets/mailgun/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ func NewService(rtCfg *config.Config, httpClient *http.Client, httpRetries *http
}

// Open opens a ticket which for mailgun means just sending an initial email
func (s *service) Open(session flows.Session, subject, body string, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, subject, body)
func (s *service) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, topic, subject, body, assignee)
contactDisplay := tickets.GetContactDisplay(session.Environment(), session.Contact())

if topic != nil {
subject = topic.Name()
}

from := s.ticketAddress(contactDisplay, ticket.UUID())
context := s.templateContext(subject, body, "", string(session.Contact().UUID()), contactDisplay)
fullBody := evaluateTemplate(openBodyTemplate, context)
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/mailgun/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func TestOpenAndForward(t *testing.T) {

logger := &flows.HTTPLogger{}

_, err = svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
_, err = svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.EqualError(t, err, "error calling mailgun API: unable to connect to server")

logger = &flows.HTTPLogger{}

ticket, err := svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
ticket, err := svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.NoError(t, err)
assert.Equal(t, flows.TicketUUID("9688d21d-95aa-4bed-afc7-f31b35731a3d"), ticket.UUID())
assert.Equal(t, "Need help", ticket.Subject())
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/rocketchat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewService(rtCfg *config.Config, httpClient *http.Client, httpRetries *http
type VisitorToken models.ContactID

// Open opens a ticket which for RocketChat means open a room associated to a visitor user
func (s *service) Open(session flows.Session, subject, body string, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, subject, body)
func (s *service) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, topic, subject, body, assignee)
contact := session.Contact()
email := ""
phone := ""
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/rocketchat/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func TestOpenAndForward(t *testing.T) {
assert.NoError(t, err)

logger := &flows.HTTPLogger{}
_, err = svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
_, err = svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.EqualError(t, err, "error calling RocketChat: unable to connect to server")

logger = &flows.HTTPLogger{}
ticket, err := svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
ticket, err := svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.NoError(t, err)
assert.Equal(t, flows.TicketUUID("59d74b86-3e2f-4a93-aece-b05d2fdcde0c"), ticket.UUID())
assert.Equal(t, "Need help", ticket.Subject())
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/zendesk/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func NewService(rtCfg *config.Config, httpClient *http.Client, httpRetries *http
}

// Open opens a ticket which for mailgun means just sending an initial email
func (s *service) Open(session flows.Session, subject, body string, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, subject, body)
func (s *service) Open(session flows.Session, topic *flows.Topic, subject, body string, assignee *flows.User, logHTTP flows.HTTPLogCallback) (*flows.Ticket, error) {
ticket := flows.OpenTicket(s.ticketer, topic, subject, body, assignee)
contactDisplay := session.Contact().Format(session.Environment())

msg := &ExternalResource{
Expand Down
4 changes: 2 additions & 2 deletions services/tickets/zendesk/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func TestOpenAndForward(t *testing.T) {
logger := &flows.HTTPLogger{}

// try with connection failure
_, err = svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
_, err = svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.EqualError(t, err, "error pushing message to zendesk: unable to connect to server")

logger = &flows.HTTPLogger{}

ticket, err := svc.Open(session, "Need help", "Where are my cookies?", logger.Log)
ticket, err := svc.Open(session, nil, "Need help", "Where are my cookies?", nil, logger.Log)
assert.NoError(t, err)
assert.Equal(t, flows.TicketUUID("59d74b86-3e2f-4a93-aece-b05d2fdcde0c"), ticket.UUID())
assert.Equal(t, "Need help", ticket.Subject())
Expand Down

0 comments on commit 33ecd1b

Please sign in to comment.