Desk SDKs JavaScript v1
Desk SDKs JavaScript
Desk SDKs
JavaScript
Version 1

Ticket

Copy link

Ticket refers to a unit of a customer's inquiry, forming the basis of all features and functionalities of Sendbird Desk. On this page, you can find how to create, retrieve, close, and display tickets on a client app.

Note: Every ticket has a corresponding group channel in the Chat SDK because the messages within a ticket are managed by Sendbird Chat.


Create a ticket

Copy link

Implement the Ticket.create() method to create a new ticket on the Desk server either before or after a customer's initial message. Once created, use ticket.channel to retrieve the information of the ticket and its channel as a callback from the server. When a customer sends the first message, the ticket is assigned to an available agent by the Desk server while messages are sent and received through the Chat SDK.

Ticket.create(TICKET_TITLE, USER_NAME, (ticket, error) => {
    if (error) {
        // Handle error.
    }

    // The ticket.channel property indicates the group channel object within the ticket.
});

Note: Until a customer sends the first message, agents can't see the ticket on the Sendbird Dashboard.

You can also append additional information like a ticket's priority or related channel URLs by passing several arguments to the corresponding parameters.

List of arguments

Copy link
Ticket.create(TICKET_TITLE, USER_NAME, GROUP_KEY, CUSTOM_FIELDS, PRIORITY, RELATED_CHANNEL_URLS,BOT_KEY, (ticket, error) => {
    if (error) {
        // Handle error.
    }

    // The ticket.channel property indicates the group channel object within the ticket.
});
Arguments
RequiredTypeDescription

TICKET_TITLE

string

Specifies the title of the ticket.

USER_NAME

string

Specifies the name of a user who submits or receives the ticket.

OptionalTypeDescription

GROUP_KEY

string

Specifies the unique key of a team for the assignment of the ticket.

CUSTOM_FIELDS

[String: String]

Specifies additional information of the ticket that consists of field and its values. Only the field already registered in Settings > Ticket fields on your dashboard can be used.

PRIORITY

string

Specifies the priority value of the ticket. Higher values stand for higher priority. Acceptable values are LOW, MEDIUM, HIGH and URGENT.

RELATED_CHANNEL_URLS

array

Specifies one or more group channel URL and its channel name in Sendbird Chat that are relevant to this ticket. Up to three related channels can be added per ticket.

BOT_KEY

string

Specifies the unique key of a specific bot. The bot with the specified key will be the assignee of the created ticket.


Retrieve a list of tickets

Copy link

You can retrieve a filtered ticket list of the customer using various parameters. Only ten tickets can be retrieved per request in descending order of the message creation time. If you're using Desk JavaScript SDK version 1.0.23 or higher, refer to the code below on how to use parameters to retrieve a list of tickets.

const params = {
    group: 'my_group',
    // Add any parameters you wish to use.
    // offset: integer.
    // customFieldFilter: object.
    // ticket status: string.
};
Ticket.getList(params, (tickets, error) => {
        if (error) {
        // Handle error.
    }

    const ticketsFromMyGroup = tickets;
    // offset += tickets.length; for the next tickets.
    // Implement your code to display the ticket list.
})

If you're using Desk JavaScript SDK version 1.0.22 or below, refer to the code below on how to retrieve a list of either opened or closed tickets of the customer. Only ten tickets can be retrieved per request in descending order of the message creation time.

Note: To use the getAllTickets method, the Desk JavaScript SDK version should be 1.0.21 or higher.

getAllTickets()getOpenedList()getClosedList()
Ticket.getAllTickets(OFFSET, (tickets, error) => {
    if (error) {
        // Handle error.
    }

    const tickets = closedTickets;
    // offset += tickets.length; for the next tickets.
    // Implement your code to display the ticket list.
});

You can also use ticket fields as search filters to only display tickets that have the value of a selected field on the ticket list.

const customFieldFilter = {'subject' : 'doggy_doggy'};
Ticket.getOpenedList(OFFSET, customFieldFilter, (openedTickets, error) => {
    if (error) {
        // Handle error.
    }

    const tickets = openedTickets;
    // offset += tickets.length; for the next tickets.
    // Implement your code to display the ticket list.
});

Retrieve a ticket

Copy link

You can retrieve a specific ticket using its channel URL.

Ticket.getByChannelUrl(CHANNEL_URL, (ticket, error) => {
    if (error) {
        // Handle error.
    }

    ...
});

If you are using the SDK version 1.0.22 or before, getByChannelUrl returned a cached data of the ticket. This has caused glitches with the ticket state updated from Sendbird Dashboard, so we removed the caching by default. If you wish to use the cached data, set the second parameter cachingEnabled to true.

const cachingEnabled = true;
Ticket.getByChannelUrl(CHANNEL_URL, cachingEnabled, (ticket, error) => {
    if (error) {
        // Handle error.
    }

    ...
});

Display open ticket count

Copy link

Use the Ticket.getOpenCount() to display the number of open tickets on a client app.

Ticket.getOpenCount((count, error) => {
    if (error) {
        // Handle error.
    }

    const numberOfOpenTickets = count;
    // Implement your code with the value of the "count" parameter.
});

Close a ticket

Copy link

To allow your customers to directly close a ticket from their app, use the ticket.close() method.

ticket.close(CLOSE_COMMENT, (ticket, error) => {
    if (error) {
        // Handle error.
    }

    ...
});

Note: Only active and idle tickets can be closed by a customer.


Reopen a closed ticket

Copy link

Use the closedTicket.reopen() method to reopen a closed ticket from a client app.

Note: Tickets that have been closed more than 20 days prior to the request can't be reopened.

closedTicket.reopen((openTicket, error) => {
    if (error) {
        // Handle error.
    }

    // Implement your code to update the ticket list using the result object in the "openTicket" parameter.
});