Sending messages with delay











up vote
0
down vote

favorite












I'm implementing a Facebook Messenger Chatbot, and in one of the conversation flows, the bot is supposed to send 6 messages, one after the other.



I'd like those messages to be delayed by 1 second, and between them, display a sender action, to make the conversation feel natural (vs. dumping 6 messages all at once, which forces the user to scroll up to read them all).



I tried 2 different webhook implementations, but neither of them work. One was in Python/Flask: between each message, I've put time.sleep(delay), but it didn't work. The other was in Javascript/NodeJS: between each message, I've put setTimeout(function() {sendMessage(recipient_id);}, delay), but it also didn't work. Both versions work perfectly without the delay.



Can anyone help?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm implementing a Facebook Messenger Chatbot, and in one of the conversation flows, the bot is supposed to send 6 messages, one after the other.



    I'd like those messages to be delayed by 1 second, and between them, display a sender action, to make the conversation feel natural (vs. dumping 6 messages all at once, which forces the user to scroll up to read them all).



    I tried 2 different webhook implementations, but neither of them work. One was in Python/Flask: between each message, I've put time.sleep(delay), but it didn't work. The other was in Javascript/NodeJS: between each message, I've put setTimeout(function() {sendMessage(recipient_id);}, delay), but it also didn't work. Both versions work perfectly without the delay.



    Can anyone help?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm implementing a Facebook Messenger Chatbot, and in one of the conversation flows, the bot is supposed to send 6 messages, one after the other.



      I'd like those messages to be delayed by 1 second, and between them, display a sender action, to make the conversation feel natural (vs. dumping 6 messages all at once, which forces the user to scroll up to read them all).



      I tried 2 different webhook implementations, but neither of them work. One was in Python/Flask: between each message, I've put time.sleep(delay), but it didn't work. The other was in Javascript/NodeJS: between each message, I've put setTimeout(function() {sendMessage(recipient_id);}, delay), but it also didn't work. Both versions work perfectly without the delay.



      Can anyone help?










      share|improve this question













      I'm implementing a Facebook Messenger Chatbot, and in one of the conversation flows, the bot is supposed to send 6 messages, one after the other.



      I'd like those messages to be delayed by 1 second, and between them, display a sender action, to make the conversation feel natural (vs. dumping 6 messages all at once, which forces the user to scroll up to read them all).



      I tried 2 different webhook implementations, but neither of them work. One was in Python/Flask: between each message, I've put time.sleep(delay), but it didn't work. The other was in Javascript/NodeJS: between each message, I've put setTimeout(function() {sendMessage(recipient_id);}, delay), but it also didn't work. Both versions work perfectly without the delay.



      Can anyone help?







      chatbot facebook-messenger facebook-messenger-bot facebook-chatbot






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 18:02









      Carlos Souza

      734




      734
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can use settimeout for such scenarios. But for showing sender_action let's say if you want to show text like typing... from the bot inside messenger then facebook provides functionalities in its messenger API to include sender actions with different tags. Here is how I am doing it.



          sender_action: 'typing...',
          messaging_type: 'MESSAGE_TAG',
          tag: 'NON_PROMOTIONAL_SUBSCRIPTION',


          Please look into the following link for more information.
          https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions






          share|improve this answer




























            up vote
            0
            down vote













            It'd be better if you provide more code when asking the question. I have the suspicion that you actually do this:



            setTimeout(function() {sendMessage(recipient_id);}, delay)
            setTimeout(function() {sendMessage(recipient_id);}, delay)
            setTimeout(function() {sendMessage(recipient_id);}, delay)
            setTimeout(function() {sendMessage(recipient_id);}, delay)
            setTimeout(function() {sendMessage(recipient_id);}, delay)
            setTimeout(function() {sendMessage(recipient_id);}, delay)


            setTimeout is asynchronous, it means that your code will wait 1 second and then send 6 messages in a row. You're probably looking for something like this:



            await setTimeout(function() {sendMessage(recipient_id);}, delay)
            await setTimeout(function() {sendMessage(recipient_id);}, delay)
            await setTimeout(function() {sendMessage(recipient_id);}, delay)
            await setTimeout(function() {sendMessage(recipient_id);}, delay)
            await setTimeout(function() {sendMessage(recipient_id);}, delay)
            await setTimeout(function() {sendMessage(recipient_id);}, delay)





            share|improve this answer




























              up vote
              -1
              down vote













              You can check out the wingbot library here on the github. It helps with building a simple bot. Like this:






              const { Router } = require('wingbot');

              const bot = new Router();

              bot.use('start', (req, res) => {
              res.typingOn()
              .wait(1000)
              .text('Hello');
              });








              share|improve this answer





















                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231117%2fsending-messages-with-delay%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                0
                down vote













                You can use settimeout for such scenarios. But for showing sender_action let's say if you want to show text like typing... from the bot inside messenger then facebook provides functionalities in its messenger API to include sender actions with different tags. Here is how I am doing it.



                sender_action: 'typing...',
                messaging_type: 'MESSAGE_TAG',
                tag: 'NON_PROMOTIONAL_SUBSCRIPTION',


                Please look into the following link for more information.
                https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions






                share|improve this answer

























                  up vote
                  0
                  down vote













                  You can use settimeout for such scenarios. But for showing sender_action let's say if you want to show text like typing... from the bot inside messenger then facebook provides functionalities in its messenger API to include sender actions with different tags. Here is how I am doing it.



                  sender_action: 'typing...',
                  messaging_type: 'MESSAGE_TAG',
                  tag: 'NON_PROMOTIONAL_SUBSCRIPTION',


                  Please look into the following link for more information.
                  https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    You can use settimeout for such scenarios. But for showing sender_action let's say if you want to show text like typing... from the bot inside messenger then facebook provides functionalities in its messenger API to include sender actions with different tags. Here is how I am doing it.



                    sender_action: 'typing...',
                    messaging_type: 'MESSAGE_TAG',
                    tag: 'NON_PROMOTIONAL_SUBSCRIPTION',


                    Please look into the following link for more information.
                    https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions






                    share|improve this answer












                    You can use settimeout for such scenarios. But for showing sender_action let's say if you want to show text like typing... from the bot inside messenger then facebook provides functionalities in its messenger API to include sender actions with different tags. Here is how I am doing it.



                    sender_action: 'typing...',
                    messaging_type: 'MESSAGE_TAG',
                    tag: 'NON_PROMOTIONAL_SUBSCRIPTION',


                    Please look into the following link for more information.
                    https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 10 at 23:29









                    Jawad Akram

                    12




                    12
























                        up vote
                        0
                        down vote













                        It'd be better if you provide more code when asking the question. I have the suspicion that you actually do this:



                        setTimeout(function() {sendMessage(recipient_id);}, delay)
                        setTimeout(function() {sendMessage(recipient_id);}, delay)
                        setTimeout(function() {sendMessage(recipient_id);}, delay)
                        setTimeout(function() {sendMessage(recipient_id);}, delay)
                        setTimeout(function() {sendMessage(recipient_id);}, delay)
                        setTimeout(function() {sendMessage(recipient_id);}, delay)


                        setTimeout is asynchronous, it means that your code will wait 1 second and then send 6 messages in a row. You're probably looking for something like this:



                        await setTimeout(function() {sendMessage(recipient_id);}, delay)
                        await setTimeout(function() {sendMessage(recipient_id);}, delay)
                        await setTimeout(function() {sendMessage(recipient_id);}, delay)
                        await setTimeout(function() {sendMessage(recipient_id);}, delay)
                        await setTimeout(function() {sendMessage(recipient_id);}, delay)
                        await setTimeout(function() {sendMessage(recipient_id);}, delay)





                        share|improve this answer

























                          up vote
                          0
                          down vote













                          It'd be better if you provide more code when asking the question. I have the suspicion that you actually do this:



                          setTimeout(function() {sendMessage(recipient_id);}, delay)
                          setTimeout(function() {sendMessage(recipient_id);}, delay)
                          setTimeout(function() {sendMessage(recipient_id);}, delay)
                          setTimeout(function() {sendMessage(recipient_id);}, delay)
                          setTimeout(function() {sendMessage(recipient_id);}, delay)
                          setTimeout(function() {sendMessage(recipient_id);}, delay)


                          setTimeout is asynchronous, it means that your code will wait 1 second and then send 6 messages in a row. You're probably looking for something like this:



                          await setTimeout(function() {sendMessage(recipient_id);}, delay)
                          await setTimeout(function() {sendMessage(recipient_id);}, delay)
                          await setTimeout(function() {sendMessage(recipient_id);}, delay)
                          await setTimeout(function() {sendMessage(recipient_id);}, delay)
                          await setTimeout(function() {sendMessage(recipient_id);}, delay)
                          await setTimeout(function() {sendMessage(recipient_id);}, delay)





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            It'd be better if you provide more code when asking the question. I have the suspicion that you actually do this:



                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)


                            setTimeout is asynchronous, it means that your code will wait 1 second and then send 6 messages in a row. You're probably looking for something like this:



                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)





                            share|improve this answer












                            It'd be better if you provide more code when asking the question. I have the suspicion that you actually do this:



                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)
                            setTimeout(function() {sendMessage(recipient_id);}, delay)


                            setTimeout is asynchronous, it means that your code will wait 1 second and then send 6 messages in a row. You're probably looking for something like this:



                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)
                            await setTimeout(function() {sendMessage(recipient_id);}, delay)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 12 at 10:50









                            kuceram

                            1,47952448




                            1,47952448






















                                up vote
                                -1
                                down vote













                                You can check out the wingbot library here on the github. It helps with building a simple bot. Like this:






                                const { Router } = require('wingbot');

                                const bot = new Router();

                                bot.use('start', (req, res) => {
                                res.typingOn()
                                .wait(1000)
                                .text('Hello');
                                });








                                share|improve this answer

























                                  up vote
                                  -1
                                  down vote













                                  You can check out the wingbot library here on the github. It helps with building a simple bot. Like this:






                                  const { Router } = require('wingbot');

                                  const bot = new Router();

                                  bot.use('start', (req, res) => {
                                  res.typingOn()
                                  .wait(1000)
                                  .text('Hello');
                                  });








                                  share|improve this answer























                                    up vote
                                    -1
                                    down vote










                                    up vote
                                    -1
                                    down vote









                                    You can check out the wingbot library here on the github. It helps with building a simple bot. Like this:






                                    const { Router } = require('wingbot');

                                    const bot = new Router();

                                    bot.use('start', (req, res) => {
                                    res.typingOn()
                                    .wait(1000)
                                    .text('Hello');
                                    });








                                    share|improve this answer












                                    You can check out the wingbot library here on the github. It helps with building a simple bot. Like this:






                                    const { Router } = require('wingbot');

                                    const bot = new Router();

                                    bot.use('start', (req, res) => {
                                    res.typingOn()
                                    .wait(1000)
                                    .text('Hello');
                                    });








                                    const { Router } = require('wingbot');

                                    const bot = new Router();

                                    bot.use('start', (req, res) => {
                                    res.typingOn()
                                    .wait(1000)
                                    .text('Hello');
                                    });





                                    const { Router } = require('wingbot');

                                    const bot = new Router();

                                    bot.use('start', (req, res) => {
                                    res.typingOn()
                                    .wait(1000)
                                    .text('Hello');
                                    });






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 16 at 20:36









                                    David menger

                                    11




                                    11






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231117%2fsending-messages-with-delay%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        這個網誌中的熱門文章

                                        Tangent Lines Diagram Along Smooth Curve

                                        Yusuf al-Mu'taman ibn Hud

                                        Zucchini