Advanced - Order of Operations

If you've made it to this page, congratulations! You are a Dexter expert -- a Dexpert, if you will... 👍


Here is a summarized reminder of how to write a standard trigger/response pair in your bot script. For the most part, any processing expected in your script will always follow the same order of operations.

Take a look at the following example of the most complex trigger/response pair you are likely to encounter on Dexter:

+ *
$ POST {"headers": {"Authorization": "Bearer xxx"}, "body": {"user":"<get user>", "item": "<star>"}}
- Thanks, your confirmation id is: ${{}} <set id=${{}}> <call>confirmOrder <star></call> {@ stuff} ^buttons(Another item, I'm done)
  1. Matches Incoming Trigger: User input hits matching trigger. (In this case, the user hits a catch-all wildcard.)
  2. Preprocessing before HTTP Request: Next, we handle the $ HTTP requests immediately following the trigger. First, we must handle any preprocessing in the "header" or the "body" of the $ request here before we can make the $ POST request.
    • We replace any <star>s with the captured wildcard. (Reminder: the <star> is a * in a trigger, but a tag when used outside of a trigger.)
    • Then we process any <get> directions,
    • And lastly we handle any <call>s and replace the <call> with the returned result from the macro.
  3. Make HTTP Request: When these <get> and <call>s have been completed, we will make a request to this resource with the final headers and body.
  4. Handle HTTP response: Now, we process the response from the resource. We use mustache syntax to process the HTTP response and plug the data into the bot's - response.
    • If there is no match, the mustache syntax is stripped from the bot response.
    • We also store the HTTP response in a value (this.httpData) that can be accessed from within macros in the bot response.
  5. Handle any directions: Next, we must replace any <get> directions with user data or save any data using the <set> direction in the - response.
  6. Handle any redirects: After this, we will handle any topic redirects, followed by any trigger redirects. If you include both a topic and a trigger redirect, it will look for a trigger in the new redirected topic
  7. Handle any macros: Now, we handle any macros that are called confirmOrder.
    • Reminder: You can pass in (1) the captured wildcard <star> (2) and the mustache syntax values as parameters in the macro, but you cannot pass in any <get> values.
    • To make use of user data in the macro, call rs.getUservar() from within the macro.
    • As a reminder, you can access the response of the HTTP data in this.httpData from within the macro.
  8. Handle any shortcodes: Lastly, we take care of our shortcodes. Since shortcodes are processed after directions and macros, any values you pass into a shortcode will reflect the state of the bot after the directions are completed and the macros return.