{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/4225","repository_url":"https://api.github.com/repos/Microsoft/BotBuilder","labels_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/4225/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/4225/comments","events_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/4225/events","html_url":"https://github.com/Microsoft/BotBuilder/issues/4225","id":299775534,"node_id":"MDU6SXNzdWUyOTk3NzU1MzQ=","number":4225,"title":"[Node.js SDK, FB Messenger] Response sequencing issue when using Session.delay()","user":{"login":"dan-cohn","id":25753506,"node_id":"MDQ6VXNlcjI1NzUzNTA2","avatar_url":"https://avatars3.githubusercontent.com/u/25753506?v=4","gravatar_id":"","url":"https://api.github.com/users/dan-cohn","html_url":"https://github.com/dan-cohn","followers_url":"https://api.github.com/users/dan-cohn/followers","following_url":"https://api.github.com/users/dan-cohn/following{/other_user}","gists_url":"https://api.github.com/users/dan-cohn/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-cohn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-cohn/subscriptions","organizations_url":"https://api.github.com/users/dan-cohn/orgs","repos_url":"https://api.github.com/users/dan-cohn/repos","events_url":"https://api.github.com/users/dan-cohn/events{/privacy}","received_events_url":"https://api.github.com/users/dan-cohn/received_events","type":"User","site_admin":false},"labels":[{"id":335881073,"node_id":"MDU6TGFiZWwzMzU4ODEwNzM=","url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/Feature%20Request","name":"Feature Request","color":"b60205","default":false},{"id":429202607,"node_id":"MDU6TGFiZWw0MjkyMDI2MDc=","url":"https://api.github.com/repos/Microsoft/BotBuilder/labels/Node.js%20SDK","name":"Node.js SDK","color":"6eff54","default":false}],"state":"open","locked":false,"assignee":{"login":"EricDahlvang","id":11055362,"node_id":"MDQ6VXNlcjExMDU1MzYy","avatar_url":"https://avatars0.githubusercontent.com/u/11055362?v=4","gravatar_id":"","url":"https://api.github.com/users/EricDahlvang","html_url":"https://github.com/EricDahlvang","followers_url":"https://api.github.com/users/EricDahlvang/followers","following_url":"https://api.github.com/users/EricDahlvang/following{/other_user}","gists_url":"https://api.github.com/users/EricDahlvang/gists{/gist_id}","starred_url":"https://api.github.com/users/EricDahlvang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricDahlvang/subscriptions","organizations_url":"https://api.github.com/users/EricDahlvang/orgs","repos_url":"https://api.github.com/users/EricDahlvang/repos","events_url":"https://api.github.com/users/EricDahlvang/events{/privacy}","received_events_url":"https://api.github.com/users/EricDahlvang/received_events","type":"User","site_admin":false},"assignees":[{"login":"EricDahlvang","id":11055362,"node_id":"MDQ6VXNlcjExMDU1MzYy","avatar_url":"https://avatars0.githubusercontent.com/u/11055362?v=4","gravatar_id":"","url":"https://api.github.com/users/EricDahlvang","html_url":"https://github.com/EricDahlvang","followers_url":"https://api.github.com/users/EricDahlvang/followers","following_url":"https://api.github.com/users/EricDahlvang/following{/other_user}","gists_url":"https://api.github.com/users/EricDahlvang/gists{/gist_id}","starred_url":"https://api.github.com/users/EricDahlvang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricDahlvang/subscriptions","organizations_url":"https://api.github.com/users/EricDahlvang/orgs","repos_url":"https://api.github.com/users/EricDahlvang/repos","events_url":"https://api.github.com/users/EricDahlvang/events{/privacy}","received_events_url":"https://api.github.com/users/EricDahlvang/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2018-02-23T16:46:00Z","updated_at":"2018-06-22T16:43:15Z","closed_at":null,"author_association":"NONE","body":"## Bot Info\r\n* SDK Platform: Node.js\r\n* SDK Version: 3.14.0\r\n* Active Channels: Facebook Messenger\r\n* Deployment Environment: AWS\r\n\r\n## Issue Description\r\nIn certain cases, users receive responses from the chatbot in the wrong order. Specifically, this occurs when typing ahead – i.e., sending a message to the bot before seeing the response from the previous one. I discovered the cause of this issue, and it relates to the use of Session.delay() to slow down the flow of responses, typically in conjunction with sendTyping().\r\n\r\nConsider the following sequence:\r\n \r\n1. ChatConnector: message received\r\n2. Session.sendTyping()\r\n3. Session.delay(2000)\r\n4. Session.send(\"First response\")\r\n5. Session.sendTyping()\r\n6. Session.delay(3000)\r\n7. Session.send(\"Second response\")\r\n8. Session.sendBatch() sending 6 message(s)\r\n9. ChatConnector: message received\r\n10. Session.sendTyping()\r\n11. Session.delay(1000)\r\n12. Session.send(\"Third response\")\r\n13. Session.sendBatch() sending 3 message(s)\r\n \r\nAssume there’s no delay between the first and second utterances from the user because they were typed quickly.  Here’s what *should* happen:\r\n \r\nAfter 0 sec – typing dots appear\r\nAfter 2 sec – “First response” appears\r\nAfter 5 sec – “Second response” appears followed by typing dots\r\nAfter 6 sec – “Third response” appears\r\n \r\nHere’s what *actually* happens:\r\n \r\nAfter 0 sec – typing dots appear\r\nAfter 1 sec – “Third response” appears\r\nAfter 2 sec – “First response” appears followed by typing dots\r\nAfter 5 sec – “Second response” appears\r\n \r\nThe reason for this is that the third delay isn’t queued behind the first two.  The framework treats it as a fresh message and sends it immediately.\r\n\r\n## Code Example\r\nSee above for details.  I also have a proposed BotBuilder code fix for this.  I'd be happy to share it.  I'm currently applying a patch from my application code.  See attached \"patches.js\" file.\r\n\r\n[patches.js.zip](https://github.com/Microsoft/BotBuilder/files/1752377/patches.js.zip)\r\n\r\n## Reproduction Steps\r\n1. Type two utterances one after the other. The first utterance should elicit a response or series of responses that include delays (e.g., for pacing). The second utterance should elicit a response or responses without delays or with a smaller delay.\r\n2. Observe that responses arrive out of order.  If you look at the logs, you can see they are also sent in the wrong order.\r\n\r\nThis is reproducible on the emulator as well.\r\n\r\n## Expected Behavior\r\nResponses should be sent in the correct order.\r\n\r\n## Actual Results\r\nSee attached video for an example of this.  First I type “help” which has a 10-second response delay (for the sake for demonstrating the issue).  While the clock is ticking, I type “bye” which has a 1-second response delay.  As you can see, the “bye” response comes out first and eventually the two-part help response appears.  Very confusing from a user standpoint.\r\n\r\n[Msg_ordering_issue.mov.zip](https://github.com/Microsoft/BotBuilder/files/1752387/Msg_ordering_issue.mov.zip)\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/comments/399506612","html_url":"https://github.com/Microsoft/BotBuilder/issues/4225#issuecomment-399506612","issue_url":"https://api.github.com/repos/Microsoft/BotBuilder/issues/4225","id":399506612,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTUwNjYxMg==","user":{"login":"EricDahlvang","id":11055362,"node_id":"MDQ6VXNlcjExMDU1MzYy","avatar_url":"https://avatars0.githubusercontent.com/u/11055362?v=4","gravatar_id":"","url":"https://api.github.com/users/EricDahlvang","html_url":"https://github.com/EricDahlvang","followers_url":"https://api.github.com/users/EricDahlvang/followers","following_url":"https://api.github.com/users/EricDahlvang/following{/other_user}","gists_url":"https://api.github.com/users/EricDahlvang/gists{/gist_id}","starred_url":"https://api.github.com/users/EricDahlvang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricDahlvang/subscriptions","organizations_url":"https://api.github.com/users/EricDahlvang/orgs","repos_url":"https://api.github.com/users/EricDahlvang/repos","events_url":"https://api.github.com/users/EricDahlvang/events{/privacy}","received_events_url":"https://api.github.com/users/EricDahlvang/received_events","type":"User","site_admin":false},"created_at":"2018-06-22T16:43:14Z","updated_at":"2018-06-22T16:43:14Z","author_association":"MEMBER","body":"Sorry @dan-cohn but we have not yet added something like this to the sdk.  I've labeled this as a feature request.  "}}
{"actor":{"display_login":"EricDahlvang"}}