‘"actions" is not defined’ error when invoking rule containing ECMAScript

System details

  • Platform information:
    • Hardware: Raspberry Pi 4B 4 GiB
    • OS: OpenSUSE Leap 15.3
    • Java Runtime Environment: openjdk 11.0.11 2021-04-20 LTS, OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS), OpenJDK 64-Bit Server VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)

Issue

Given this script:

triggers:
  - id: "1"
    configuration:
      thingUID: xmppclient:xmppBridge:5af0583a7b
      channelUID: xmppclient:xmppBridge:5af0583a7b:XMPPIncoming
    type: core.ChannelEventTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >+
        
        const publish = actions.get("xmppclient:xmppBridge:5af0583a7b").publishXMPP;

    type: script.ScriptAction

I receive this error:

11:25:16.843 [ERROR] [ab.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: ReferenceError: "actions" is not defined
…
11:25:16.924 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'e0a3078ba2' failed: org.graalvm.polyglot.PolyglotException: ReferenceError: "actions" is not defined

My goal is to get a reference to publishXMPP on the XMPP binding. I’ve seen this post on the subject and also seen this illustrative example which suggest that should work.

What am I doing wrong?

Uninstalling JSScripting and changing the code slightly gets me there.

triggers:
  - id: "1"
    configuration:
      thingUID: xmppclient:xmppBridge:5af0583a7b
      channelUID: xmppclient:xmppBridge:5af0583a7b:XMPPIncoming
    type: core.ChannelEventTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >+
        
        actions.get("xmppclient", "xmppclient:xmppBridge:5af0583a7b").publishXMPP("xr37@example.com", "Hello there!");


    type: script.ScriptAction

I’d still love to know how I would go about implementing the above example with the JSScripting binding installed though, so I could use ES6 features. :slightly_smiling_face: