Provide JavaScript examples (#17490)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-10-01 14:12:22 +02:00 committed by Ciprian Pascu
parent f7ab4f2307
commit 2ee86a07e9

View File

@ -87,12 +87,34 @@ Thing pushover:pushover-account:account [ apikey="APP_TOKEN", user="USER_KEY" ]
demo.rules:
:::: tabs
::: tab DSL
```java
val actions = getActions("pushover", "pushover:pushover-account:account")
// send HTML message
actions.sendHtmlMessage("Hello <font color='green'>World</font>!", "openHAB")
```
:::
::: tab JavaScript
```javascript
var pushoverActions = actions.thingActions('pushover', 'pushover:pushover-account:account');
// send HTML message
pushoverActions.sendHtmlMessage("Hello <font color='green'>World</font>!", "openHAB");
```
:::
::::
:::: tabs
::: tab DSL
```java
val actions = getActions("pushover", "pushover:pushover-account:account")
// send message with attachment
@ -103,6 +125,28 @@ actions.sendAttachmentMessage("Hello World!", "openHAB", "data:[<media type>][;b
actions.sendAttachmentMessage("Hello World!", "openHAB", myImageItem.state.toFullString, null)
```
:::
::: tab JavaScript
```javascript
var pushoverActions = actions.thingActions('pushover', 'pushover:pushover-account:account');
// send message with attachment
pushoverActions.sendAttachmentMessage("Hello World!", "openHAB", "/path/to/my-local-image.png", "image/png");
pushoverActions.sendAttachmentMessage("Hello World!", "openHAB", "https://www.openhab.org/openhab-logo-square.png", null);
pushoverActions.sendAttachmentMessage("Hello World!", "openHAB", "data:[<media type>][;base64],<data>", null);
// in case you want to send the content of an Image Item (RawType)
pushoverActions.sendAttachmentMessage("Hello World!", "openHAB", items.myImageItem.rawState.toFullString(), null);
```
:::
::::
:::: tabs
::: tab DSL
```java
val actions = getActions("pushover", "pushover:pushover-account:account")
// send priority message
@ -116,6 +160,27 @@ if( receipt !== null ) {
}
```
:::
::: tab JavaScript
```javascript
var pushoverActions = actions.thingActions('pushover', 'pushover:pushover-account:account');
// send priority message
var receipt = pushoverActions.sendPriorityMessage("Emergency!!!", "openHAB", 2);
// wait for your cancel condition
if (receipt !== null ) {
pushoverActions.cancelPriorityMessage(receipt);
receipt = null;
}
```
:::
::::
:::: tabs
::: tab DSL