Skip to content

Commit

Permalink
add wenichats msg uuid that be sent to rmq exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Jan 13, 2025
1 parent d874137 commit 2950cbb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func (ts *BackendTestSuite) TestOutgoingQueue() {

var err error

msgStrJSON := `[{"org_id":1,"id":10000,"uuid":"00000000-0000-0000-0000-000000000000","direction":"O","status":"F","visibility":"V","high_priority":true,"urn":"","urn_auth":"","text":"test message","attachments":null,"external_id":"ext1","response_to_id":null,"response_to_external_id":"","metadata":"{\"ticketer_id\":1}","channel_id":10,"contact_id":100,"contact_urn_id":1000,"msg_count":1,"error_count":3,"channel_uuid":"dbc126ed-66bc-4e28-b67b-81dc3327c95d","contact_name":"","next_attempt":"2024-11-06T20:45:31.123208Z","created_on":"2024-11-06T20:30:14.898168Z","modified_on":"2024-11-06T20:30:31.122974Z","queued_on":"2024-11-06T20:30:14.898168Z","sent_on":null}]`
msgStrJSON := `[{"org_id":1,"id":10000,"uuid":"00000000-0000-0000-0000-000000000000","direction":"O","status":"F","visibility":"V","high_priority":true,"urn":"","urn_auth":"","text":"test message","attachments":null,"external_id":"ext1","response_to_id":null,"response_to_external_id":"","metadata":"{\"ticketer_id\":1, \"chats_msg_uuid\":\"adc67dda-314b-427a-b6c7-0cc8c2d89867\"}","channel_id":10,"contact_id":100,"contact_urn_id":1000,"msg_count":1,"error_count":3,"channel_uuid":"dbc126ed-66bc-4e28-b67b-81dc3327c95d","contact_name":"","next_attempt":"2024-11-06T20:45:31.123208Z","created_on":"2024-11-06T20:30:14.898168Z","modified_on":"2024-11-06T20:30:31.122974Z","queued_on":"2024-11-06T20:30:14.898168Z","sent_on":null}]`

err = queue.PushOntoQueue(r, msgQueueName, "dbc126ed-66bc-4e28-b67b-81dc3327c95d", 10, msgStrJSON, queue.HighPriority)
ts.NoError(err)
Expand Down
4 changes: 3 additions & 1 deletion billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ type Message struct {
Attachments []string `json:"attachments,omitempty"`
QuickReplies []string `json:"quick_replies,omitempty"`
FromTicketer bool `json:"from_ticketer"`
ChatsUUID string `json:"chats_uuid,omitempty"`
}

// Create a new message
func NewMessage(contactURN, contactUUID, channelUUID, messageID, messageDate, direction, channelType, text string, attachments, quickreplies []string, fromTicketer bool) Message {
func NewMessage(contactURN, contactUUID, channelUUID, messageID, messageDate, direction, channelType, text string, attachments, quickreplies []string, fromTicketer bool, chatsUUID string) Message {
return Message{
ContactURN: contactURN,
ContactUUID: contactUUID,
Expand All @@ -53,6 +54,7 @@ func NewMessage(contactURN, contactUUID, channelUUID, messageID, messageDate, di
Attachments: attachments,
QuickReplies: quickreplies,
FromTicketer: fromTicketer,
ChatsUUID: chatsUUID,
}
}

Expand Down
3 changes: 3 additions & 0 deletions billing/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestBillingResilientClient(t *testing.T) {
nil,
nil,
false,
"",
)

billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName)
Expand Down Expand Up @@ -170,6 +171,7 @@ func TestBillingResilientClientSendAsync(t *testing.T) {
nil,
nil,
false,
"",
)

billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName)
Expand Down Expand Up @@ -239,6 +241,7 @@ func TestBillingResilientClientSendAsyncWithPanic(t *testing.T) {
nil,
nil,
false,
"",
)

billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName)
Expand Down
1 change: 1 addition & 0 deletions handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func (h *handler) processCloudWhatsAppPayload(ctx context.Context, channel couri
nil,
nil,
false,
"",
)
h.Server().Billing().SendAsync(billingMsg, billing.RoutingKeyUpdate, nil, nil)
}
Expand Down
4 changes: 4 additions & 0 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ func (w *Sender) sendMessage(msg Msg) {
// if ticketer_type is eg: "wenichats" it is a message from ticketer sent by an agent, so must be sent to billing anyway
ticketerType, _ := jsonparser.GetString(msg.Metadata(), "ticketer_type")
fromTicketer := ticketerType != ""

chatsUUID, _ := jsonparser.GetString(msg.Metadata(), "chats_msg_uuid")

billingMsg := billing.NewMessage(
string(msg.URN().Identity()),
"",
Expand All @@ -311,6 +314,7 @@ func (w *Sender) sendMessage(msg Msg) {
msg.Attachments(),
msg.QuickReplies(),
fromTicketer,
chatsUUID,
)
w.foreman.server.Billing().SendAsync(billingMsg, billing.RoutingKeyCreate, nil, nil)
}
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func handleBilling(s *server, msg Msg) error {
msg.Attachments(),
msg.QuickReplies(),
false,
"",
)
billingMsg.ChannelType = string(msg.Channel().ChannelType())
billingMsg.Text = msg.Text()
Expand Down

0 comments on commit 2950cbb

Please sign in to comment.