amelia-sendbird-desk-agent
Version:
Unofficial Desk Agent SDK for Sendbird
450 lines (449 loc) • 19 kB
TypeScript
export default class AmeliaDesk {
/**
* Main entrypoint for Gate API
*/
private DESK_API;
/**
* Main entrypoint for Gate API
*/
private GATE_API;
/**
* App ID for Desk
* (see constructor)
*/
private appId;
/**
* Region for Desk
* (see constructor)
*/
private region;
/**
* This is the information received once
* we do a login to Desk
* init(...)
*/
private deskUser;
/**
* Token from Dashbaord. You get this
* from a Login (see hate.ts) or form
* verifyDashboardToken(...) (see hate.ts)
*/
private token;
/**
* Cache all the REMOTE agents.
* See getRemoteAgents(...)
*/
private remoteAgents;
/**
* Cache for groups
*/
private groups;
/**
* Cache for ticket fields
*/
private ticketFields;
/**
* Cache for ticket field datas
*/
private ticketFieldDatas;
/**
* Cache for customer fields
*/
private customerFields;
/**
* Cache for customer field datas
*/
private customerFieldDatas;
/**
* Cache for tags
*/
private tags;
/**
* Sendbird SDK instance
*/
private sb;
/**
* Current sendbird logged user
*/
private sendbirdUser;
/**
* Channel handler for Desk
* (optional)
*/
private channelHandler;
/**
* Cache for practive chat tickets
*/
private proactiveChats;
/**
* Cache for quick replies and its categories
*/
private quickRepliesAndCategories;
/**
* Constructor
*
* @param region : string ('eu-1' for example)
* @param dashboardToken : token from Dashboard login
*/
constructor(appId: string, region: string);
/**
* Call this function right after calling the constructor.
*
* @param dashboardToken Token obtained from Dashboard when logging in.
* @param callback (error: any, token: string) Token contains a token for using with Desk.
*/
init(dashboardToken: string, callback: any): void;
/**
* Once init(...) is called, you can get your projects for Desk.
*
* @returns Projects
*/
getProjets(): any;
/**
* You can optionally connect agent to chat for listening for messages
* and ticket modifications.
*
* @param appId Your valid Sendbird App ID.
* @param callback (error: any, data: any) Data will be the information returned by Sendbird's SDK when connecting to chat.
*/
connectAgentToChat(appId: string, callback: any): void;
/**
* You can optionally set a Channel Handler for listening to
* chat events, once connected using Sendbird SDK.
*
* @param uniqueId Any string identifier you want.
* @returns null | channel handler from Sendbird SDK.
*/
addChannelHandler(uniqueId: string): any;
/**
* Gets agent according to the given app id
*
* @param appId The application ID you want to get your agent from.
*/
getAgentForAppId(appId: string): any;
/**
* Get all agents for the given project ID.
*
* @param projectId Project ID from where you want the information from.
* @param query String text to search for agents.
* @param callback (error: any, agents: Array<any>)
*/
getRemoteAgents(projectId: string, query: string, callback: any, next?: string | null): void;
/**
* Gets a detailed agent from Sendbird Desk.
*
* @param projectId The project ID from where to take agents from.
* @param agentId The agent ID you want.
* @param callback (error: any, agent: any)
*/
getAgent(projectId: string, agentId: string, callback: any): void;
/**
* Modifies any agent's connection status.
*
* @param projectId The project this agent belongs to.
* @param agentId Agent id to change
* @param newStatus 'OFFLINE' | 'ONLINE' | AWAY' as the supported connection status.
* @param callback (error: any, success: boolean)
*/
changeAgentOnlineStatus(projectId: string, agentId: string, newStatus: 'OFFLINE' | 'ONLINE' | 'AWAY', callback: any): void;
/**
* Gets tickets from Sendbird server.
*
* @param projectId Project where these tickets belong to.
* @param offset Starting index to get tickets from.
* @param ticketCount Max amount of tickets to return (100 is the maximum per call)
* @param ticketStatus Array of statuses to retrieve: 'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE'
* @param order One of the values: '-created_at' | 'created_at'
* @param agentId Agent ID for the tickets to be recovered.
* @param callback (error: any, tickets: Array<any>)
*/
getTickets(projectId: string, offset: number, ticketCount: number, ticketStatus: Array<'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE'>, order: '-created_at' | 'created_at', agentId: number, callback: any): void;
/**
* Returns a list of tickets (sorted by last creation date) according to a list of given tags and statuses.
*
* @param projectId Project ID where these tickets belong to.
* @param limit How many records you want to retrieve from the server (max 100)
* @param offset Starting numbers to retrieve tickets from.
* @param startDate Date when tickets start (YYYY-MM-DD)
* @param endDate Date when tickets end (YYYY-MM-DD)
* @param tagIds Array of TAG IDs to retrieve.
* @param statuses Array of ticket status to retrieve. Limited to: 'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE'
* @param callback (error: any, data: any)
* @param next If there are more tickets to retrieve, the server will respond will a URL to call. This URL comes in the "next" value you must send for more data. For your first request send a null value.
*/
getTicketsByTag(projectId: string, limit: number, offset: number, startDate: number, endDate: number, tagIds: Array<number>, statuses: Array<'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE'>, callback: any, next?: string | null): void;
/**
* Gets a specific ticket.
*
* @param projectId Project this ticket belongs to.
* @param ticketId Ticket id to retrieve.
* @param callback (error: any, ticket: any)
*/
getTicketById(projectId: string, ticketId: string, callback: any): void;
/**
* Gets the total amount of tickets for a given agent.
*
* @param projectId Project where this ticket belonts to.
* @param agentId Agent ID attached to this ticket ID.
* @param callback (error: any, ticket: any)
*/
getTicketCountForAgent(projectId: string, agentId: string, callback: any): void;
/**
* Gets ticket fields.
*
* @param projectId Project ID for the ticket fields to get.
* @param callback (error: any, ticketFields: Array<any>)
* @param next Send a null value (optional)
*/
getTicketFields(projectId: string, callback: any, next?: string | null): void;
/**
* Gets the data for ticket fields for a given ticket ID.
*
* @param projectId Project ID from where this ticket belongs to.
* @param ticketId Ticket ID to get its ticket fields data.
* @param callback (error: any, ticketFieldData: Array<any>)
* @param next Send a null value (optional)
*/
getTicketFieldData(projectId: string, ticketId: number, callback: any, next?: string | null): void;
/**
* Gets a list of all customer fields.
*
* @param projectId Project ID from these customer fields are.
* @param callback (error: any, customerFields: Array<any>)
* @param next Send a null value (optional)
*/
getCustomerFields(projectId: string, callback: any, next?: string | null): void;
/**
* Gets the data for customer fields for a given customer ID.
*
* @param projectId Project ID from where this customer belongs to.
* @param customerId Customer ID to get its customer fields data.
* @param callback (error: any, customerFieldDatas: Array<any>)
* @param next Send a null value (optional)
*/
getCustomerFieldData(projectId: string, customerId: number, callback: any, next?: string | null): void;
/**
* Get the messages for a given Ticket.
*
* @param ticket Ticket Object provided by Sendbird Desk.
* @param appId Application ID to get tickets from.
* @param ameliaSendbirdToken We need the tocket you received when performing loginFromDashboard(...)
* @param messageCount Amount of messages to retrieve (max. 100 per call)
* @param includeRemoved If include removed messages (true / false)
* @param callback (error: any, messages: Array<any>)
*/
getTicketMessages(ticket: any, appId: string, ameliaSendbirdToken: string, messageCount: number, includeRemoved: boolean, callback: any): void;
/**
* Creates a customer field for showing on tickets.
*
* @param projectId Project ID this customer field will be related to.
* @param description Description (optional)
* @param fieldType One of these values: 'STRING' | 'INTEGER' | 'DROPDOWN' | 'LINK'
* @param key Any unique string key.
* @param name Any name that will be shown to agents.
* @param options boolean | Array<string> - Send false if fieldType is different from DROPDOWN. Send ['any thing here', 'more here'] as options for DROPDOWN.
* @param readOnly true / false if this field will be accessible for modifications.
* @param callback (error: any, data: any)
*/
createCustomerField(projectId: string, description: string, fieldType: 'STRING' | 'INTEGER' | 'DROPDOWN' | 'LINK', key: string, name: string, options: boolean | Array<string>, readOnly: boolean, callback: any): void;
/**
* Adds data to a ticket where this customer field ID is present.
* Dropdown values are added as the content and not as any ID.
*
* @param projectId Project ID where this data will be stored into.
* @param customerId Customer ID.
* @param customerFieldId Customer Field ID.
* @param value Value to store.
* @param callback (error: any, data: any)
*/
createCustomFieldData(projectId: string, customerId: number, customerFieldId: number, value: string, callback: any): void;
/**
* Creates a ticket field for showing on tickets.
*
* @param projectId Project ID this ticket field will be related to.
* @param description Description (optional)
* @param fieldType One of these values: 'STRING' | 'INTEGER' | 'DROPDOWN' | 'LINK'
* @param key Any unique string key.
* @param name Any name that will be shown to agents.
* @param options boolean | Array<string> - Send false if fieldType is different from DROPDOWN. Send ['any thing here', 'more here'] as options for DROPDOWN.
* @param readOnly true / false if this field will be accessible for modifications.
* @param callback (error: any, data: any)
*/
createTicketField(projectId: string, description: string, fieldType: 'STRING' | 'INTEGER' | 'DROPDOWN' | 'LINK', key: string, name: string, options: boolean | Array<string>, readOnly: boolean, callback: any): void;
/**
* Adds data to a ticket field ID.
*
* @param projectId Project ID where this ticket ID belongs to.
* @param ticketId Ticket ID where this data will be stored.
* @param ticketFieldId Ticket field ID where this data will be related to.
* @param value Value to store. Dropdown data will store values, not IDs.
* @param callback (error: any, data: any)
*/
createTicketFieldData(projectId: string, ticketId: number, ticketFieldId: number, value: string, callback: any): void;
/**
* Agents are organized in groups.
* This function will get those groups.
*
* @param callback (error: any, groups: Array<any>)
* @param next Send an empty string (optional)
*/
getGroups(callback: any, next?: string): void;
/**
* Creates a TAG. These tags can be later related to tickets and perform
* searches according to these TAGS.
*
* @param projectId Project ID where this TAG will be stored into.
* @param name Name for this TAG.
* @param callback (error: any, data: any)
*/
createTag(projectId: string, name: string, callback: any): void;
/**
* TAGs can be assigned to tickets so you can perform searches based on this.
*
* @param projectId Project where this ticket and TAG will be.
* @param ticketId Ticket ID where this TAG will be related to.
* @param tagId Tag ID to relate.
* @param callback (error: any, data: any)
*/
assignTagsToTicket(projectId: string, ticketId: number, tagId: number, callback: any): void;
/**
* Gets all tags you create for Tickets.
*
* @param projectId Project ID where these tasks are from.
* @param status One of these values: 'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE'
* @param query String to filter your ticket result.
* @param callback (error: any, tags: Array<any>)
* @param next Send a null value (optional)
*/
getTags(projectId: string, status: 'INITIALIZED' | 'PROACTIVE' | 'PENDING' | 'ACTIVE' | 'CLOSED' | 'WORK_IN_PROGRESS' | 'IDLE', query: string, callback: any, next?: string | null): void;
/**
* Reopens a closed ticket.
*
* @param projectId Project ID this ticket belongs to.
* @param ticketId Ticket ID to reopen.
* @param callback (error: any, data: any)
*/
openTicket(projectId: string, ticketId: number, callback: any): void;
/**
* Set ticket to IDLE status.
*
* @param projectId Project ID this ticket belongs to.
* @param ticketId Ticket ID to set to IDLE.
* @param callback (error: any, data: any)
*/
setTicketToIdle(projectId: string, ticketId: number, callback: any): void;
/**
* Closes a ticket and sends a comment.
*
* @param projectId Project ID this ticket belongs to.
* @param ticketId Ticket ID to close.
* @param closeComment Text comment explaining why this ticket was closed.
* @param callback (error: any, data: any)
*/
closeTicket(projectId: string, ticketId: number, closeComment: string, callback: any): void;
/**
* Assigns a ticket to an Agent.
* Error is returned if this ticket was already assigned.
*
* @param projectId Project this ticket belongs to.
* @param ticketId Ticket ID to assign.
* @param agentId Agent ID to assign this ticket to.
* @param callback (error: any, data: any)
*/
assignTicketToAgent(projectId: string, ticketId: number, agentId: number, callback: any): void;
/**
* Quick replies can be organized into categories. This function will insert one.
*
* @param projectId Project ID this new category will be related to.
* @param name Name of the new category.
* @param callback (error: any, data: any)
*/
createQuickReplyCategory(projectId: string, name: string, callback: any): void;
/**
* Creates a quick reply for all agents.
*
* @param projectId project ID where this quick reply will be shown.
* @param name Name for the quick reply.
* @param message Message to show.
* @param callback (error: any, data: any)
*/
createQuickReplyToAllAgents(projectId: string, name: string, message: string, callback: any): void;
/**
* Creates a quick reply for all groups.
*
* @param projectId project ID where this quick reply will be shown.
* @param name Name for the quick reply.
* @param message Message to show.
* @param callback (error: any, data: any)
*/
createQuickReplyToGroups(projectId: string, name: string, message: string, groups: Array<number>, callback: any): void;
/**
* Creates a quick reply available to me only.
*
* @param projectId project ID where this quick reply will be shown.
* @param name Name for the quick reply.
* @param message Message to show.
* @param callback (error: any, data: any)
*/
createQuickReplyToMeOnly(projectId: string, name: string, message: string, agentId: number, categories: Array<number>, callback: any): void;
/**
* Gets all the quick replies and categories.
*
* @param projectId Project ID where this information relies on.
* @param callback (error: any, quickRepliesAndCategories: Array<any>)
* @param next Send a null value (optional)
*/
getQuickRepliesAndCategories(projectId: string, callback: any, next: string | null): void;
/**
* Simply counts available quick replies and categories.
*
* @param projectId Project ID where this information relies on.
* @param callback (error: any, data: any)
*/
getQuickReplyCount(projectId: string, callback: any): void;
/**
* Gets a list of all the tickets available for Proactive Chat.
*
* @param projectId Project ID these proactive chats belongs to.
* @param limit Ma amount of proactive chat tickets to recover (max. 100)
* @param descending true / false If the result will be in a descending order or not.
* @param callback (error: any, proactiveChats: Array<any>)
* @param next Send a null value (optional)
*/
getPractiveChatTickets(projectId: string, limit: number, descending: boolean, callback: any, next?: string | null): void;
/**
* Allows you to send a new proactive chat to users.
*
* @param projectId Project ID this proactive chat will be sent to.
* @param ticketId Ticket ID for sending this proactive chat.
* @param message Message to send to customer.
* @param callback (error: any, data: any)
*/
sendProactiveChat(projectId: string, ticketId: number, message: string, callback: any): void;
/**
* Gets all the proactive chat.
*
* @param projectId Project ID where the proactive chat is located.
*
* @param offset Starting number to get records from.
* @param totalChatsToGet Total chat rows to get.
* @param callback (error: any, proactiveChats: Array<any>)
* @param nextUrl If you want more information, send this URL Sendbird sends you in the previous response. This continues getting more information.
*/
getProactiveChats(projectId: string, offset: number, totalChatsToGet: number, callback: any, nextUrl: string | null): void;
/**
* TODO
*/
private getAssignmentLogs;
/**
* TODO
*/
private getRealTimeMonitoring;
/**
* TODO
*/
private getPerformanceReport;
private getToken;
private initSendbird;
private connectToSendbird;
}