Skip to content

BotWorks 104: Bot Messages explained

BotEvangelist edited this page Dec 3, 2018 · 2 revisions

Overview

A BotMessage is a JSON formatted document that has a specific structure to allow proper processing. There are a few things that you should be aware of:

  1. All BotMessages are JSON documents with a standard format. The overall structure of the message is described later in this page.
  2. The only portion of a BotMessage that may not have a defined structure is the 'data' section of the document, and that format is determined by the needs of each particular type of Bot.
  3. Receipt, parsing and publishing of all BotMessages is done by the BaseBot class.
  4. Within the Bot ecosystem, BotMessages are created by the rendering of a StringTemplate.

Message Structure

A BotMessage has the following parts:

  1. Metadata - This is a set of descriptive data about the process itself. It include things like
  • process names and ids, timestamps related to the overall and current process.
  • the topic on which the message was published
  • the type of Bot that should process it
  • Tags that are carried through a multi-step process. Note: Tags from an input BotMessage are replicated in the output BotMessage(s) with whatever addition is made by the current Bot. You can think of the Tags section as a medium for carrying state from the over all process.
  1. Tasks - A task is an atomic action that a Bot needs to execute. Within the Task there are a number of sections:
  • A Data Section: This contains data that is required for the Bot to execute the Task at hand.
  • An Application Template - This is a reference to a StringTemplate Template Group and Template Name that will be instantiated along with the information in the data section to produce the result of the action.
  • An optional processor class - In rare cases there is a need to do a bit of processing on the incoming data before applying the Application Template.
  • An Output Template(s) - This is a reference to a StringTemplate Template Group and Template Name that will be instantiated along with the information from the Application Template to produce a message that will be emitted from the Bot if the Task is successful.
  • An Error Template - This is a reference to a StringTemplate Template Group and Template Name that will be instantiated along with the information from the Application Template to produce a message that will be emitted from the Bot if the Task is not successful.