Facebook Messenger bot not sending messages in order

后端 未结 11 2006
遥遥无期
遥遥无期 2021-01-01 21:00

I\'m playing around with building a simple Facebook Messenger chatbot and I\'m having trouble sending messages in sequence.

In the example above, it should

11条回答
  •  清酒与你
    2021-01-01 21:23

    Based on the recursive solution proposed by @user3884594, I kind of make it work using this (I removed the error handling in order to simplify):

    send_messages (["message 01", "message 02", "message 03"]);
    
    function send_messages (which, i = 0)
    {
        request({
            url: 'https://graph.facebook.com/v2.10/me/messages',
            qs: { access_token: FACEBOOK_ACCESS_TOKEN },
            method: 'POST',
            json: { recipient: { id: senderId }, message: { text: which [i] }
        }, (error, response, body) => 
        {
            // You need to put your error handling logic here
            if (i++ < which.length - 1)
                send_messages (which, i);
        });
    }
    

提交回复
热议问题