脚本(开发者)

示例中的 _id 需要替换成你自己的
示例中的 hmp_... 需要替换为自己的令牌 获取令牌

获取脚本列表

GET /v1/devscripts

示例

Hamibot 示例

// hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts', {
  method: 'GET',
  headers: {
    authorization: 'token hmp_...',
  },
});
log(res.body.json());

curl 示例

curl -H "Authorization: token hmp_..." \
    https://api.hamibot.com/v1/devscripts

响应

200 成功

{
  "count": 1,
  "items": [
    {
      "_id": "bfe67d643ababe0ab6fda054",
      "name": "你好世界"
    }
  ]
}

获取脚本

GET /v1/devscripts/{scriptId}

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts/_id', {
  method: 'GET',
  headers: {
    authorization: 'token hmp_...',
  },
});
log(res.body.json());

curl 示例

curl -H "Authorization: token hmp_..." \
    https://api.hamibot.com/v1/devscripts/_id

响应

200 成功

{
  "_id": "bfe67d643ababe0ab6fda054",
  "name": "你好世界"
}

运行脚本

POST /v1/devscripts/{scriptId}/run

参数

名称类型描述
robotsarray要执行脚本的机器人
varsobject可选,脚本配置

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
http.request('https://api.hamibot.com/v1/devscripts/_id/run', {
  method: 'POST',
  contentType: 'application/json',
  headers: {
    authorization: 'token hmp_...',
  },
  body: JSON.stringify({
    robots: [{ _id: 'a51d237e9af41ecc021c9ff6', name: '零号机' }],
  }),
});

curl 示例

curl \
    -X POST \
    -H "Authorization: token hmp_..." \
    -H "Content-Type: application/json" \
    -d '{"robots": [{"_id": "a51d237e9af41ecc021c9ff6", "name": "零号机"}]}' \
    https://api.hamibot.com/v1/devscripts/_id/run

响应

204 成功

422 参数错误

停止脚本

DELETE /v1/devscripts/{scriptId}/run

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
http.request('https://api.hamibot.com/v1/devscripts/_id/run', {
  method: 'DELETE',
  contentType: 'application/json',
  headers: {
    authorization: 'token hmp_...',
  },
  body: JSON.stringify({
    robots: [{ _id: 'a51d237e9af41ecc021c9ff6', name: '零号机' }],
  }),
});

curl 示例

curl \
    -X DELETE \
    -H "Authorization: token hmp_..." \
    -H "Content-Type: application/json" \
    -d '{"robots": [{"_id": "a51d237e9af41ecc021c9ff6", "name": "零号机"}]}' \
    https://api.hamibot.com/v1/devscripts/_id/run

响应

204 成功

创建脚本

POST /v1/devscripts

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts', {
  method: 'POST',
  headers: {
    authorization: 'token hmp_...',
  },
});
log(res.body.json());

curl 示例

curl \
    -X POST \
    -H "Authorization: token hmp_..." \
    https://api.hamibot.com/v1/devscripts

响应

201 成功

{
  "_id": "bfe67d643ababe0116fda052",
  "name": "未命名9527"
}

删除脚本

DELETE /v1/devscripts/{scriptId}

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts/_id', {
  method: 'DELETE',
  headers: {
    authorization: 'token hmp_...',
  },
});

curl 示例

curl \
    -X DELETE \
    -H "Authorization: token hmp_..." \
    -H "Content-Type: application/json" \
    https://api.hamibot.com/v1/devscripts/_id

响应

204 成功

修改脚本

PUT /v1/devscripts/{scriptId}/files

注意

  • 脚本和配置可同时上传,也可单独上传(最多可同时上传 2 个文件)
  • 文件大小不能超过 3Mb(以系统为准)
  • 配置文件是 JSON 数组,参见 配置脚本
  • 需要正确提供 MIME type,脚本 application/javascript,配置 application/json

示例

curl 示例

curl \
    -X PUT \
    -H "Authorization: token hmp_..." \
    -F "data=@index.js;type=application/javascript" \
    -F "data=@config.json;type=application/json" \
    https://api.hamibot.com/v1/devscripts/bfe67d643ababe0ab6fda054/files

响应

204 成功

发布脚本

POST /v1/devscripts/{scriptId}/publish
仅支持已审核通过的脚本

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts/_id/publish', {
  method: 'POST',
  headers: {
    authorization: 'token hmp_...',
  },
});
log(res.body.json());

curl 示例

curl \
    -X POST \
    -H "Authorization: token hmp_..." \
    https://api.hamibot.com/v1/devscripts/_id/publish

响应

201 成功

撤销发布

DELETE /v1/devscripts/{scriptId}/publish

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
var res = http.request('https://api.hamibot.com/v1/devscripts/_id/publish', {
  method: 'DELETE',
  headers: {
    authorization: 'token hmp_...',
  },
});

curl 示例

curl \
    -X DELETE \
    -H "Authorization: token hmp_..." \
    -H "Content-Type: application/json" \
    https://api.hamibot.com/v1/devscripts/_id/publish

响应

204 成功