# How to run global command based on user typing input

Global command can be called from any JavaScript code execution. Every input component in Request Response step has switch "Use function to define user answer" that allows to execute JavaScript code before user answer will be sent. It was created to check user input and change it somehow or run custom logic.

  1. Add Process Global Command (RWC) step Steps
  2. Add new command and type 'agent' New Command
  3. In Request Response step chose Text and Files input component and enable "Use function to define user answer" toggle Request response tree
  4. In User answer message add a code, that will check whether user reply matches with global command name.
if (userReply.includes('agent')) {
  window.runGlobalCommand({name: 'agent'})
  return null
}
return userReply

WARNING

You have to return null to prevent message sending

  1. If user answer contains 'agent' then global command will be triggered and flow goes by 'agent' leg

Download Flow source example

Last Updated: 12/21/2023, 2:38:08 PM