Skip to content

Commit c64f792

Browse files
committed
v1.0.11
1 parent be9b692 commit c64f792

File tree

5 files changed

+136
-113
lines changed

5 files changed

+136
-113
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change Log
22

3+
### v1.0.11(Feb 6, 2020)
4+
5+
- TypeScript d.ts interface fix.
6+
37
### v1.0.10(Jan 3, 2020)
48

59
- Added `setCustomFields(customFields, callback)` in `Ticket`.

README.md

Lines changed: 117 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
SendBird Desk SDK Integration Guide for JavaScript
2-
===========
1+
# SendBird Desk SDK Integration Guide for JavaScript
2+
33
SendBird Desk is a chat customer service platform built on SendBird SDK and API.
44

55
Desk JavaScript SDK provides customer-side integration on your own application, so you can easily implement **ticketing system with chat inquiry**. Desk JavaScript SDK requires **SendBird JavaScript SDK 3.0.55 or higher**.
66

77
## Table of Contents
88

9-
1. [Installation](#installation)
10-
1. [Authentication](#authentication)
11-
1. [Setting customer customFields](#setting-customer-customfields)
12-
1. [Creating a new ticket](#creating-a-new-ticket)
13-
1. [Count of opened tickets](#count-of-opened-tickets)
14-
1. [Loading ticket list](#loading-ticket-list)
15-
1. [Confirming end of chat](#confirming-end-of-chat)
16-
1. [Ticket Feedback](#ticket-feedback)
17-
1. [Handling ticket event](#handling-ticket-event)
18-
1. [Rich messages](#rich-messages)
19-
9+
- [SendBird Desk SDK Integration Guide for JavaScript](#sendbird-desk-sdk-integration-guide-for-javascript)
10+
- [Table of Contents](#table-of-contents)
11+
- [Installation](#installation)
12+
- [Authentication](#authentication)
13+
- [Setting customer customFields](#setting-customer-customfields)
14+
- [Creating a new ticket](#creating-a-new-ticket)
15+
- [Count of opened tickets](#count-of-opened-tickets)
16+
- [Loading ticket list](#loading-ticket-list)
17+
- [Handling ticket event](#handling-ticket-event)
18+
- [Rich messages](#rich-messages)
19+
- [Confirm end of chat](#confirm-end-of-chat)
20+
- [Reopen a closed ticket](#reopen-a-closed-ticket)
21+
- [Ticket Feedback](#ticket-feedback)
22+
- [URL preview](#url-preview)
23+
2024
## Installation
2125

2226
Before setup, you need to get SendBird App ID at [SendBird Dashboard](https://dashboard.sendbird.com). For using Desk solution, you may upgrade the plan. For more information, please contact [sales team](https://sendbird.com/contact-sales).
2327

2428
Installing the Desk SDK is straightforward if you're familiar with npm. Run the following command at the project path.
29+
2530
```
2631
~$ cd /path/to/your-project
2732
~$ npm install --save sendbird-desk
@@ -31,39 +36,42 @@ Installing the Desk SDK is straightforward if you're familiar with npm. Run the
3136
3237
> Basically SendBird Desk SDK is a plugin to handle tickets. You have to handle chat messages through SendBird SDK. Ticket is newly introduced in SendBird Desk SDK to support customer service ticketing system. Every ticket will be assigned to the appropriate agents and it will be mapped to a SendBird SDK channel, so you can implement real-time messaging on tickets with SendBird SDK.
3338
34-
3539
## Authentication
3640

3741
Connecting to SendBird platform via SendBird SDK is essential for real-time messaging. The official guide to SendBird SDK authentication is [here](https://docs.sendbird.com/android#authentication_2_authentication).
3842
Authentication in SendBird Desk is done by calling `SendBirdDesk.authenticate()`. The following is an example for SendBird SDK connection and SendBird Desk SDK authentication.
43+
3944
```js
40-
const sb = new SendBird({ appId : 'YOUR_APP_ID' });
45+
const sb = new SendBird({ appId: "YOUR_APP_ID" });
4146
sb.connect(userId, accessToken, (res, err) => {
42-
if(err) throw err;
43-
SendBirdDesk.init(SendBird);
44-
SendBirdDesk.authenticate(userId, accessToken, (res, err) => {
45-
if(err) throw err;
46-
// Now you can use Desk SDK later on
47-
});
47+
if (err) throw err;
48+
SendBirdDesk.init(SendBird);
49+
SendBirdDesk.authenticate(userId, accessToken, (res, err) => {
50+
if (err) throw err;
51+
// Now you can use Desk SDK later on
52+
});
4853
});
4954
```
50-
55+
5156
Now your customers are ready to create tickets and start inquiry with your agents!
5257

5358
## Setting customer customFields
5459

5560
Customer information could be kept in `customFields`. `setCustomerCustomFields()` in `SendBirdDesk` lets the SDK set the `customFields` of the current customer. The `customFields` columns should be defined in SendBird Dashboard beforehand. Otherwise, the setting would be ignored.
61+
5662
```js
57-
SendBirdDesk.setCustomerCustomFields({
58-
gender: 'male',
59-
age: 20
60-
},
61-
err => {
62-
if (!err) {
63-
// customer's customFields is rightly set
64-
// (or a certain key could get ignored if the key is not defined yet)
65-
}
66-
});
63+
SendBirdDesk.setCustomerCustomFields(
64+
{
65+
gender: "male",
66+
age: 20
67+
},
68+
err => {
69+
if (!err) {
70+
// customer's customFields is rightly set
71+
// (or a certain key could get ignored if the key is not defined yet)
72+
}
73+
}
74+
);
6775
```
6876

6977
## Creating a new ticket
@@ -82,57 +90,66 @@ Ticket.create(ticketTitle, userName, (ticket, err) =>
8290
`Ticket.create()` has 2 more parameters `groupKey` and `customFields`. The values could be evaluated when a ticket is created though it's used only in Dashboard currently. `groupKey` is the key of an agent group so that the ticket is assigned to the agents in that group. `customFields` holds customizable data for the individual ticket. The below is an example.
8391

8492
```js
85-
Ticket.create(ticketTitle, userName,
86-
'cs-team-1', // groupKey
87-
{
88-
'text': 'hello',
89-
'number': 14,
90-
'select': 'option2'
91-
}, // customFields
92-
(ticket, err) => {
93+
Ticket.create(
94+
ticketTitle,
95+
userName,
96+
"cs-team-1", // groupKey
97+
{
98+
text: "hello",
99+
number: 14,
100+
select: "option2"
101+
}, // customFields
102+
(ticket, err) => {
93103
// Ticket is created with groupKey 'cs-team-1' and customFields.
94-
});
104+
}
105+
);
95106
```
96107

97108
> Note: each key in `customFields` should be preregistered in Dashboard. Otherwise, the key would be ignored.
98109
99110
## Count of opened tickets
111+
100112
When you need to display opened ticket count in your application, use `Ticket.getOpenCount()`.
113+
101114
```js
102115
Ticket.getOpenCount((res, err) => {
103-
const count = res;
104-
// do something with the value
116+
const count = res;
117+
// do something with the value
105118
});
106119
```
107120

108121
## Loading ticket list
122+
109123
Retrieving ticket list is essential for inbox. SendBird Desk SDK provides `Ticket.getOpenedList()` and `Ticket.getClosedList()` to get the list of open/closed ticket. Open ticket list and closed ticket list can be loaded as below:
124+
110125
```js
111126
Ticket.getOpenedList(offset, (res, err) => {
112-
const tickets = res;
113-
// offset += tickets.length; for the next tickets.
114-
// here is to display tickets on inbox.
127+
const tickets = res;
128+
// offset += tickets.length; for the next tickets.
129+
// here is to display tickets on inbox.
115130
});
116131
```
117132

118133
```js
119134
Ticket.getClosedList(offset, (res, err) => {
120-
const tickets = res;
121-
// offset += tickets.length; for the next tickets.
122-
// here is to display tickets on inbox.
135+
const tickets = res;
136+
// offset += tickets.length; for the next tickets.
137+
// here is to display tickets on inbox.
123138
});
124139
```
125140

126141
> Note: Once you set `customFields` to tickets, you can put `customFieldFilter` to `getOpenedList()` and `getClosedList()` in order to filter the tickets by `customFields` values.
127142
128143
## Handling ticket event
144+
129145
SendBird Desk SDK uses predefined AdminMessage custom type which can be derived by calling `message.customType`. Custom type for Desk AdminMessage is set to `SENDBIRD_DESK_ADMIN_MESSAGE_CUSTOM_TYPE`. And there are sub-types which indicate ticket events: assign, transfer, and close. Each event type is located in `message.data` which looks like below.
130146

131147
```js
132148
{
133149
"type": "TICKET_ASSIGN" // "TICKET_TRANSFER", "TICKET_CLOSE"
134150
}
135151
```
152+
136153
You can check out these messages in `ChannelHandler.onMessageReceived()`.
137154

138155
## Rich messages
@@ -142,7 +159,7 @@ Rich message is a special message that holds custom content. You can distinguish
142159
- **`Confirm end of chat`** message notifies that the agent sent a confirm-end-of-chat request. When the user agrees with the closure, the ticket would be closed.
143160
- **`URL preview`** message contains web URL which is filled with image and description.
144161

145-
### Confirm end of chat
162+
## Confirm end of chat
146163

147164
Confirm end of chat message is initiated from the agent to inquire closure of ticket. The message has 3 states which are `WAITING`, `CONFIRMED`, `DECLIEND`. When agent sends confirm end of chat message, its state is set to `WAITING`. Customer can answer to the inquiry as `YES` or `NO` which leads to `CONFIRMED` state and `DECLINED` state accordingly. You can check the state by looking `message.data`. The format looks like below:
148165

@@ -159,29 +176,39 @@ Once customer replies to the inquiry, the message would be updated. `SendBirdDes
159176

160177
```js
161178
channelHandler.onMessageUpdated = (channel, message) => {
162-
SendBirdDesk.Ticket.getByChannelUrl(channel.url, (ticket, err) => {
163-
if(err) throw err;
164-
let data = JSON.parse(message.data);
165-
const isClosureInquired = (data.type === SendBirdDesk.Message.DataType.TICKET_INQUIRE_CLOSURE);
166-
if(isClosureInquired) {
167-
const closureInquiry = data.body;
168-
switch(closureInquiry.state) {
169-
case SendBirdDesk.Message.ClosureState.WAITING:
170-
// do something on WAITING
171-
break;
172-
case SendBirdDesk.Message.ClosureState.CONFIRMED:
173-
// do something on CONFIRMED
174-
break;
175-
case SendBirdDesk.Message.ClosureState.DECLIND:
176-
// do something on DECLIND
177-
break;
178-
}
179-
}
180-
});
181-
}
179+
SendBirdDesk.Ticket.getByChannelUrl(channel.url, (ticket, err) => {
180+
if (err) throw err;
181+
let data = JSON.parse(message.data);
182+
const isClosureInquired = data.type === SendBirdDesk.Message.DataType.TICKET_INQUIRE_CLOSURE;
183+
if (isClosureInquired) {
184+
const closureInquiry = data.body;
185+
switch (closureInquiry.state) {
186+
case SendBirdDesk.Message.ClosureState.WAITING:
187+
// do something on WAITING
188+
break;
189+
case SendBirdDesk.Message.ClosureState.CONFIRMED:
190+
// do something on CONFIRMED
191+
break;
192+
case SendBirdDesk.Message.ClosureState.DECLIND:
193+
// do something on DECLIND
194+
break;
195+
}
196+
}
197+
});
198+
};
199+
```
200+
201+
## Reopen a closed ticket
202+
203+
The closed ticket could be reopened with `reopen()` function in `Ticket`.
204+
205+
```js
206+
closedTicket.reopen((openTicket, err) => {
207+
// update the ticket list here
208+
});
182209
```
183210

184-
### Ticket Feedback
211+
## Ticket Feedback
185212

186213
If Desk satisfaction feature is on, a message would come after closing the ticket. The message is for getting customer feedback including score and comment. The data of satisfaction form message looks like below.
187214

@@ -200,26 +227,26 @@ Once the customer inputs the score and the comment, the data could be submitted
200227

201228
```js
202229
channelHandler.onMessageUpdated = (channel, message) => {
203-
SendBirdDesk.Ticket.getByChannelUrl(channel.url, (ticket, err) => {
204-
if(err) throw err;
205-
let data = JSON.parse(message.data);
206-
const isFeedbackMessage = (data.type === SendBirdDesk.Message.DataType.TICKET_FEEDBACK);
207-
if(isFeedbackMessage) {
208-
const feedback = data.body;
209-
switch(feedback.state) {
210-
case SendBirdDesk.Message.FeedbacState.WAITING:
211-
// do something on WAITING
212-
break;
213-
case SendBirdDesk.Message.FeedbacState.CONFIRMED:
214-
// do something on CONFIRMED
215-
break;
216-
}
217-
}
218-
});
219-
}
230+
SendBirdDesk.Ticket.getByChannelUrl(channel.url, (ticket, err) => {
231+
if (err) throw err;
232+
let data = JSON.parse(message.data);
233+
const isFeedbackMessage = data.type === SendBirdDesk.Message.DataType.TICKET_FEEDBACK;
234+
if (isFeedbackMessage) {
235+
const feedback = data.body;
236+
switch (feedback.state) {
237+
case SendBirdDesk.Message.FeedbacState.WAITING:
238+
// do something on WAITING
239+
break;
240+
case SendBirdDesk.Message.FeedbacState.CONFIRMED:
241+
// do something on CONFIRMED
242+
break;
243+
}
244+
}
245+
});
246+
};
220247
```
221248

222-
### URL preview
249+
## URL preview
223250

224251
To send URL preview message, you should send a text message with URL, extract preview data, and update it with the preview data. Use `channel.updateUserMessage(messageId, text, messageData, customType, callback)` for the update operation. The format of `messageData` looks like below:
225252

@@ -237,4 +264,4 @@ To send URL preview message, you should send a text message with URL, extract pr
237264
}
238265
```
239266

240-
You may get the preview message in `ChannelHandler.onMessageUpdated()` or `channel.getPreviousMessagesByTimestamp()` for URL preview rendering.
267+
You may get the preview message in `ChannelHandler.onMessageUpdated()` or `channel.getPreviousMessagesByTimestamp()` for URL preview rendering.

SendBird.Desk.d.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
2-
* Type Definitions for SendBird Desc SDK v1.0.10
2+
* Type Definitions for SendBird Desc SDK v1.0.11
33
* homepage: https://sendbird.com/
44
*/
5-
export = SendBirdDesk;
6-
export as namespace SendBirdDesk;
5+
export default SendBirdDeskStatic;
76

87
interface SendBirdDeskStatic {
98
version: string;
@@ -46,14 +45,7 @@ declare namespace SendBirdDesk {
4645
create(title: string, name: string, callback: TicketCallback): void;
4746
create(title: string, name: string, groupKey: string, callback: TicketCallback): void;
4847
create(title: string, name: string, groupKey: string, customFields: object, callback: TicketCallback): void;
49-
create(
50-
title: string,
51-
name: string,
52-
groupKey: string,
53-
customFields: object,
54-
priority: TicketPriority,
55-
callback: TicketCallback
56-
): void;
48+
create(title: string, name: string, groupKey: string, customFields: object, priority: TicketPriority, callback: TicketCallback): void;
5749
getOpenCount(callback: Callback): void;
5850
getByChannelUrl(channelUrl: string, callback: TicketCallback): void;
5951
getOpenedList(offset: number, callback: TicketArrayCallback): void;
@@ -66,18 +58,18 @@ declare namespace SendBirdDesk {
6658
new (json: object): TicketInstance;
6759
}
6860
enum TicketStatus {
69-
INITIALIZED = 'INITIALIZED',
70-
PROACTIVE = 'PROACTIVE',
71-
UNASSIGNED = 'UNASSIGNED',
72-
ASSIGNED = 'ASSIGNED',
73-
OPEN = 'OPEN',
74-
CLOSED = 'CLOSED'
61+
INITIALIZED = "INITIALIZED",
62+
PROACTIVE = "PROACTIVE",
63+
UNASSIGNED = "UNASSIGNED",
64+
ASSIGNED = "ASSIGNED",
65+
OPEN = "OPEN",
66+
CLOSED = "CLOSED"
7567
}
7668
enum TicketPriority {
77-
URGENT = 'URGENT',
78-
HIGH = 'HIGH',
79-
MEDIUM = 'MEDIUM',
80-
LOW = 'LOW'
69+
URGENT = "URGENT",
70+
HIGH = "HIGH",
71+
MEDIUM = "MEDIUM",
72+
LOW = "LOW"
8173
}
8274
interface TicketInstance {
8375
id: string;

SendBird.Desk.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sendbird-desk",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "SendBird Desk SDK Integration Guide for JavaScript =========== SendBird Desk is a chat customer service platform built on SendBird SDK and API.",
55
"main": "SendBird.Desk.min.js",
66
"scripts": {

0 commit comments

Comments
 (0)