ignacio-chiazzo / ruby_whatsapp_sdk

A lightweight, efficient Ruby gem for interacting with Whatsapp Cloud API.
https://ignacio-chiazzo.github.io/ruby_whatsapp_sdk/
MIT License
156 stars 33 forks source link

How to send messages Production Environment? #111

Closed ademir10 closed 3 months ago

ademir10 commented 7 months ago

Describe the bug After to finish all configuration and added the new phone number, when i try to send a message using the Gem, I receive the message "message sent" but the recipient dont receive any message.

To Reproduce Steps to reproduce the behavior: the Code below: def send_whatsapp_message @config = Config.first require 'whatsapp_sdk'

variables

access_token = @config.access_token_whats business_id = @config.business_id_whats sender_id = @config.sender_id_whats recipient_number = params[:numero_whatsapp]

client = WhatsappSdk::Api::Client.new(access_token) # replace this with a valid access token messages_api = WhatsappSdk::Api::Messages.new(client)

message_sent = messages_api.send_text(sender_id: sender_id.to_i, recipient_number: recipient_number.to_i, message: params[:mensagem].to_s) print_message_sent(message_sent) redirect_back(fallback_location: root_path) end

def print_message_sent(message_response) if message_response.ok? sweetalert_success("Mensagem enviada com sucesso para: #{message_response.data.contacts.first.input}", 'Sucesso!', persistent: 'Ok') puts "Message sent to: #{message_response.data.inspect}" else sweetalert_success("Ocorreu um erro: #{message_response.error&.to_s}", 'Erro:', persistent: 'Ok') end end

THIS IS MY RESPONSE: Message sent to: #<WhatsappSdk::Api::Responses::MessageDataResponse:0x000000010667d728 @contacts=[#<WhatsappSdk::Resource::ContactResponse:0x000000010667d570 @input="5511991078572", @wa_id="5511991078572">], @messages=[#<WhatsappSdk::Resource::Message:0x000000010667d368 @id="wamid.HBgNNTUxMTk5MTA3ODU3MhUCABEYEjBFQkI2OEYyNTdBMTBDRUY1NwA=">], @raw_data_response={"messaging_product"=>"whatsapp", "contacts"=>[{"input"=>"5511991078572", "wa_id"=>"5511991078572"}], "messages"=>[{"id"=>"wamid.HBgNNTUxMTk5MTA3ODU3MhUCABEYEjBFQkI2OEYyNTdBMTBDRUY1NwA="}]}>

Expected behavior The recipient receive the message.

If you look to my configs at images attached you can see that everything is configured, (I guess) There is something else more to do? thanks!

Additional context Add any other context about the problem here

Captura de Tela 2023-11-28 às 16 36 53 Captura de Tela 2023-11-28 às 16 37 18 Captura de Tela 2023-11-28 às 16 38 39

.

ignacio-chiazzo commented 7 months ago

Hey! I have seen this before, check the troubleshooting section.

If you click on Enviar mensagem, do you receive it ?

ademir10 commented 7 months ago

Hi! thanks for your help. Yes! when i try to send using the Meta API everything is working as expected, but when i try to do the same using the Gem, ia receive the message sent, but i dont receive the message in my device.

ademir10 commented 7 months ago

Only after to do it started to receive the messages: "Try also replying a message to the number you are registered on your Whatsapp."

Do you know if i need to do something else more?

what is this?: phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new

ademir10 commented 7 months ago

What about this step 6? I don't did it...

has something to do with it to make the recipient receive the message?

Captura de Tela 2023-11-28 às 17 30 03
ademir10 commented 7 months ago

Finally i found the problem @ignacio-chiazzo ! Just to help more people with the same error:

1 - If you try to send a text message directly without to use a message template created and approved in your Meta control panel, you can't start a chat with other people, but if you receive a message before, it's possible to send a message.

ignacio-chiazzo commented 7 months ago

oh great find, could you add that to the troubleshooting section in the readme? thanks!

ignacio-chiazzo commented 3 months ago

I have added your suggestion to the README. Thank you.