Developer documentation
Hooks
Hooks let plugins participate in Send without the user clicking your plugin button.
Before request
hooks.beforeRequest(ctx) runs before the active request is sent. Return ctx.request, a full request, or an action.
hooks: {
beforeRequest: function(ctx) {
var token = ctx.bus.input("auth.token", "");
if (token) ctx.request.headers["Authorization"] = "Bearer " + token;
ctx.request.headers["X-From-Plugin"] = "auth-helper";
return ctx.request;
}
}
After response
hooks.afterResponse(ctx) and hooks.onResponse(ctx) receive ctx.response, ctx.responseBody, ctx.request, ctx.pluginData, and ctx.bus.
hooks: {
afterResponse: function(ctx) {
return {
__action: "multi",
actions: [
{ __action: "setPluginData", key: "lastStatus", value: ctx.response.statusCode },
{ __action: "pluginBus.output", name: "response.body", value: ctx.responseBody }
]
};
}
}
Send and then run a response command
commands: {
"responsePopup.send": function(ctx) {
return {
__action: "runCommand",
command: "core.request.send",
payload: { afterSendCommand: "responsePopup.show" }
};
},
"responsePopup.show": function(ctx) {
return {
__action: "showMessage",
title: "Response",
message: ctx.responseBody || (ctx.payload && ctx.payload.response && ctx.payload.response.body) || ""
};
}
}