PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to send multiple messages synchronously?

 July 12, 2022     facebook-messenger, messages, synchronization     No comments   

Issue

I'm using a for-loop to send a large text (larger than 320 chars) in multiple messages, but they land in no-particular order:

var arr = ['this', 'is', 'a', 'string'];
for (var i = 0; i < arr.length; i++) {
  sendTextMessage(sender, arr[i]);
}

Could land as a, is, this, string, or any other combination. How do I force them to land in order?


Solution

I assume that you're using the code example from facebook that provides your sendTextMessage method. This one acts asynchronously since it uses request module (https://www.npmjs.com/package/request).

If you want to do synchronous calls - means one after another - you've to use another module, e.g. https://github.com/dhruvbird/http-sync



Answered By - Juergen
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing