edit

告警推送

Note

告警推送分为厂家规则和用户规则,其中厂家规则必须由厂家用户调用console-openapi.hekr.me, 用户规则由厂家用户调用user-openapi.hekr.me

厂家查询脚本

GET https://console-openapi.hekr.me/api/v1/product/{mid}/ifttt HTTP/1.1
Authorization: Bearer {JWT_TOKEN}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "id": {
        "pid": "01240737641",
        "mid": "IyFauxgNdjFs"
    },
    "enable": true,
    "language": "rule",
    "ifttt": {
        "javascript": {
            "code": "var onDevSend = function (message) {}"
        },
        "rule": {
            "rules": [
                {
                    "name": "关灯通知",
                    "enable": true,
                    "triggerOn": "onDevSend",
                    "condition": {
                        "type": "and",
                        "conditions": [
                            {
                                "type": "eq",
                                "left": "cmdId",
                                "right": 1
                            },
                            {
                                "type": "eq",
                                "left": "switch",
                                "right": 0
                            }
                        ]
                    },
                    "actions": [
                        {
                            "type": "notification",
                            "push": true,
                            "subject": {
                                "zh": "灯关了",
                                "en": "lights out"
                            },
                            "content": {
                                "zh": "开关 = ${switch}",
                                "en": "switch = ${switch}"
                            },
                            "notificationType": "INFO"
                        }
                    ]
                }
            ]
        }
    }
}

厂家添加脚本(javascript)

PUT https://console-openapi.hekr.me/api/v1/product/{mid}/ifttt HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer {JWT_TOKEN}

{
  "enable": false,
  "language": "javascript",
  "ifttt": {
    "javascript": {
      "code": "var onDevSend = function (message) {}"
    }
  }
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "id": {
        "pid": "01240737641",
        "mid": "IyFauxgNdjFs"
    },
    "enable": false,
    "language": "javascript",
    "ifttt": {
        "javascript": {
            "code": "var onDevSend = function (message) {}"
        }
    }
}

请求参数

参数 类型 是否必须 默认 含义
enable Boolean true 是否启用该IFTTT
language String true IFTTT编写方式,当前支持[javascript, rule]
ifttt.javascript.code String true javascript 方式脚本,编写规则参考告警推送

厂家添加脚本(rule)

PUT https://console-openapi.hekr.me/api/v1/product/{mid}/ifttt HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer {JWT_TOKEN}

{
  "enable": true,
  "language": "rule",
  "ifttt": {
    "javascript": {
      "code": "var onDevSend = function (message) {}"
    },
    "rule": {
      "rules": [
        {
          "name": "关灯通知",
          "enable": true,
          "triggerOn": "onDevSend",
          "condition": {
            "type": "and",
            "conditions": [
              {
                "type": "eq",
                "left": "cmdId",
                "right": 1
              },
              {
                "type": "eq",
                "left": "switch",
                "right": 0
              }
            ]
          },
          "actions": [
            {
              "type": "notification",
              "notificationType": "INFO",
              "subject": {
                "zh": "灯关了",
                "en": "lights out"
              },
              "content": {
                "zh": "开关 = ${switch}",
                "en": "switch = ${switch}"
              }
            }
          ]
        }
      ]
    }
  }
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "id": {
        "pid": "01240737641",
        "mid": "IyFauxgNdjFs"
    },
    "enable": true,
    "language": "rule",
    "ifttt": {
        "javascript": {
            "code": "var onDevSend = function (message) {}"
        },
        "rule": {
            "rules": [
                {
                    "name": "关灯通知",
                    "enable": true,
                    "triggerOn": "onDevSend",
                    "condition": {
                        "type": "and",
                        "conditions": [
                            {
                                "type": "eq",
                                "left": "cmdId",
                                "right": 1
                            },
                            {
                                "type": "eq",
                                "left": "switch",
                                "right": 0
                            }
                        ]
                    },
                    "actions": [
                        {
                            "type": "notification",
                            "subject": {
                                "zh": "灯关了",
                                "en": "lights out"
                            },
                            "content": {
                                "zh": "开关 = ${switch}",
                                "en": "switch = ${switch}"
                            },
                            "notificationType": "INFO"
                        }
                    ]
                }
            ]
        }
    }
}

请求参数

参数 类型 是否必须 默认 含义
ifttt.rule.rules.*.name String true 规则名称
ifttt.rule.rules.*.enable Boolean true 是否启用该规则
ifttt.rule.rules.*.triggerOn String true 触发时机 当前支持[onDevSend]
ifttt.rule.rules.*.condition Object true 触发条件
ifttt.rule.rules.*.actions Array true 执行动作

condition

condition支持多层复合,约定客户端仅使用2层以便于客户端解析。第一层and, or 逻辑条件第二层eq, lt...

逻辑条件包含type和conditions,type有"and", "or"两种分别对应逻辑与和逻辑或,conditions是提交列表 可以是任何条件的集合(逻辑条件或者算术条件)。

{
  "type": "and",
  "conditions": []
}

算术条件由三部分组成,type表示条件类型,left为左操作数,right为右操作数 例如下例表示switch 等于 10

{
  "type": "eq",
  "left": "switch",
  "right": 10   
}

所有可用的操作符:

名称 含义
lt 小于
gt 大于
eq 等于
lte 小于等于
gte 大于等于

Note

  1. 服务端并不强制要求left为变量或数字,但建议保证left一定是变量
  2. 变量名必须满足正则表达式^[a-zA-Z_][a-zA-Z0-9]*$
  3. 可以是2个变量之间进行比较,{ "type": "gte", "left": "param1", "right": "param2" } 表示param1 >= param2

action

rule可以指定多个action,通过type区分,目前支持[notification, appPush]


notification

添加用户通知

参数 类型 是否必须 默认 含义
notificationType String true 通知类型 当前支持[WARNING, INFO]
subject Object true 多语言标题
content Object true 多语言内容

appPush

发送APP应用推送

参数 类型 是否必须 默认 含义
subject Object true 多语言标题
content Object true 多语言内容

http

参数 类型 是否必须 默认 含义
url String true 消息转发地址
method [PUT, POST] true 消息转发HTTP 方法

消息的格式为

{
    "ctrlKey": "298722...",
    "mid": "JIxjWqjxk",
    "payload": {
        "cmdId": 1,   
        "light": 23
    }
}
字段 含义
ctrlKey 设备唯一标识
mid 产品唯一标识
payload 具体的设备上报信息