Create new instance.
The baseURL of the request. This should include the x-callback-url base URL and action, typically something like app-scheme://x-callback-url/actionName
An object contain and URL query parameters returned by the target app along with it’s callback response. For example, if the target app called x-success with the query parameters result=MyTestText
, callbackResponse would contain {"result": "MyTestText"}
.
Object containing string keys and values to be appended to the base url as query parameters. Values should not be pre-encoded, but will be encoded and added to the base URL automatically. Do not include x-callback parameters (x-success
, x-error
, x-cancel
) as these will be generated by Drafts.
The current status of the callback. Used to check outcome after open is called. Possible values:
The current URL. This is provided as a debugging property, and will output the URL including the baseURL property with any configured parameters added. This property will differ from the actual URL opened when calling open()
in that it will not contain the x-success
, x-error
and x-cancel
parameters which are added dynamically at the time open()
is called.
If true, the script will pause and wait for the x-success
, x-error
or x-cancel
response from the app being targeted by the URL. If false, execution of the script/action will continue immediately and no response/results will be available.
Add a query parameter for the outgoing URL. FIXME: can the value be anything?
Opens the URL with associated parameters, and waits for a callback response. Returns true if an x-success response was received from the target app, otherwise false. If false, use the "status" property to determine the type of failure.
Creates a new CallbackURL object.
Generated using TypeDoc
CallbackURL
CallbackURL objects can be used to open x-callback-url requests and wait for a response from the target app.
NOTE: If you want to open a URL in Safari or another app and do not need a response or x-callback-url support, use the
app.openURL(url)
method on the App object.Example
// Open callback URL for each line in a draft // Setup base Fantastical URL, with no parameters const baseURL = "fantastical2://x-callback-url/parse/"; // split draft and loop over lines var lines = draft.content.split("\n"); for (var line of lines) { // create and configure callback object var cb = CallbackURL.create(); cb.baseURL = baseURL; cb.addParameter("sentence", line); // open and wait for result var success = cb.open(); if (success) { console.log("Event created"); } else { // something went wrong or was cancelled console.log(cb.status); if (cb.status == "cancel") { context.cancel(); } else { context.fail(); } } }