@@ -221,6 +221,7 @@ def receive_message(self, message):
221221 def test_receive_message_01 (self ):
222222 message = self .receive_message (self .message_01 )
223223 self .assertFalse (message .author_id )
224+ self .assertFalse (message .parent_id )
224225
225226 def test_receive_message_02 (self ):
226227 # Check that the partner is assigned automatically
@@ -229,6 +230,62 @@ def test_receive_message_02(self):
229230 )
230231 message = self .receive_message (self .message_01 )
231232 self .assertEqual (message .author_id , partner )
233+ self .assertFalse (message .parent_id )
234+
235+ def test_receive_related_message (self ):
236+ """
237+ Send outgoing message, and then receive a reply message
238+ with reference to the original.
239+ """
240+ # Send outgoing
241+ partner = self .env ["res.partner" ].create (
242+ {"name" : "DEMO" , "phone" : "+34699999999" }
243+ )
244+ ctx = {
245+ "default_res_model" : partner ._name ,
246+ "default_res_id" : partner .id ,
247+ "default_number_field_name" : "mobile" ,
248+ "default_composition_mode" : "comment" ,
249+ "default_gateway_id" : self .gateway .id ,
250+ }
251+ self .gateway .whatsapp_account_id = "123456"
252+ form_composer = Form (self .env ["whatsapp.composer" ].with_context (** ctx ))
253+ form_composer .body = "Body test"
254+ form_composer .template_id = self .ws_template
255+ composer = form_composer .save ()
256+ channel = partner ._whatsapp_get_channel (
257+ composer .number_field_name , composer .gateway_id
258+ )
259+ message_domain = [
260+ ("gateway_type" , "=" , "whatsapp" ),
261+ ("model" , "=" , channel ._name ),
262+ ("res_id" , "=" , channel .id ),
263+ ]
264+ ID_WHATSAPP = "wamid.TEST_UNIQUE_ID_123"
265+ with (
266+ RecordCapturer (self .env ["mail.message" ], message_domain ) as capture ,
267+ patch ("requests.post" ) as post_mock ,
268+ ):
269+ response_mock = MagicMock ()
270+ response_mock .status_code = 200
271+ # Mock the response of whatsapp to include an assigned ID
272+ response_mock .json .return_value = {"messages" : [{"id" : ID_WHATSAPP }]}
273+ post_mock .return_value = response_mock
274+ composer .action_send_whatsapp ()
275+ message = capture .records
276+ # Check that the sent message notification contains the received Whatsapp ID
277+ self .assertTrue (
278+ message .notification_ids .filtered (
279+ lambda msg : msg .gateway_message_id == ID_WHATSAPP
280+ )
281+ )
282+ # Receive message 01 with related id set.
283+ reply_message = self .message_01
284+ reply_message ["entry" ][0 ]["changes" ][0 ]["value" ]["messages" ][0 ]["context" ] = {
285+ "id" : ID_WHATSAPP
286+ }
287+ received_reply = self .receive_message (reply_message )
288+ self .assertEqual (message .id , received_reply .parent_id .id )
232289
233290 def test_receive_message_03 (self ):
234291 class GetImageResponse :
0 commit comments