ConversationQueue\<TInput, TOutput>

Manages planned conversations.

A conversation may be enqueued, that is, planned to execute in a specific time frame. When the conversation is to be executed, a "ready" event is fired on this object, that gets passed a Conversation object to populate its input and run.

The queue is stored on the Dasha platform. To associate an enqueued conversation with its data, each conversation is assigned a key.

Examples

application.queue.on("ready", async (key, conversation) => { conversation.input = getInput(key); const result = await conversation.execute(); });

Sometimes, the conversation can be removed from the queue by the Dasha platform itself. In that case, a "rejected" event is fired.

application.queue.on("rejected", (key, error) => { console.log(`conversation with key ${key} was rejected`, error); });

There is an important caveat with the incoming SIP conversations. They get placed in the queue automatically, by the Dasha platform itself. To discern them from the manually-enqueued conversations, and to get the additional SIP info (e.g. the SIP user and domain of the conversation partner), the "ready" event has an extra argument of type QueuedConversationInfo.

application.queue.on("ready", (key, conversation, info) => { assert(info.sip !== undefined); conversation.input.from = `${info.fromUser}@${info.fromDomain}`; await conversation.execute(); });

Extends

Type Parameters

• TInput extends Record<string, unknown>

• TOutput extends Record<string, unknown>

Methods

length()

length(): Promise<number>

Get current queue length at the server side.

Returns

Promise<number>


push()

push(key, options?): Promise<{ jobId: string; }>

Push a new conversation into the queue.

Parameters

key

string

a conversation key that can be used to associate data

options?

after

Date

the earliest point in time the conversation can run at

before

Date

the latest point in time the conversation can run at

input

TInput

priority

number

Returns

Promise<{ jobId: string; }>

Object with internal backend jobId

Example

application.queue.push("key", { after: new Date(), before: new Date(Date.now() + 60 * 60 * 1000) });

waitUntilCurrentProcessed()

waitUntilCurrentProcessed(options?): Promise<boolean>

Parameters

options?

cancelationToken

checkPeriodInMs

number

Returns

Promise<boolean>

Found a mistake? Let us know.

Enroll in beta

Request invite to our private Beta program for developers to join the waitlist. No spam, we promise.