Home
/
Desk
/
Android

Ticket

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

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, you can retrieve the information of the ticket and its group channel in the ticket.getChannel() through the 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.

Light Color Skin
Copy
Ticket.create(TICKET_TITLE, USER_NAME, new Ticket.CreateHandler() {
    @Override
    public void onResult(Ticket ticket, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        // The ticket is created. Agents and customers can chat with each other by sending a message through the ticket.getChannel(), sendUserMessage() or sendFileMessage().
    }
});

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.

Light Color Skin
Copy
Map<String, String> customFields = new HashMap<>();
customFields.put("product", "desk");
customFields.put("line", "14");
customFields.put("select", "option2");

Ticket.create(TICKET_TITLE, USER_NAME,
    GROUP_KEY,
    customFields,
    PRIORITY,
    RELATED_CHANNEL_URLS,
    BOT_KEY,
    new Ticket.CreateHandler() {
        @Override
        public void onResult(Ticket ticket, SendBirdException e) {
            if (e != null) {
                // Handle error.
            }

            // The ticket is created with parameters.
        }
    }
);

List of arguments

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.

customFields

[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 identifier of a specific bot. The bot with the specified bot key will be the assignee of the created ticket.


Retrieve a list of tickets

Use the Ticket.getOpenedList() and Ticket.getClosedList() to retrieve a list of the current customer's open and closed tickets.

Note: Only ten tickets can be retrieved per request in descending order of the message creation time.

getOpenedList()
getClosedList()
Light Color Skin
Copy
Ticket.getOpenedList(OFFSET, new Ticket.GetOpenedListHandler() {
    @Override
    public void onResult(List<Ticket> tickets, boolean hasNext, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        // offset += tickets.size(); for the next tickets.
        // Implement your code to display the ticket list.
    }
});
Light Color Skin
Copy
Ticket.getClosedList(OFFSET, new Ticket.GetClosedListHandler() {
    @Override
    public void onResult(List<Ticket> tickets, boolean hasNext, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        // offset += tickets.size(); for the next tickets.
        // Implement your code to display the ticket list.
    }
});

You can filter tickets by adding a ticket field as a search filter to the getOpenedList() and getClosedList(). Tickets that have a value of the selected field will appear on the ticket list.

Light Color Skin
Copy
Map<String, String> customFieldFilter = new HashMap<>();
customFieldFilter.put("subject", "doggy_doggy");

Ticket.getOpenedList(OFFSET, customFieldFilter, new Ticket.GetOpenedListHandler() {
    @Override
    public void onResult(List<Ticket> tickets, boolean hasNext, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        // offset += tickets.length; for the next tickets.
        // Implement your code to display the ticket list.
        List<Ticket> openedTicket = tickets;
        ...
    }
});

Retrieve a ticket

You can retrieve a specific ticket using its channel URL.

Light Color Skin
Copy
Ticket.getByChannelUrl(channel.getUrl(), new Ticket.GetByChannelUrlHandler() {
    @Override
    public void onResult(Ticket ticket, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        ...
    }
});

Display open ticket count

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

Light Color Skin
Copy
Ticket.getOpenCount(new Ticket.GetOpenCountHandler() {
    @Override
    public void onResult(int count, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

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

Close a ticket

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

Light Color Skin
Copy
ticket.close(CLOSE_COMMENT, new Ticket.CloseHandler() {
    @Override
    public void onResult(Ticket ticket, SendBirdException e) {
        if (e != null) {
            // Handle error
        }

        // Implement your code for the UI of the closed ticket.
    }
});

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


Reopen a closed ticket

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

Light Color Skin
Copy
ticket.reopen(new Ticket.ReopenHandler() {
    @Override
    public void onResult(Ticket ticket, SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        ...
    }
});

Cancel assignment of a ticket

Use the ticket.cancel() method to cancel the assignment of a specific ticket. When a ticket is unassigned from the current assignee, the ticket's status changes to Pending and it is assigned to an available live agent in the current or a specified team in accordance with the auto ticket routing function.

Light Color Skin
Copy
ticket.cancel(GROUP_KEY, new Ticket.CancelHandler() {
    @Override
    public void onResult(final Ticket ticket, final SendBirdException e) {
        if (e != null) {
            // Handle error.
        }
        // The assignment of the ticket has been canceled.
    }
});
ArgumentTypeDescription

GROUP_KEY

string

Specifies the unique key of a specific team to transfer the ticket.