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.

example running enqueued conversations

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.

example conversation rejection

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.

example using SIP data in a conversation

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

Type parameters

NameType
TInputRecord<string, unknown>
TOutputRecord<string, unknown>

Hierarchy

  • EventEmitter<{ error: [error: Error] ; ready: [key: string, conv: QueuedConversation<TInput, TOutput>, info: QueuedConversationInfo] ; rejected: [key: string, error: ConversationRejectedError] ; timeout: [key: string] }>

    ConversationQueue

Methods

length

length(): Promise<number>

Get current queue length at the server side.

Returns: Promise<number>


push

push(key: string, options?: { after?: Date ; before?: Date ; priority?: number }): Promise<{ jobId: string }>

Push a new conversation into the queue.

example enqueue a conversation to within an hour

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

Parameters:

NameTypeDescription
keystringa conversation key that can be used to associate data
options?object-
options.after?Datethe earliest point in time the conversation can run at
options.before?Datethe latest point in time the conversation can run at
options.priority?number-

Returns: Promise<{ jobId: string }>

Object with internal backend jobId


waitUntilCurrentProcessed

waitUntilCurrentProcessed(options?: { cancelationToken?: CancelToken ; checkPeriodInMs?: number }): Promise<boolean>

Parameters:

NameType
options?object
options.cancelationToken?CancelToken
options.checkPeriodInMs?number

Returns: Promise<boolean>

Found a mistake? Email us, and we'll send you a free t-shirt!

Enroll in beta

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