diff --git a/backends/rapidpro/backend.go b/backends/rapidpro/backend.go index 5fe1b3c1d..7b22db0bb 100644 --- a/backends/rapidpro/backend.go +++ b/backends/rapidpro/backend.go @@ -60,8 +60,7 @@ func (b *backend) PopNextOutgoingMsg() (*courier.Msg, error) { } // TODO: what other attributes are needed here? - msg := courier.NewOutgoingMsg(channel, dbMsg.ID, courier.NilMsgUUID, dbMsg.URN, dbMsg.Text) - msg.ExternalID = dbMsg.ExternalID + msg := courier.NewOutgoingMsg(channel, dbMsg.URN, dbMsg.Text).WithID(dbMsg.ID).WithExternalID(dbMsg.ExternalID) msg.WorkerToken = token return msg, nil diff --git a/msg.go b/msg.go index e96346e88..b5c8da3cf 100644 --- a/msg.go +++ b/msg.go @@ -66,6 +66,7 @@ func NewMsgUUID() MsgUUID { // NewIncomingMsg creates a new message from the given params func NewIncomingMsg(channel Channel, urn URN, text string) *Msg { m := &Msg{} + m.ID = NilMsgID m.UUID = NewMsgUUID() m.Channel = channel m.Text = text @@ -78,10 +79,10 @@ func NewIncomingMsg(channel Channel, urn URN, text string) *Msg { } // NewOutgoingMsg creates a new message from the given params -func NewOutgoingMsg(channel Channel, id MsgID, uuid MsgUUID, urn URN, text string) *Msg { +func NewOutgoingMsg(channel Channel, urn URN, text string) *Msg { m := &Msg{} - m.ID = id - m.UUID = uuid + m.ID = NilMsgID + m.UUID = NilMsgUUID m.Channel = channel m.Text = text m.URN = urn @@ -120,6 +121,12 @@ func (m *Msg) WithReceivedOn(date time.Time) *Msg { m.ReceivedOn = &date; return // WithExternalID can be used to set the external id on a msg in a chained call func (m *Msg) WithExternalID(id string) *Msg { m.ExternalID = id; return m } +// WithID can be used to set the id on a msg in a chained call +func (m *Msg) WithID(id MsgID) *Msg { m.ID = id; return m } + +// WithUUID can be used to set the id on a msg in a chained call +func (m *Msg) WithUUID(uuid MsgUUID) *Msg { m.UUID = uuid; return m } + // AddAttachment can be used to append to the media urls for a message func (m *Msg) AddAttachment(url string) *Msg { m.Attachments = append(m.Attachments, url); return m }