History
The thread list of the chat history interface, available as
client.workflows.history. Lists the user's past conversation threads,
page by page as the list scrolls, and works with the conversation
workflow (client.workflows.conversation) to show the selected thread.
Threads are listed in groups: all threads ('all'), favorited ones
('favorite'), and the rest ('unfavorite').
Instance properties
workflow.destroyed
Whether the workflow is destroyed.
Type: boolean
workflow.exhausted
Whether no more threads will be loaded into the list, as the list is complete, or a page failed to load.
Type: boolean
workflow.selectedId
The ID of the selected thread.
Type: string or undefined
workflow.states
The current states of the workflow, by field name, such as data. For
debugging.
Type: Object
workflow.status
The status of the data: initial, loading, ready, or erroneous.
Type: string or undefined
workflow.threads
The listed threads, of all groups. Same as getThreads('all').
Type: Object[]
workflow.trackers
The trackers of the workflow, which track impressions, viewables, and clicks of the rendered items.
Type: Object
workflow.views
The views of the workflow: the elements bound to it, by role.
Type: Object
Instance methods
workflow.clearApi()
Remove the API options set by useApi().
Returns this.
workflow.clearDataProcessor()
Remove the functions added by useDataProcessor().
Returns this.
workflow.clearInteractions()
Remove the interaction options set by useInteractions().
Returns this.
workflow.clearLayouts()
Remove the layout options set by useLayouts().
Returns this.
workflow.clearPagination()
Remove the pagination options set by usePagination().
Returns this.
workflow.clearTrackers()
Remove the tracker options set by useTrackers().
Returns this.
workflow.delete(threadIds)
Delete one or more threads.
| Parameter | Type | Description |
|---|---|---|
threadIds |
string or string[] |
A thread ID, or an array of them. |
workflow.deleteAll()
Delete all threads of the user.
workflow.favorite(threadId, [value])
Add a thread to, or remove it from, the favorites. This sets the state rather than toggling it.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
value |
boolean |
true to favorite, false to unfavorite. Default true. Optional. |
workflow.get(threadId)
Get a listed thread by its thread ID.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
Returns Object or undefined.
workflow.getThreads([group])
Get the listed threads of a group.
| Parameter | Type | Description |
|---|---|---|
group |
string |
'all', 'favorite', or 'unfavorite'. Default 'all'. Optional. |
Returns Object[].
workflow.isExhausted([group])
Whether no more threads will be loaded into a group, like exhausted.
| Parameter | Type | Description |
|---|---|---|
group |
string |
'all', 'favorite', or 'unfavorite'. Default 'all'. Optional. |
Returns boolean.
workflow.markAsRead(threadId)
Mark a thread as read.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
workflow.notifyViewUpdate(role, [state])
Tell the workflow that a view of a role is rendered, when the view is rendered by your own code. Lifecycle events are emitted off the view of the main role.
| Parameter | Type | Description |
|---|---|---|
role |
string |
The role. |
state |
Object |
The view state. Status defaults to ready. Optional. |
Returns this.
workflow.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.
workflow.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.
workflow.rename(threadId, title)
Rename a thread.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
title |
string |
The new title. |
workflow.restart()
Start a new session, discarding the data of the current one, along with any API call in progress.
Returns this.
workflow.select(threadId)
Select a thread, and show it in the conversation panel.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
Returns this.
workflow.start()
Load the thread list. Does nothing if the list is already loaded or
loading. To reload from scratch, call restart() then start().
Returns this.
workflow.subscribe(threadId)
Subscribe to answer updates of a thread.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
workflow.unsubscribe(threadId)
Unsubscribe from answer updates of a thread. An unsubscribed thread is no longer presented as unread.
| Parameter | Type | Description |
|---|---|---|
threadId |
string |
The thread ID. |
workflow.updateData(data)
Update the workflow with data from your own source, instead of calling the API. The data must carry the current session, or it is ignored.
| Parameter | Type | Description |
|---|---|---|
data |
Object |
|
data.session |
Object |
The current session, workflow.session. |
data.value |
* |
The data value, in the shape of the API response. Optional. |
data.error |
Object |
The error, if the data failed to load. Optional. |
Returns this.
Throws Error: If data or its session is missing.
workflow.updateData({ session: workflow.session, value: response });
workflow.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"] });
workflow.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.
workflow.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.
workflow.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",
});
workflow.usePagination(options)
Set the pagination options.
| Parameter | Type | Description |
|---|---|---|
options |
Object or boolean |
true or false to turn pagination on or off, or the options, such as active and mode. |
Returns this.
workflow.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 } } });
