Desk / JavaScript
Home
/
Desk
/
JavaScript

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

First, a SendBirdDesk instance must be initialized when launching a client app. Pass the SendBird instance that is already initialized by the APP_ID of your Sendbird application in the dashboard. However, if you initiate the SendBirdDesk again with a SendBird instance initiated by a different APP_ID, all existing Desk-related data in the client app will be cleared.

Light Color Skin
Copy
// Initialize SendBirdDesk instance to use APIs in your app.
SendBirdDesk.init(SendBird);

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 authenticate() method with their user IDs. 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.
const sb = new SendBird({ appId: APP_ID });
sb.connect(USER_ID, ACCESS_TOKEN, (user, error) => {
    if (error) {
        // Handle error.
    }
 
    SendBirdDesk.init(SendBird);
    SendBirdDesk.authenticate(USER_ID, ACCESS_TOKEN, (user, error) => {
        if (error) {
            // Handle error.
        }

        // SendBirdDesk is now initialized,
        // and the customer is authenticated and connected to Sendbird server.
        ...
    });
    
    ...
});

Step 3: Create a ticket

Implement the Ticket.create() 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 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
Ticket.create(TICKET_TITLE, USER_NAME, (ticket, error) => {
    if (error) {
        // 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().
    // The ticket.channel property indicates the group channel object within the ticket.
    ...
});