votcore
Version:
Vot Kit for Valensas Bots
301 lines (300 loc) • 9.03 kB
TypeScript
import 'moment/locale/tr';
import { Card, ChannelClient, ChannelClientInterface, Context, Conversation, Message, User, VotClient } from './../models';
import { ChannelMessage, ChannelMessageInput, ChannelMessageStatic, ChannelSettings, ClientConstructor, Environment, MessagePayloadType, MessageType, Platform, UrlPayload, UrlReplyOptions, VotChannels } from './../types';
/**
* Properties of Sorun Agent Class. Only the ones used are modeled.
*/
export interface SorunAgent {
id: number;
isBot: boolean;
isActive: boolean;
lastOnline: string;
}
/**
* Properties of Sorun Pool Class. Only the ones used are modeled.
*/
export interface SorunPool {
isOutOfOffice: boolean;
}
/**
* Properties of Sorun Company Class. Only the ones used are modeled.
*/
export interface SorunCompany {
isOutOfOffice: boolean;
}
/**
* Properties of Sorun Message Class in incoming input. Only the ones used are modeled.
*/
export interface SorunMessageInterface {
conversationID: number;
type: string;
platform: string;
payload: string | {
x: number;
y: number;
};
id?: number;
isAgent?: boolean;
userID?: number;
messageDate?: string;
uniqueID?: string;
}
/**
* Properties of Sorun Client Class in incoming input. Only the ones used are modeled.
*/
export interface SorunClientInterface {
name: string;
surname: string;
phone: string;
mail: string;
}
/**
* Properties of Sorun Conversation Class in incoming input. Only the ones used are modeled.
*/
export interface SorunConversationInterface {
variable: string;
}
/**
* Format of data received from Sorun at each message
*/
export interface SorunMessageInput extends ChannelMessageInput {
message: SorunMessageInterface;
client: SorunClientInterface;
conversation: SorunConversationInterface;
}
/**
* Prototype of a message that can be sent to Sorun
*/
export interface SorunMessagePrototype {
type: string;
payload: string;
}
/**
* Settings for connecting to Sorun
*/
export interface SorunSettingsType {
/**
* apiKey given by Sorun. Sent at each request with the name token at querystring
*/
apiKey: string;
/**
* Selection of Sorun server to connect
*/
environment?: Environment;
/**
* Url of Sorun server. Overrides environment setting
*/
url?: string;
/**
* Token that is sent with each message by Sorun.
*/
incomingHookToken: string;
}
/**
* Format of buttons in Sorun Cards
*/
export interface SorunButton {
type: 'L' | 'T';
text: string;
action: string;
}
/**
* Format of cards that can be send to Sorun
*/
export interface SorunCard {
image: string;
title: string;
text: string;
buttons: SorunButton[];
}
/**
* A class that represents the data received from Sorun
*/
export declare class SorunMessage extends ChannelMessageStatic implements ChannelMessage {
message: SorunMessageInterface;
client: SorunClientInterface;
conversation: SorunConversationInterface;
constructor({message, client, conversation}: SorunMessageInput);
/**
* Constructs a payload to be sent to Sorun from Message object
*/
static fromMessage(message: Message): {
payload: any;
type: string;
};
/**
* Constructs a payload to be sent to Sorun from CardMessage object
*/
static fromCardMessage(message: Message): {
payload: string;
type: string;
};
/**
* Function that parses the date of the incoming message
*/
getDate(): Date;
/**
* Converts Sorun message payload type to VoT Message Payload Type
*
* @returns VoT Promise<MessagePayloadType> VoT Message Payload Type
*/
getMessagePayloadType(): Promise<MessagePayloadType>;
/**
* Converts Sorun message type to VoT Message Type
*
* @returns MessageType VoT MessageType
*/
getMessageType(): MessageType;
/**
* Converts Sorun platform to VoT Pltform
*
* @returns Platform VoT Platform
*/
getPlatform(): Platform;
/**
* Parses incoming message from Sorun and produces a Message object.
* Uses the given Conversation and User to fill the properties.
*
* @returns Promise<Message> Parsed Message
*/
toMessage(conversation: Conversation, user: User): Promise<Message>;
}
export interface SorunClientConstructor extends ClientConstructor {
/**
* apiKey given by Sorun. Sent at each request with the name token at querystring
*/
apiKey: string;
/**
* Token that is sent with each message by Sorun.
*/
incomingHookToken: string;
/**
* Url of Sorun server. Overrides environment setting
*/
url?: string;
/**
* Selection of Sorun server to connect
*/
environment?: Environment;
/**
* Initial Context for messages coming from Sorun
*/
initialContext: Context;
/**
* Company ID given by Sorun
*/
companyID: number;
}
/**
* Client to connect to Sorun services
*/
export declare class SorunClient extends ChannelClient implements ChannelClientInterface {
/**
* apiKey given by Sorun. Sent at each request with the name token at querystring
*/
apiKey: string;
/**
* Selection of Sorun server to connect
*/
environment?: Environment;
/**
* Url of Sorun server. Overrides environment setting
*/
url?: string;
/**
* Token that is sent with each message by Sorun.
*/
incomingHookToken: string;
/**
* Initial Context for messages coming from Sorun
*/
initialContext: Context;
/**
* Company ID given by Sorun
*/
companyID: number;
/**
* Time in milliseconds to pass before timeouts during Sorun requests
*/
timeoutInMilliseconds: number;
kind: keyof VotChannels;
constructor({apiKey, incomingHookToken, url, environment, initialContext, companyID, timeoutInMilliseconds}: SorunClientConstructor);
/**
* Returns Sorun's conversation id
*/
static getConversationIdentifier(conversation: Conversation): string;
isProduction(): boolean;
checkIncomingHookToken(token: string): boolean;
/**
* Get user information from received message
*/
getUser(message: ChannelMessage): Promise<User>;
/**
* Save the context
*/
saveContext(votClient: VotClient, conversation: Conversation): Promise<string>;
/**
* Ends the conversation, removes the context from Redis. Shows rating stars.
*/
endConversation(votClient: VotClient, conversation: Conversation): Promise<any>;
/**
* Parses incoming Sorun messages into Message instances
* Works with text and card messages
*/
receiveMessage(votClient: VotClient, input: SorunMessageInput, settings: ChannelSettings): Promise<Message | null>;
/**
* Send a message through Sorun
*/
sendMessage(message: Message): Promise<Object>;
/**
* Sends a reply to a message from Sorun
*/
textReply(incoming: Message, payload: string): Promise<Object>;
/**
* Sends a reply in URL format to a message received from Sorun
*/
urlReply(incoming: Message, payload: UrlPayload, options?: UrlReplyOptions): Promise<Object>;
/**
* Sends a reply in Card format to a message received from Sorun
*/
cardReply(incoming: Message, payload: Card[] | Card): Promise<Object>;
/**
* Gets the list of active non-bot agents from Sorun
*/
getActiveAgents(): Promise<any>;
/**
* Gets the poolID of a conversation and information about that pool.
*/
getPoolData(conversation: Conversation): Promise<SorunPool>;
getPoolDataByPoolID(poolID: number): Promise<SorunPool>;
/**
* Removes the conversation from Redis and sets the active agent to the given id at Sorun
*/
yieldToAgent(votClient: VotClient, conversation: Conversation, agentID: number): Promise<any>;
changePool(conversation: Conversation, poolID: number): Promise<any>;
/**
* Prevents Sorun to automatically end the conversation if the user is not responding
*/
setHold(conversation: Conversation): Promise<any>;
/**
* Activates Sorun's feature to automatically end the conversation if the user is not responding
*/
unHold(conversation: Conversation): Promise<any>;
/**
* Fetches company data from Sorun
*/
getCompanyData(): Promise<any>;
/**
* Tests the conversation is in a pool that is currently in working hours.
*/
inWorkingHours(conversation: Conversation): Promise<boolean>;
inWorkingHoursByPoolID(poolID: number): Promise<boolean>;
/**
* Fetches the list of all ongoing conversations from Sorun
*/
getOpenConversations(): Promise<any>;
/**
* Chooses an agent to redirect the conversation to.
*/
findMostAvailableAgent(customersPerAgent: number): Promise<number | null>;
}