alavers/smooch-bot

Bot states inconsistent with multiple user messages.

adit-chandra opened this issue · 3 comments

My team and I have written a custom state in the Script for the smooch bot. It works exactly as expected when we feed it messages (as a user) one at time. However, sometimes when we send multiple messages one after the other (as a real user might) the bot behaves unpredictably. Sometimes it doesn't finish executing everything written in the state. Sometimes it just restarts the state.

This happens even for our simple start state where the bot waits for the user to say something and responds 'Hello' and moves onto the next, different state. If the user says 'hi' four times in four separate lines quickly, the bot responds by saying 'Hello' four times (sometimes even giving the processing 'beep boop' message) instead of just say 'Hello' once and treating the next user message line as input for the next state.

This seems like a significant issues. Is there anyway to ensure that a state executes to its entirety before it attempts to read in another user message?

+1

This is what the locking mechanism in the state machine is intended to achieve:

https://github.com/smooch/smooch-bot/blob/master/lib/stateMachine.js#L31

The state machine will only process one user message at a time. If the bot receives a second user message before it's done processing the last one, (eg, before your receive has resolved its promise) the bit will instead executes whatever receive method you define in your processing state. By default, it simply ignores the message and does nothing, but you can override it however you want:

https://github.com/smooch/smooch-bot/blob/master/lib/script.js#L5

Hopefully this answers your question?

That helps some. Thank you.