脚本

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

获取脚本列表

GET /v1/scripts

示例

Hamibot 示例

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

curl 示例

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

响应

200 成功

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

获取脚本

GET /v1/scripts/{scriptId}

示例

Hamibot 示例

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

curl 示例

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

响应

200 成功

{
  "_id": "bfe67d643ababe0ab6fda054",
  "slug": "FLZoI",
  "name": "你好世界",
  "version": "1.1.3"
}

运行脚本

POST /v1/scripts/{scriptId}/run

参数

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

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
http.request('https://api.hamibot.com/v1/scripts/_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/scripts/_id/run

响应

204 成功

422 参数错误

停止脚本

DELETE /v1/scripts/{scriptId}/run

示例

Hamibot 示例

// _id 和 hmp_... 需要替换成自己的
http.request('https://api.hamibot.com/v1/scripts/_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/scripts/_id/run

响应

204 成功

删除脚本

DELETE /v1/scripts/{scriptId}

示例

Hamibot 示例

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

curl 示例

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

响应

204 成功