Desk SDKs iOS v1
Desk SDKs iOS
Desk SDKs
iOS
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 SBDSKTicket.createTicket() 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.

SBDSKTicket.createTicket(with: TICKET_TITLE, userName: USER_NAME) { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }

    // The ticket is created. Agents and customers can chat with each other by sending a message through the ticket.channel.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.

var customFields = [String: String]()
customFields["product"] = "desk"
customFields["line"] = "14"
customFields["select"] = "option2"

SBDSKTicket.createTicket(with: TICKET_TITLE, userName: USER_NAME, groupKey: "cs-team-1", customFields: customFields, priority: PRIORITY, relatedChannels: RELATED_CHANNEL_URLS) { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }

    // The ticket is created with the specified parameters.
}

List of arguments

Copy link
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.


Retrieve a list of tickets

Copy link

Use the SBDSKTicket.getOpenedList() and SBDSKTicket.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()
SBDSKTicket.getOpenedList(withOffset: OFFSET) { (tickets, hasNext, error) in
    guard error == nil else {
        // 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.

let customFieldFilter = ["subject": "doggy_doggy"]

SBDSKTicket.getOpenedList(withOffset: OFFSET, customFieldFilter: CUSTOM_FIELD_FILTER) { (tickets, hasNext, error) in
    guard error == nil else {
        // Handle error.
    }

    // 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.

SBDSKTicket.getByChannelUrl(channel.channelURL) { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }
    ...
}

Display open ticket count

Copy link

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

SBDSKTicket.getOpenCount { (count, error) in
    guard error == nil else {
        // Handle error.
    }

    // 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 SBDSKTicket.close() method.

ticket.close(withComment: closeComment) { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }

    // Implement your code to close a ticket.
}

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


Reopen a closed ticket

Copy link

Use the ticket.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.

ticket.reopen { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }

    ...
}