nyaruka/rapidpro

Attaching two images with no caption misses an image

Closed this issue · 5 comments

Describe the bug
If I attach two images from an MO in Telegram but do not include a caption, I only see one message with a single attachment arrive in RapidPro. While I suspect this is a courier issue, I know mailroom coordinates with courier on inbound attachment retrieval, so putting this here.

To Reproduce
Steps to reproduce the behavior:

  1. Add or use existing Telegram Channel
  2. Send an inbound message with two images but no caption
  3. Observe only one message in the contact history

Expected behavior
I would think this should be a single message with multiple attachments. We should also make sure it is consistent when a caption is provided (ie, single message with text and two image attachments)

Additional Context
In the courier log multiple message receive events:

  • The msg_uuid is the same for both events
  • The msg_id is 0 for the second image
INFO[0027] msg received  channel_uuid=xxx elapsed_ms=932.5495 msg_attachments="[https://api.telegram.org/file/botxxx/photos/file_68.jpg]" msg_id=192 msg_text= msg_urn="telegram:25028612" msg_uuid=31d21bee-8977-4f28-a1de-d6f02834924c url=/c/tg/xxx/receive
INFO[0028] msg received  channel_uuid=xxx elapsed_ms=579.494875 msg_attachments="[https://api.telegram.org/file/botxxx/photos/file_69.jpg]" msg_id=0 msg_text= msg_urn="telegram:25028612" msg_uuid=31d21bee-8977-4f28-a1de-d6f02834924c url=/c/tg/xxx/receive

Without activity, this issue will be closed in 14 days.

This issue was closed for inactivity.

We should look into this, assigning it so it stays active.

I looked into this and I found

Telegram sends 2 different requests for each attachments however there is a new field in that case we could probably use media_group_id that is the only value that is the same.

And when no caption is added the second attachment is ignore as the msg is considered a dupe by https://github.com/nyaruka/courier/blob/f76152aee193dac87b9d0c5a54fc048777d1e191/backends/rapidpro/msg.go#L431

We can probably hash the attachment in the fingerprint too so that message with empty text but different attachments are always accepted.

The solution is in 2 steps:

  1. first make sure we never ignore any messages with different attachments with empty text
  2. find a way to merge multiple requests into the existing message when both have the same media_group_id, so appending the attachments to the previous saved message
  1. is addressed by nyaruka/courier#607

With that we will no longer miss the second attachment