Facebook-chat-api: Facebook changed sendMessage endpoint

Created on 12 Aug 2016  ·  35Comments  ·  Source: Schmavery/facebook-chat-api

I have this problem
@Schmavery :'(
Code:

book-chat-api/node_modules/bluebird/js/main/method.js:31:24)
ERR! ERROR in sendMessage -->      at /root/olaf-bot/node_modules/facebook-chat-api/utils.js:518:24
ERR! ERROR in sendMessage -->      at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules
/bluebird/js/main/util.js:26:23)
ERR! ERROR in sendMessage -->      at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/faceboo
k-chat-api/node_modules/bluebird/js/main/promise.js:507:31)
ERR! ERROR in sendMessage -->      at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-ap
i/node_modules/bluebird/js/main/promise.js:581:18)
ERR! ERROR in sendMessage -->      at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api
/node_modules/bluebird/js/main/promise.js:697:14)
ERR! ERROR in sendMessage -->      at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_
modules/bluebird/js/main/async.js:123:16)
ERR! ERROR in sendMessage -->      at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node
_modules/bluebird/js/main/async.js:133:10)
ERR! ERROR in sendMessage -->      at Immediate.Async.drainQueues [as _onImmediate] (/root/olaf-bot/node_mod
ules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! ERROR in sendMessage -->      at tryOnImmediate (timers.js:534:15)
ERR! ERROR in sendMessage -->      at processImmediate [as _immediateCallback] (timers.js:514:5)
ERR! ERROR in sendMessage -->   [Error: parseAndCheckLogin got status code: 404. Bailing out of trying to pa
rse response.]
info Got answer in  395
info Got answer in  2693
info Got answer in  4620
info Got answer in  4260
info Got answer in  4830
info Got answer in  297
info Got answer in  1707
info Got answer in  6831

But passing investigate the 404 error is that the url https://www.facebook.com/ajax/mercury/send_messages.php not exist in facebook, but when you send a message from my facebook capture the head and threw me this url for post https://www.messenger.com/messaging/send/?dpr=1 , which is alive :+1:

Header.!

https://www.messenger.com/messaging/send/?dpr=1

POST /messaging/send/?dpr=1 HTTP/1.1
Host: www.messenger.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
X-MSGR-Region: ATN
Referer: https://www.messenger.com/t/Chicotecno
Content-Length: 682
Cookie: datr=WQauVzreL_2MDtFGjOPLe3Eg; lu=gg4lZuQCnQqDpWhIt_ybgt9Q; sb=_o4tV1yC8SdDtl8hpXkQpfum; c_user=100012648525019; xs=205%3AoqQ814KFbdAAMA%3A2%3A1467729876%3A-1; csm=2; s=Aa4qf8e83-Whph-7.BXe8fU; p=-2; presence=EDvF3EtimeF1471024231EuserFA21B12648525019A2EstateFDutF1471024231520CEchFDp_5f1B12648525019F10CC; wd=1366x565
Connection: keep-alive
client=mercury&action_type=ma-type%3Auser-generated-message&body=hola&ephemeral_ttl_mode=0&has_attachment=false&message_id=6169927513991285568&offline_threading_id=6169927513991285568&other_user_fbid=100007502617855&source=source%3Amessenger%3Aweb&specific_to_list[0]=fbid%3A100007502617855&specific_to_list[1]=fbid%3A100012648525019&timestamp=1471025351045&__user=100012648525019&__a=1&__dyn=7AzkXh8OAcjxd2u6W85k2m3miWF3oyfJLFwgoqwWhE98nwgUaqG2yaBxebkwy3eF8vDKuEjKewExW14DwPxSFEW2O7EOEixu1jyoCcxG48hxGbxO7VUgCLxZ3E&__req=1u&__be=-1&__pc=PHASED%3Amessengerdotcom_pkg&fb_dtsg=AQG7QMvuaB3J%3AAQGyMl_0ns3C&ttstamp=265817155817711811797665174586581711217710895481101155167&__rev=2502705

facebook change

Most helpful comment

I can confirm that it works by changing to https://www.messenger.com/messaging/send/ and removing message_batch[0]. @Schmavery

No need for __be

All 35 comments

Wow, maybe they're retiring this endpoint. Is anyone else experiencing this yet?
Does it work if you simply modify
https://github.com/Schmavery/facebook-chat-api/blob/master/src/sendMessage.js#L119
to hit "https://www.messenger.com/messaging/send/" instead?

@Schmavery well, it happened in the night , I think I still have not thought of such an error , if I do not change that and tried , so here we are now having it works.

@Schmavery Well not me worked apparently changed parameters

@Schmavery generate a curl tests which gave me a good result messages are sent , but not how to modify your code :-1:
Curl:
curl 'https://www.messenger.com/messaging/send/?dpr=1' -H 'Host: www.messenger.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-MSGR-Region: ATN' -H 'Referer: https://www.messenger.com/t/Chicotecno' -H 'Cookie: datr=WQauVzreL_2MDtFGjOPLe3Eg; lu=ggGyxlO1iN3ywCk9giqu38FQ; sb=_o4tV1yC8SdDtl8hpXkQpfum; c_user=100012648525019; xs=205%3AoqQ814KFbdAAMA%3A2%3A1467729876%3A-1; csm=2; s=Aa4qf8e83-Whph-7.BXe8fU; p=-2; presence=EDvF3EtimeF1471035435EuserFA21B12648525019A2EstateFDutF1471035435098CEchFDp_5f1B12648525019F13CC; wd=1366x565' -H 'Connection: keep-alive' --data 'client=mercury&action_type=ma-type%3Auser-generated-message&body=hola&ephemeral_ttl_mode=0&has_attachment=false&message_id=6169974268040363954&offline_threading_id=6169974268040363954&other_user_fbid=100007502617855&source=source%3Amessenger%3Aweb&specific_to_list[0]=fbid%3A100007502617855&specific_to_list[1]=fbid%3A100012648525019&timestamp=1471036498079&__user=100012648525019&__a=1&__dyn=7AzkXh8OAcjxd2u6W85k2m3miWF3oyfJLFwgoqwWhE98nwgUaqG2yaBxebkwy3eF8vDKuEjKewExW14DwPxSFEW2O7EOEixu1jyoCcxG48hxGbxO7VUgCLxZ3E&__req=1h&__be=-1&__pc=PHASED%3Amessengerdotcom_pkg&fb_dtsg=AQFJUss0qUNJ%3AAQHZZDNlatBL&ttstamp=26581707485115115481138578745865817290906878108971166676&__rev=2502705'
Response :
for (;;);{"__ar":1,"payload":{"actions":[{"client_thread_id":null,"message_id":"mid.1471036757895:ca51ac54bb638c8f61","client_message_id":"6169974268040363954","status":1,"timestamp":1471036757896,"timestamp_absolute":"Hoy","timestamp_relative":"18:19","timestamp_datetime":"18:19","timestamp_time_passed":0,"attachments":[],"thread_id":null,"thread_fbid":null,"other_user_fbid":"100007502617855","action_type":"ma-type:send-message"}],"payload_source":"server_send_message"},"bootloadable":{},"ixData":{},"lid":"6318054764639433166"}

messages are sent but would have to set the parameters !

@Schmavery not result :'(
parameters !
'client' : 'mercury',
'action_type' : 'ma-type:user-generated-message',
'body' : msg.body ? msg.body.toString() : "",
'ephemeral_ttl_mode' : '0',
'has_attachment' : !!(msg.attachment || msg.url || msg.sticker),
'message_id' : messageAndOTID,
'offline_threading_id' : messageAndOTID,
'source' : 'source:chat:web',
'timestamp' : Date.now(),

Still works for me.

@Schmavery @Schmavery
ok , facebook move is proving that it works now if it was a problem yesterday , I beg leave this post because it may change the way to send messages

Mine has also stopped functioning.
screen shot 2016-08-13 at 6 39 46 pm

@Seledity , no problem now, but I investigate that new url

Mine is now working again after making no changes

My friend detected this trouble too, as I said in older issues, facebook applying "updates" faster on some countries, so nobody got update at same time as others

@GAMELASTER you're definitely right that they're staggering the release of updates as usual. The problem is that this makes it harder for @bsansouci and I to test/fix these on our own as our accounts frequently don't have the updates right away. We rely on the community to help in these cases :smile:

@Seledity @ErmanSayin @Schmavery @GAMELASTER again have this problem ,you have it

Yes, I'm also having the problem right now. @Theblood

Problem for me to :(

Has anyone tried modifying https://github.com/Schmavery/facebook-chat-api/blob/master/src/sendMessage.js#L119
to hit "https://www.facebook.com/messaging/send/?dpr=1" instead? @Theblood sorry, I can't understand your response.
It looks like they may have potentially removed the "message_batch[0]" prefix from most of the fields that are sent. Other than that, they look very similar. If changing the URL doesn't work on it's own, someone could try removing that string from all fields in the form, just to see if it works. Once we know what works, we can figure out what the nicest fix is to keep it compatible with all versions.
Edit: looks like __be: -1 was also added?

I can confirm that it works by changing to https://www.messenger.com/messaging/send/ and removing message_batch[0]. @Schmavery

No need for __be

@kjellberg you 've tried with these parameters?

'client' : 'mercury', 'action_type' : 'ma-type:user-generated-message', 'body' : msg.body ? msg.body.toString() : "", 'ephemeral_ttl_mode' : '0', 'has_attachment' : !!(msg.attachment || msg.url || msg.sticker), 'message_id' : messageAndOTID, 'offline_threading_id' : messageAndOTID, 'source' : 'source:chat:web', 'timestamp' : Date.now(),

info Got answer in  1247
info Got answer in  529
{ client: 'mercury',
  action_type: 'ma-type:user-generated-message',
  author: 'fbid:100010359372619',
  timestamp: 1471400345995,
  timestamp_absolute: 'Today',
  timestamp_relative: '4:19',
  timestamp_time_passed: '0',
  is_unread: false,
  is_cleared: false,
  is_forward: false,
  is_filtered_content: false,
  is_filtered_content_bh: false,
  is_filtered_content_account: false,
  is_filtered_content_quasar: false,
  is_filtered_content_invalid_app: false,
  is_spoof_warning: false,
  source: 'source:chat:web',
  'source_tags[0]': 'source:chat',
  body: 'TEST BOT: aaf',
  html_body: false,
  ui_push_phase: 'V3',
  status: '0',
  offline_threading_id: '6171500356804827443',
  message_id: '6171500356804827443',
  threading_id: '<1471400345996:[email protected]>',
  'ephemeral_ttl_mode:': '0',
  manual_retry_cnt: '0',
  has_attachment: false,
  signatureID: '7ed6ba49',
  'specific_to_list[0]': 'fbid:100000121491279',
  'specific_to_list[1]': 'fbid:100010359372619',
  'other_user_fbid': '100000121491279' }
info Got answer in  540
info Got answer in  394

screen shot 2016-08-17 at 04 20 44

Can someone update the repo with a solution that works for all versions?

I have this issue as well.

It still works for boths versions by sending the form both with and without message_batch[0] like this:

form['message_batch[0][specific_to_list][0]'] = "fbid:" + threadID;  // old version
form['message_batch[0][specific_to_list][1]'] = "fbid:" + ctx.userID;  // old version
form['message_batch[0][other_user_fbid]'] = threadID;  // old version
form['specific_to_list[0]'] = "fbid:" + threadID;  // new version
form['specific_to_list[1]'] = "fbid:" + ctx.userID;  // new version
form['other_user_fbid'] = threadID; // new version

But then we'll got a lot of duplicate code. Maybe someone can make a function for building the form?

this issue fixed?

@kjellberg Not result , I can see your code

@kjellberg awesome, thanks for trying that. Can you submit a pull request to this repo with the change you mentioned above? I'm tempted to just do the new version because I think most people will be on that now.
Edit: There's https://www.messenger.com/messaging/send/ and https://www.facebook.com/messaging/send/, not sure which one we should be using. Is there any chance you can test sending a file or image with the new endpoint?

@Schmavery since post your problem to state this endpoint , there should be no problem

@Schmavery PR sent 👍

hi guys,

Is this issue fixed?

Hi guys, sorry for a dumb question. The fix #316 works fine. Thanks a lot.
But for now it works only locally.
How i deploy these changes to heroku?

I just merged @Mini-Geek's PR. Thanks to everyone who helped track down this issue. I will push a new version to npm asap.

@Schmavery
awesome , this app has been running very well . Thank you very much guys. :+1:

How can we update our programs to reflect these changes?

@trev4ev follow these steps :+1:

 cd node_modules
 rm -rf facebook-chat-api
​ git clone https://github.com/Schmavery/facebook-chat-api.git
 cd ​facebook-chat-api
npm install

@Theblood thanks!
Should this also work if I am hosting my chat bot on a server? Has the npm been updated or will I have to wait?

This has now been pushed to npm as version 1.2.0

Thanks guys for the quick turn around really appreciate it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomekb530 picture tomekb530  ·  6Comments

ezaca picture ezaca  ·  3Comments

nripendra picture nripendra  ·  8Comments

KuoyuanY picture KuoyuanY  ·  7Comments

ravkr picture ravkr  ·  7Comments