Skip to content

Commit

Permalink
Merge pull request #226 from weni-ai/fix/null-template
Browse files Browse the repository at this point in the history
Fix template field to save null when empty
  • Loading branch information
Robi9 authored Jan 24, 2025
2 parents 12778af + a31781a commit 3581258
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions WENI-CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.49.2
----------
* Fix template field to save null when empty

1.49.1
----------
* Send created_on on wenichats message forward
Expand Down
9 changes: 5 additions & 4 deletions core/models/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type Msg struct {
URNAuth null.String `db:"urn_auth" json:"urn_auth,omitempty"`
OrgID OrgID `db:"org_id" json:"org_id"`
TopupID TopupID `db:"topup_id" json:"-"`
Template string `db:"template" json:"template"`
Template null.String `db:"template" json:"template"`

SessionID SessionID `json:"session_id,omitempty"`
SessionStatus SessionStatus `json:"session_status,omitempty"`
Expand Down Expand Up @@ -179,7 +179,7 @@ func (m *Msg) TopupID() TopupID { return m.m.TopupID }
func (m *Msg) ContactID() ContactID { return m.m.ContactID }
func (m *Msg) ContactURNID() *URNID { return m.m.ContactURNID }
func (m *Msg) IsResend() bool { return m.m.IsResend }
func (m *Msg) Template() string { return m.m.Template }
func (m *Msg) Template() null.String { return m.m.Template }

func (m *Msg) SetTopup(topupID TopupID) { m.m.TopupID = topupID }

Expand Down Expand Up @@ -383,6 +383,7 @@ func newOutgoingMsg(rt *runtime.Runtime, org *Org, channel *Channel, contactID C
m.OrgID = org.ID()
m.TopupID = NilTopupID
m.CreatedOn = createdOn
m.Template = null.NullString

msg.SetChannel(channel)
msg.SetURN(out.URN())
Expand Down Expand Up @@ -436,7 +437,7 @@ func newOutgoingMsg(rt *runtime.Runtime, org *Org, channel *Channel, contactID C
}
if out.Templating() != nil {
metadata["templating"] = out.Templating()
m.Template = out.Templating().Template().Name
m.Template = null.String(out.Templating().Template().Name)
}
if out.Topic() != flows.NilMsgTopic {
metadata["topic"] = string(out.Topic())
Expand Down Expand Up @@ -661,7 +662,7 @@ func newOutgoingMsgWpp(rt *runtime.Runtime, org *Org, channel *Channel, contactI
}
if msgWpp.Templating() != nil {
metadata["templating"] = msgWpp.Templating()
m.Template = msgWpp.Templating().Template().Name
m.Template = null.String(msgWpp.Templating().Template().Name)
}

m.Metadata = null.NewMap(metadata)
Expand Down
4 changes: 2 additions & 2 deletions core/models/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestMarshalMsg(t *testing.T) {
"session_id": %d,
"session_status": "W",
"status": "Q",
"template": "",
"template": null,
"text": "Hi there",
"tps_cost": 2,
"urn": "tel:+250700000001?id=10000",
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestMarshalMsg(t *testing.T) {
"session_id": %d,
"session_status": "W",
"status": "Q",
"template": "",
"template": null,
"text": "Hi there",
"tps_cost": 1,
"urn": "tel:+250700000001?id=10000",
Expand Down

0 comments on commit 3581258

Please sign in to comment.