ignacio-chiazzo/ruby_whatsapp_sdk

how to get Access Token

Closed this issue · 23 comments

Hi!
Could you tell me how to get a Access Token?
Do you have some step by step for that?

config.access_token = ACCESS_TOKEN

Thank you!

Hey 👋 .

You should create a Meta app and use grab the token from the Facebook Manager.

See the Facebook Guide

I will add instructions to the README.

Hey 👋 .

You should create a Meta app and use grab the token from the Facebook Manager.

See the Facebook Guide

I will add instructions to the README.

thank you so much my dear friend!
let's check it out!

Can I offer this feature in the same API for different clients? or not?

Which feature? If you mean using different phone numbers as receivers then yes, you can do that.

Which feature? If you mean using different phone numbers as receivers then yes, you can do that.

yep! thank you my friend! let's try it!

how can i get this SENDER_ID?

message_sent = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
message: "Hey there! it's Whatsapp Ruby SDK")

SENDER_ID is one of the phone numbers associated with the account. You can get the list of phone numbers registered using the PhoneNumbers API or just doing:

BUSINESS_ID = <1234> # The business ID you created, check the Meta dasbhoard.
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
phone_numbers_api.registered_numbers(BUSINESS_ID)

Thanks for all the questions! I'm preparing a FAQ section.

@ademir10 I updated the README file explaining how to get the ACCESS_TOKEN, the SENDER_ID, BUSINESS_ID and other parameters.

See Pull Request #38

@ademir10 I updated the README file explaining how to get the ACCESS_TOKEN, the SENDER_ID, BUSINESS_ID and other parameters.

See Pull Request #38

lol it sounds good! thank you my dear friend!

hello

@ademir10 I updated the README file explaining how to get the ACCESS_TOKEN, the SENDER_ID, BUSINESS_ID and other parameters.

See Pull Request #38

hello my friend!
after to find a time here and back with our whatsapp integration, i'm facing with this error message when i try to send a message:

:multipart is not registered on Faraday::Request

this is my code inside the action:

def send_whatsapp_message

  require "whatsapp_sdk"
  #variables
  access_token = "mytokenhere"
  business_id = "my_business_id"
  sender_id = "the_sender_id"
  recipient_number = "the_number_here"

  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: "Message sent! thank you.")
  sweetalert_success('Mensagem enviada!', 'Sucesso!', persistent: 'Ok')
  redirect_to root_path and return
end

any suggestion? thanks!

after to update my gems and install your gem i started to receive this warning message too:
WARNING: Zeitwerk defines the constant Version after the file

/Users/ademir/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/whatsapp_sdk-0.4.0/lib/version.rb

To prevent that, please configure the loader to ignore it:

loader.ignore("#{__dir__}/version.rb")

Otherwise, there is a flag to silence this warning:

Zeitwerk::Loader.for_gem(warn_on_extra_files: false)

after to update my gems and install your gem i started to receive this warning message too: WARNING: Zeitwerk defines the constant Version after the file

/Users/ademir/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/whatsapp_sdk-0.4.0/lib/version.rb

To prevent that, please configure the loader to ignore it:

loader.ignore("#{__dir__}/version.rb")

Otherwise, there is a flag to silence this warning:

Zeitwerk::Loader.for_gem(warn_on_extra_files: false)

a

After to add this lines i fixed the faraday error:
require 'faraday'
require 'faraday/multipart'

  but i don't receive the message , how to check the log message sent?

after to update my gems and install your gem i started to receive this warning message too: WARNING: Zeitwerk defines the constant Version after the file

/Users/ademir/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/whatsapp_sdk-0.4.0/lib/version.rb

To prevent that, please configure the loader to ignore it:

loader.ignore("#{__dir__}/version.rb")

Otherwise, there is a flag to silence this warning:

Zeitwerk::Loader.for_gem(warn_on_extra_files: false)

a

After to add this lines i fixed the faraday error: require 'faraday' require 'faraday/multipart'

  but i don't receive the message , how to check the log message sent?

adding this guy: print_message_sent(message_sent)
i can see this log message in my terminal:
Started GET "/send_whatsapp_message" for 127.0.0.1 at 2022-09-12 17:24:55 -0300
Processing by ConfigsController#send_whatsapp_message as HTML
Message sent to: 5511970395230
Redirected to http://localhost:3000/
Completed 302 Found in 682ms (ActiveRecord: 0.0ms | Allocations: 1833)

after to update my gems and install your gem i started to receive this warning message too: WARNING: Zeitwerk defines the constant Version after the file

/Users/ademir/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/whatsapp_sdk-0.4.0/lib/version.rb

To prevent that, please configure the loader to ignore it:

loader.ignore("#{__dir__}/version.rb")

Otherwise, there is a flag to silence this warning:

Zeitwerk::Loader.for_gem(warn_on_extra_files: false)

a

After to add this lines i fixed the faraday error: require 'faraday' require 'faraday/multipart'

  but i don't receive the message , how to check the log message sent?

adding this guy: print_message_sent(message_sent) i can see this log message in my terminal: Started GET "/send_whatsapp_message" for 127.0.0.1 at 2022-09-12 17:24:55 -0300 Processing by ConfigsController#send_whatsapp_message as HTML Message sent to: 5511970395230 Redirected to http://localhost:3000/ Completed 302 Found in 682ms (ActiveRecord: 0.0ms | Allocations: 1833)

but the messages not arriving to this whatsapp above..

Do you have a link to the repository or a code snippet I can see?

Also, see the troubleshooting section. Try the hints there, if it doesn't work lmk.

Do you have a link to the repository or a code snippet I can see?

Also, see the troubleshooting section. Try the hints there, if it doesn't work lmk.

Let me show my code:
im my gem file:
gem 'whatsapp_sdk'

in my controller:
def send_whatsapp_message
require 'faraday'
require 'faraday/multipart'
require 'whatsapp_sdk'

#variables
access_token = "EAAVRvYO3LQMBAHlO359cnZBb6u2ZAK0R1ECvcEZBQtedPpwqY7p1U0jNoKJ4v3nwrZAUc1AQ6wqmnQzrLbIUDowvwBq1uaBZBaz9FDY0kSHYbZAZAzNs3nKKMmhZAyaFYmV3eyWEtyrw60rvs8SWBUHJedNY1KCf5VZAzDNVAPbYFZBbzl9IYrCuHmBkEAXJnvUaw8ZC9ojKAq1ggZDZdsf"
business_id = "1012924296380714"
sender_id = "1081290820631154"
recipient_number = "5511970395230"

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: "Message sent! thank you.")
print_message_sent(message_sent)

sweetalert_success('Mensagem enviada!', 'Sucesso!', persistent: 'Ok')
redirect_to root_path and return
end

Do you have a link to the repository or a code snippet I can see?

Also, see the troubleshooting section. Try the hints there, if it doesn't work lmk.

i checked my token and i have all permissions.
i changed the token sent for you in my code above.

What does the print_message_sent(message_sent) print? Does it return success?

I tried with the token you shared and it's expired. My DMS are open if you want to chat https://twitter.com/IgnacioChiazzo.

What does the print_message_sent(message_sent) print? Does it return success?

I tried with the token you shared and it's expired. My DMS are open if you want to chat https://twitter.com/IgnacioChiazzo.

okay! let's chat, thank you my friend!

about your question above:
this is my token:
EAAVRvYO3LQMBANyzA38RmXZA83VGGwYblwZASqrEU50dZBki0vqEsGSlglL2nuyD9XVbX0qxbSQURnzW5jkwvfrz8J0P3XW3CSM1R03n81ZBjd1dLHsYIIPdhF8NjMy8hnwYDzTFLSabpkWlD7LQ7VWQAx5k64XgNv02DFLt2EhgVhib09SmEj6ZBSKZBknasHjaTUcgX0iQZDZD

yes i receive this message:
Message sent to: 5511970395230

yes i receive this message:
Message sent to: 5511970395230

What's the API response? Is the phone set in the Facebook dashboard?

yes i receive this message:
Message sent to: 5511970395230

What's the API response? Is the phone set in the Facebook dashboard?

here:
def print_message_sent(message_response)
puts 'calling the action'
if message_response.ok?
puts "Message sent to: #{message_response.data.contacts.first.input}"
else
puts "Error: #{message_response.error&.to_s}"
end
end

i receive this:
puts "Message sent to: #{message_response.data.contacts.first.input}"
Message sent to: 5511970395230

message_response

when i inspect :
puts "Message sent to: #{message_response.data.inspect

Message sent to: #<WhatsappSdk::Api::Responses::MessageDataResponse:0x00007fd1851ae448 @contacts=[#<WhatsappSdk::Resource::ContactResponse:0x00007fd1851ae290 @input="5511970395230", @wa_id="5511970395230">], @messages=[#<WhatsappSdk::Resource::Message:0x00007fd1851ae0d8 @id="wamid.HBgNNTUxMTk3MDM5NTIzMBUCABEYEjIyQTJERDJDNzdCRUFCMUNGNAA=">], @raw_data_response={"messaging_product"=>"whatsapp", "contacts"=>[{"input"=>"5511970395230", "wa_id"=>"5511970395230"}], "messages"=>[{"id"=>"wamid.HBgNNTUxMTk3MDM5NTIzMBUCABEYEjIyQTJERDJDNzdCRUFCMUNGNAA="}]}>