{
  "ruleChain": {
    "name": "Telegram Alarm Notification",
    "type": "CORE",
    "firstRuleNodeId": null,
    "root": false,
    "debugMode": false,
    "configuration": null,
    "additionalInfo": {
      "description": ""
    }
  },
  "metadata": {
    "version": 3,
    "firstNodeIndex": 0,
    "nodes": [
      {
        "type": "org.thingsboard.rule.engine.filter.TbJsFilterNode",
        "name": "Check Temperature Range",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "return msg.temperature > 20;",
          "tbelScript": "return msg.temperature < -15 || msg.temperature > 30;"
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 302,
          "layoutY": 151
        }
      },
      {
        "type": "org.thingsboard.rule.engine.action.TbCreateAlarmNode",
        "name": "Create Temperature Alarm",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "alarmDetailsBuildJs": "var details = {};\nif (metadata.prevAlarmDetails) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    delete metadata.prevAlarmDetails;\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
          "alarmDetailsBuildTbel": "var details = {};\nif (metadata.prevAlarmDetails != null) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    metadata.remove('prevAlarmDetails');\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
          "useMessageAlarmData": false,
          "overwriteAlarmDetails": false,
          "alarmType": "High Temperature",
          "severity": "CRITICAL",
          "propagate": false,
          "relationTypes": [],
          "propagateToOwner": false,
          "propagateToOwnerHierarchy": false,
          "propagateToTenant": false,
          "dynamicSeverity": false
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 577,
          "layoutY": 227
        }
      },
      {
        "type": "org.thingsboard.rule.engine.transform.TbTransformMsgNode",
        "name": "New Telegram Message",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "var newMsg = {};\nnewMsg.text = '\"' + metadata.alarmType + '\"' + ' alarm was created for device: \"' + metadata.deviceName + '\"';\nnewMsg.chat_id = 337878729; // replace with your chat_id\nreturn {msg: newMsg, metadata: metadata, msgType: msgType};",
          "tbelScript": "var newMsg = {};\nnewMsg.text = '\"' + metadata.alarmType + '\"' + ' alarm was created for device: \"' + metadata.deviceName + '\"';\nnewMsg.chat_id = 337878729; // replace with your chat_id\nreturn {msg: newMsg, metadata: metadata, msgType: msgType};"
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 575,
          "layoutY": 326
        }
      },
      {
        "type": "org.thingsboard.rule.engine.rest.TbRestApiCallNode",
        "name": "Send Telegram Message",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 3,
        "configuration": {
          "restEndpointUrlPattern": "https://api.telegram.org/bot110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw/sendMessage",
          "requestMethod": "POST",
          "useSimpleClientHttpFactory": false,
          "parseToPlainText": false,
          "ignoreRequestBody": false,
          "enableProxy": false,
          "useSystemProxyProperties": false,
          "proxyScheme": null,
          "proxyHost": null,
          "proxyPort": 0,
          "proxyUser": null,
          "proxyPassword": null,
          "readTimeoutMs": 0,
          "maxParallelRequestsCount": 0,
          "headers": {
            "Content-Type": "application/json"
          },
          "credentials": {
            "type": "anonymous"
          },
          "maxInMemoryBufferSizeInKb": 256
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 577,
          "layoutY": 425
        }
      },
      {
        "type": "org.thingsboard.rule.engine.action.TbClearAlarmNode",
        "name": "Clear Temperature Alarm",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "alarmDetailsBuildJs": "var details = {};\nif (metadata.prevAlarmDetails) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    delete metadata.prevAlarmDetails;\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
          "alarmDetailsBuildTbel": "var details = {};\nif (metadata.prevAlarmDetails != null) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    metadata.remove('prevAlarmDetails');\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
          "alarmType": "High Temperature"
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 575,
          "layoutY": 77
        }
      }
    ],
    "connections": [
      {
        "fromIndex": 0,
        "toIndex": 1,
        "type": "True"
      },
      {
        "fromIndex": 0,
        "toIndex": 4,
        "type": "False"
      },
      {
        "fromIndex": 1,
        "toIndex": 2,
        "type": "Created"
      },
      {
        "fromIndex": 2,
        "toIndex": 3,
        "type": "Success"
      }
    ],
    "ruleChainConnections": null
  }
}
