Skip to main content
A logic.insert adds one message to a messages list. It places the message at the position index names, or at the end, and writes the longer list to its output. Use it to build a history by hand, or to put a message in front of a conversation before a chat reads it.

Where the message goes

index places the message the way a Python list.insert does.
  • 0 puts it first, and the messages that were there move up by one.
  • A positive index puts it before the message now at that position. 2 leaves two messages ahead of it.
  • A negative index counts from the end. -1 puts the message before the last one, not after it.
  • An index out of range goes to the nearest end. One past the length of the list appends, and one before the start puts the message first. It never fails.
  • No index appends. The message goes after the last.
A message that carries no attributes is given an id and a created_at time as it goes in. A message that already has attributes keeps them.

When it fails

A logic.insert whose message holds no value takes failure, with an error event, Cannot insert an empty or uninitialized message., and writes nothing. A message value that holds no message inside it takes failure the same way, without the event. A messages that holds no value does not fail: the list starts empty.

Example

Ostrava Pumps opens each service conversation with a standing instruction. A data.message called House rules holds the instruction, and a data.messages called Request history holds what the customer has said so far. A logic.insert has messages wired to Request history as input and as output, message wired to House rules, and index 0, so the rules are the first message a chat reads, whatever the length of the history.