ruby_whatsapp_sdk icon indicating copy to clipboard operation
ruby_whatsapp_sdk copied to clipboard

Read a message, and how to get the id and other data

Open ignacio-chiazzo opened this issue 1 year ago • 2 comments

Discussed in https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/discussions/92

Originally posted by AlkhabazHasan July 18, 2023 Grate gem and well documented and, it save times of works, but isn't messages_api.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M12345678910=") needs more explanation?

It is so easy to get the id for sent message:

message_sent = messages_api.send_text(sender_id: sender, recipient_number: phone_numbers, message: "Hey there! it's Whatsapp Ruby SDK")
message_id = message_sent.data.messages.first.id
puts message_id

But for messages_api.read_message I have to do it like this: params["entry"][0]["changes"][0]["value"]["messages"][0]["id"]

Is there something I didn't get? I think I may need some help!

ignacio-chiazzo avatar Jul 18 '23 19:07 ignacio-chiazzo

i did a big "parse" of possibilities in incoming message,

Basic i have created this architecture:

| WhatsAPP Hook -> Persist Incoming Message -> Send to Queue Job Incoming |

| Queue Job Incoming -> Loop Entries -> Loop Changes -> Process Envelope -> { Metadata, Contacts, Messages, Statuses } |

Metadata -> Extract destination phone Contacts -> Extract customers in conversation Messages -> Handle by type -> Persist the message Statuses -> Find Previous Message & Update the Status

When Message is Persisted & Handled the read_message is dispatched with id

It's is bit tedious but worked really well

renatovico avatar Aug 01 '23 08:08 renatovico

Thanks @renatovico. That's an interesting solution.

Please, submit any improvement/issue you have faced and I will take a look.

ignacio-chiazzo avatar Aug 03 '23 12:08 ignacio-chiazzo