Skip to content
← Back to Index

messageActor

messageActor(
  actorType: text
  actorId: uuid|text
  messages: [{
    type: text
    alias: text | nothing
    body: value    
  }]
  preview: boolean | nothing
): {
  actorId: uuid|nothing
  paths: [text]
  data: {
    \`[type or alias]\`: value
  }
  errors: [<a href="/resources/components/runtimes/types/error/">Error</a>]
  preview: boolean
}

The messageActor function enables messaging Actors and receiving the response. Multiple messages can be sent in a single call, allowing preview of multiple messages in a single transaction. The messages are processed by the target actor in the order they are specified.

Availability

DiscountRuleReactor

Message Response

The return value contains information about the actor, whether the response was previewed or not, and the actual response values for each individual message (data)

The response data from the actor is a record where each field maps to the original message type (or alias if specified). Refer to the message reference for details of each message response type.

Error Handling

Multiple errors can occur during a single batch of messages, therefor inspect the error field in the response. Errors that are returned by the actor itself has a detail property fromMessage allowing you to infer which message caused the error.

Some errors, such as invalid actorId will result in the response actorId field being nothing.

Examples

From the Cookbook:

filtrera
from orderState match
  'pending' |> messageActor (
    'order'
    orderId
    [{
      type = 'applyCommands'
      body = {
        commands = [{
          type = 'setOrderState'
          orderState = 'cancelled'
        }]
      }
    }]
  )
  'confirmed' |> 'Order is confirmed, no cancellation'
  'cancelled' |> 'Order is already cancelled'
  |> orderState

© 2024 Hantera AB. All rights reserved.