From 2950cbbea198be52489607ed48631e336e2f443f Mon Sep 17 00:00:00 2001 From: Rafael Soares Date: Mon, 13 Jan 2025 11:42:18 -0300 Subject: [PATCH] add wenichats msg uuid that be sent to rmq exchange --- backends/rapidpro/backend_test.go | 2 +- billing/billing.go | 4 +++- billing/billing_test.go | 3 +++ handlers/facebookapp/facebookapp.go | 1 + sender.go | 4 ++++ server.go | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backends/rapidpro/backend_test.go b/backends/rapidpro/backend_test.go index 9d884a7fe..af40657ac 100644 --- a/backends/rapidpro/backend_test.go +++ b/backends/rapidpro/backend_test.go @@ -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) diff --git a/billing/billing.go b/billing/billing.go index 2e26b0cad..cd1981b0c 100644 --- a/billing/billing.go +++ b/billing/billing.go @@ -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, @@ -53,6 +54,7 @@ func NewMessage(contactURN, contactUUID, channelUUID, messageID, messageDate, di Attachments: attachments, QuickReplies: quickreplies, FromTicketer: fromTicketer, + ChatsUUID: chatsUUID, } } diff --git a/billing/billing_test.go b/billing/billing_test.go index 587af42dc..fd749c2cd 100644 --- a/billing/billing_test.go +++ b/billing/billing_test.go @@ -102,6 +102,7 @@ func TestBillingResilientClient(t *testing.T) { nil, nil, false, + "", ) billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName) @@ -170,6 +171,7 @@ func TestBillingResilientClientSendAsync(t *testing.T) { nil, nil, false, + "", ) billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName) @@ -239,6 +241,7 @@ func TestBillingResilientClientSendAsyncWithPanic(t *testing.T) { nil, nil, false, + "", ) billingClient, err := NewRMQBillingResilientClient(connURL, 3, 1000, billingTestExchangeName) diff --git a/handlers/facebookapp/facebookapp.go b/handlers/facebookapp/facebookapp.go index ff8eafe3e..aaf956546 100644 --- a/handlers/facebookapp/facebookapp.go +++ b/handlers/facebookapp/facebookapp.go @@ -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) } diff --git a/sender.go b/sender.go index 115875d73..15340a65e 100644 --- a/sender.go +++ b/sender.go @@ -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()), "", @@ -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) } diff --git a/server.go b/server.go index 4e1a4464c..b15a0ff71 100644 --- a/server.go +++ b/server.go @@ -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()