Home
/
Desk
/
iOS

Create your first ticket

Once the Desk SDK is installed into your client app, you can now create a ticket that indicates a customer inquiry and where an agent and a customer can chat with each other. Follow the step-by-step instructions below to create your first ticket.


Step 1: Initialize the Desk SDK

A SBDSKMain instance must be initialized when launching a client app. Call the SBDMain.initWithApplicationId() and SBDSKMain.initializeDesk() methods within the applicationDidFinishLaunching(). The initWithApplicationId() should be called first by the APP_ID of your Sendbird application in the dashboard. However, if you initiate the SBDSKMain again with a SBDMain instance initiated by a different APP_ID, all existing Desk-related data in the client app will be cleared.

Light Color Skin
Copy
// Initialize SBDSKMain instance to use APIs in your app.
class AppDelegate: UIApplicationDelegate {
    func applicationDidFinishLaunching(_ application: UIApplication) {
        SBDMain.initWithApplicationId(APP_ID)
        SBDSKMain.initializeDesk()
    }
}

Note: Built with Sendbird Chat SDK, Sendbird Desk SDK is a plugin that handles customer inquiries through tickets. Messages within tickets are dealt with by Sendbird Chat platform, and every ticket is mapped to a group channel in Sendbird Chat. Because of this interaction, the same APP_ID should be used for both Desk and Chat SDKs.


Step 2: Authenticate a customer

If a customer comes from Sendbird Chat platform, authenticate them using the SBDMain.connect() and the SBDSKMain.authenticate() method with their user ID. If a customer comes from social media such as Instagram or Facebook, they are automatically registered in the dashboard with their social media accounts without any authentication process.

Light Color Skin
Copy
// The USER_ID below should be unique to your Sendbird application.
SBDMain.connect(withUserId: USER_ID, accessToken: ACCESS_TOKEN) { (user, error) in
    guard error == nil else {
        // Handle error.
    }
    
    // Use the same user ID and access token used in the SBDMain.connect().
    SBDSKMain.authenticate(withUserId: USER_ID, accessToken: ACCESS_TOKEN) { (error) in
        guard error == nil else {
            // Handle error.
        }
        
        // SendBirdDesk is now initialized, 
        // and the customer is authenticated and connected to Sendbird server.
        ...
    }
}

Step 3: Create a ticket

Implement the SBDSKTicket.createTicket() method to create a new ticket either before or after the customer’s initial message. Once a ticket is successfully created in the Desk server, you can access the ticket and its channel in the ticket.channel through the callback from the server. Until a customer sends the first message, agents can’t see the ticket in the dashboard. When a conversation starts, 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
SBDSKTicket.createTicket(withTitle: TITLE, userName: USER_NAME) { (ticket, error) in
    guard error == nil else {
        // Handle error.
    }
    
    // The ticket is created. 
    // The customer and agents can chat with each other by sending a message through the ticket.channel.sendUserMessage() or sendFileMessage().
    ...
}