Events

During its lifetime, your application will receive events sent from Deskpro. These events can be global events, system or user events or events specific to the host container component.

In addition to classifying them according to their scope and context, events can be classified according to how their handlers are invoked into Request-Response and Fire-And-Forget events:

  • Request-Response events require their handler to send a response back by invoking a response callback. The Deskpro UI will wait (but not block) for a response from your application and will act according to that. For example, in case of a 'context.ticket.reply' event if your applications decides to respond with the message { allowReply: false } the reply will not go through

  • Fire-And-Forget events do not require a response from your application and are usually sent as notifications that something failed or was successful, for instance an event 'context.ticket.reply-success' will be sent after the reply is processed on the server-side.

Subscribing to events

In order to receive events, your application must subscribe to them. At the moment the subscription, once acquired can not be cancelled. You use the application client object to subscribe, passing an eventName and a handler function:

const { dpapp } = this.props;
dpapp.subscribe(eventName, handler);

If you are subscribing to a Request-Response event then your handler must have the following signature:

  /**
   * @param {function} response callback that must be invoked with your response
   * @param {object} data the event payload
   * @returns null
   */
  handler(response, data)

If you are subscribing to a Fire-And-Forget event then your handler must have the following signature:

  /**
   * @param {object} data the event payload
   * @returns null
   */
  handler(data)

Ticket Tab Events

These events are available whenever your application runs inside a Ticket UI Tab.

context.ticket.reply

Fired when the Agent clicks the reply button.

Handler invocation type: request-response

Event payload:

/**
 * @typedef {Object} ContextTicketReplyPayload
 *
 * @property {string} ticket_id the ticket id
 * @property {object} meta information about the ticket
 */

Response type:

/**
 * @typedef {Object} ContextTicketReplyResponse
 *
 * @property {boolean} allowReply false when reply should not be allowed
 * @property {string} [reason] an optional string with a human readable message giving more details about the choice of allowReply
 */

Usage examples

Disabling ticket replies:

 const { dpapp } = this.props;
 dpapp.subscribe('context.ticket.reply', (response, data) => {
  response({allowReply: false, reason: 'ticket replies are disabled'})
 });

context.ticket.reply-success

Fired after the ticket reply has been successfully processed

Handler invocation type: request-response

Event payload:

/**
 * @typedef {Object} ContextTicketReplySuccessPayload
 *
 * @property {string} message the reply message
 */

context.ticket.update-success

Fired after the server-side has successfully processed a ticket update. This event is triggered whenever a property changes in the Deskpro UI

Handler invocation type: request-response

Event payload:

/**
 * @typedef {Object} ContextTicketUpdateSuccessPayload
 *
 * @property {String} status the ticket status
 * @property {Number} urgency urgency level
 * @property {object} api_data all the data loaded via the api for this ticket
 */

Last updated