miki2826 / botly

Simple Facebook Messenger Bot API
http://developers.askhaley.com
MIT License
92 stars 34 forks source link

Reply with multiple messages? #46

Closed cesars closed 6 years ago

cesars commented 6 years ago

Is possible reply with multiple messages using Bolty? some code example?

aellanglet commented 6 years ago

send your next message on the first one callback like this :

botly.sendText({
    id: senderId,
    text: "Hello"
}, (err, data) => {

    botly.sendText({
      id: senderId,
      text: "How are you ?"
   })

  })

or you can do a timeout :)

cesars commented 6 years ago

well, if i need send ten messages? ten callbacks is very inefficient. Any idea?

aellanglet commented 6 years ago

I would do a loop at least if it's only messages ^^' Or like is said, set timeout to be sure that messages will be send one after one but 10 messages is a lot anyway :s The problem is that nodejs is asynchronous so if you are not setting next messages with timeout or on callbacks of first ones, it will send all your messages randomly when he can send it. At least in cb, he is waiting for facebook reception to send the other part :/

miki2826 commented 6 years ago

Hi @cesars, Botly is aimed to be a very simple SDK, following the FB API. Since the API does not provide an ability to send multiple messages, Botly doesn't provide it as well.

In order to send multiple messages when there are a lot of callbacks involved, I recommend using async to solve the problem.