0
votes

is there a way to transmit the needed parameters with Koala::Facebook Gem (RoR) for sending messages in FB?

If i try

graph.put_connections(page_id, "messages", {recipient: {id: "1000XXXOUTXX"}, message: {text: "Hello"}})

i get

Koala::Facebook::ClientError: type: OAuthException, code: 100, message: (#100) The parameter recipient is required

Debug

POST: /16XX_OUT_XX814/messages params: {"recipient"=>{:id=>"1000XXXOUTXX"}, "message"=>{:text=>"Hello"}, "access_token"=>"XX_OUTXX"

According to facebook api description i have to send:

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": {
    "id": "USER_ID"
  },
  "message": {
    "text": "hello, world!"
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

If i understand the error reply from fb correct i´m not sending the parameters correctly with Koala.

Thanks for any help!

Links

Koala: http://www.rubydoc.info/github/arsduo/koala/Koala%2FFacebook%2FGraphAPIMethods:put_connections

FB-Api: https://developers.facebook.com/docs/messenger-platform/send-api-reference

1
You need to send JSON. - CBroe
Yeah, of course, but Koala normaly does the jason job for me :-), please see edit DEBUG output. - Alex
Normal Graph API requests don’t use JSON. So if you are using the same method here that you are using for normal API requests, then I doubt that it sends JSON here on its own. - CBroe
@Alex did you ever figure this out? I'm running into the same issue. Thanks! - Jack Collins

1 Answers

1
votes

The parameters that are hashes need to be strings as well. Here's an example of sending a message as a page:

page_graph = Koala::Facebook::API.new(page.access_token)
#Send new message
page_graph.put_connections(page.id, 'messages', recipient: {id: recipient_id}.to_json, message: {text: "Hello World"}.to_json)