Asks

The Ask workflow context, available as client.workflows.asks. Manages the Ask workflows: the one of the first question, plus one for each follow-up question.

Events emitted by the Ask workflows are also emitted here, with the source workflow as event.workflow.

Instance properties

context.active

The workflow of the latest question being asked or answered.

Type: Ask

context.autocomplete

Autocomplete settings shared by the workflows of this context. Call enable() or disable() to switch autocomplete on or off, and read enabled for the current state.

Type: Object

context.root

The workflow of the first question. Same as client.workflows.ask.

Type: Ask

context.workflows

All Ask workflows.

Type: Ask[]

Instance methods

context.autoNext([options])

Prepare the workflow of the next follow-up question automatically, so a follow-up question can be asked right away.

Parameter Type Description
options boolean or string or function When to prepare the next workflow: true (the default) when an answer is done, an event name to wait for that event, or a function taking the event and returning whether to prepare. Optional.

context.clearApi()

Remove the API options set by useApi().

Returns this.

context.clearDataProcessor()

Remove the functions added by useDataProcessor().

Returns this.

context.clearInteractions()

Remove the interaction options set by useInteractions().

Returns this.

context.clearLayouts()

Remove the layout options set by useLayouts().

Returns this.

context.clearTemplates()

Remove the template options set by useTemplates().

Returns this.

context.clearTrackers()

Remove the tracker options set by useTrackers().

Returns this.

context.getByParentQuestionId([parentQuestionId], [options])

Get a workflow by the question ID of its parent question. Without a parent question ID, get the workflow of the first question.

Parameter Type Description
parentQuestionId string The question ID of the parent question. Optional.
options Object Optional.
options.autoCreate boolean Create the workflow if it does not exist. Default false. Optional.

Returns Ask or undefined.

context.getByQuestionId(questionId)

Get a workflow by the question ID of its question.

Parameter Type Description
questionId string The question ID.

Returns Ask or undefined.

context.on(name, callback)

Listen to an event.

Parameter Type Description
name string The event name, or '*' for all events.
callback function Called with (data, meta) on every event, where meta carries the event name and the timestamp ts.

Returns function: A function to remove the listener.

context.once(name)

Wait for the next occurrence of an event.

Parameter Type Description
name string The event name.

Returns Promise<{data: *, meta: Object}>: The event, with its data and meta.

context.reset([options])

Destroy the workflows of all follow-up questions, and start over.

Parameter Type Description
options Object Optional.
options.root boolean Also reset the workflow of the first question. Default true. Optional.
options.events boolean Also remove the event listeners on this context. Defaults to the value of root. Optional.

context.useApi([name], [payload])

Set the API to call, and extra payload to send with each request.

Parameter Type Description
name string or Object or false The API name, such as 'questions', or with its group, such as 'ask/questions'. Pass the payload object alone to keep the API, or false to stop calling the API, so you can provide data by updateData() instead. Optional.
payload Object Extra payload, merged into the request payload. Optional.

Returns this.

workflow.useApi("ask/questions", { source_fl: ["title", "url"] });

context.useDataProcessor(fns)

Add functions to process the data before it is rendered. They run in the order they are added.

Parameter Type Description
fns function or function()[] Functions taking (data, oldData) and returning the processed data.

Returns this.

context.useInteractions(options)

Set how interactions are sent.

Parameter Type Description
options Object or false Pass false to stop sending interactions.
options.preprocess function or function()[] Functions taking the interaction payload and returning the modified one, run before it is sent. Optional.
options.handle function A function taking the interaction payload, to send it yourself instead. Optional.

Returns this.

context.useLayouts(options)

Set the layouts, by role.

Parameter Type Description
options Object or false The layout of each role, as a layout name, layout options, or [name, options]. Pass false to stop rendering.

Returns this.

workflow.useLayouts({
  query: { placeholder: "Ask a question" },
  products: "list",
});

context.useTemplates(options)

Set the templates, by name.

Parameter Type Description
options Object The template of each name, as a function, or a value.

Returns this.

context.useTrackers(options)

Set the trackers, by role.

Parameter Type Description
options Object or boolean true or false to turn all trackers on or off, or the options of each role: active, and the options of each event type, impression, viewable (area and duration), and click (lenient).

Returns this.

workflow.useTrackers({ products: { viewable: { duration: 2000 } } });