Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Livechat features #124

Merged
merged 11 commits into from
Aug 30, 2019
14 changes: 14 additions & 0 deletions src/definition/accessors/IHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ export interface IHttpRequest {
[key: string]: string,
};
timeout?: number;
/**
* if `true`, requires SSL certificates be valid.
*
* Defaul: `true`;
*/
strictSSL?: boolean;
/**
* If `true`, the server certificate is verified against the list of supplied CAs.
*
* Default: `true`.
*
* https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
*/
rejectUnauthorized?: boolean;
}

export interface IHttpResponse {
Expand Down
7 changes: 7 additions & 0 deletions src/definition/accessors/ILivechatRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ILivechatRoom } from '../livechat/ILivechatRoom';
import { IVisitor } from '../livechat/IVisitor';

export interface ILivechatRead {
getLivechatRooms(visitor: IVisitor, departmentId?: string): Promise<Array<ILivechatRoom>>;
getLivechatVisitors(query: object): Promise<Array<IVisitor>>;
}
278 changes: 277 additions & 1 deletion src/definition/accessors/IModify.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ILivechatMessage, ILivechatRoom, ILivechatTransferData } from '../livechat';
import { IVisitor } from '../livechat/IVisitor';
import { IMessage, IMessageAttachment } from '../messages';
import { RocketChatAssociationModel } from '../metadata';
import { IRoom, RoomType } from '../rooms';
Expand Down Expand Up @@ -46,6 +48,11 @@ export interface INotifier {
}

export interface IModifyUpdater {
/**
* Get the updater object responsible for the
* Livechat integrations
*/
getLivechatUpdater(): ILivechatUpdater;
/**
* Modifies an existing message.
* Raises an exception if a non-existent messageId is supplied
Expand Down Expand Up @@ -104,6 +111,11 @@ export interface IModifyExtender {
}

export interface IModifyCreator {
/**
* Get the creator object responsible for the
* Livechat integrations
*/
getLivechatCreator(): ILivechatCreator;
/**
* Starts the process for building a new message object.
*
Expand All @@ -113,6 +125,15 @@ export interface IModifyCreator {
*/
startMessage(data?: IMessage): IMessageBuilder;

/**
* Starts the process for building a new livechat message object.
*
* @param data (optional) the initial data to pass into the builder,
* the `id` property will be ignored
* @return an IMessageBuilder instance
*/
startLivechatMessage(data?: ILivechatMessage): ILivechatMessageBuilder;

/**
* Starts the process for building a new room.
*
Expand All @@ -128,7 +149,49 @@ export interface IModifyCreator {
* @param builder the builder instance
* @return the resulting `id` of the resulting object
*/
finish(builder: IMessageBuilder | IRoomBuilder): Promise<string>;
finish(builder: IMessageBuilder | ILivechatMessageBuilder | IRoomBuilder): Promise<string>;
}

export interface ILivechatCreator {
/**
* Creates a room to connect the `visitor` to an `agent`.
*
* This method uses the Livechat routing method configured
* in the server
*
* @param visitor The Livechat Visitor that started the conversation
* @param agent The agent responsible for the room
*/
createRoom(visitor: IVisitor, agent: IUser): Promise<ILivechatRoom>;
/**
* Creates a Livechat visitor
*
* @param visitor Data of the visitor to be created
*/
createVisitor(visitor: IVisitor): Promise<string>;

/**
* Creates a token to be used when
* creating a new livechat visitor
*/
createToken(): string;
}

export interface ILivechatUpdater {
/**
* Transfer a Livechat visitor to another room
*
* @param visitor Visitor to be transfered
* @param transferData The data to execute the transfering
*/
transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData): Promise<boolean>;
/**
* Closes a Livechat room
*
* @param room The room to be closed
* @param comment The comment explaining the reason for closing the room
*/
closeRoom(room: IRoom, comment: string): Promise<boolean>;
}

export interface IMessageExtender {
Expand Down Expand Up @@ -377,6 +440,219 @@ export interface IMessageBuilder {
getMessage(): IMessage;
}

/**
* Interface for building out a livechat message.
* Please note, that a room and sender must be associated otherwise you will NOT
* be able to successfully save the message object.
*/
export interface ILivechatMessageBuilder {
kind: RocketChatAssociationModel.LIVECHAT_MESSAGE;

/**
* Provides a convient way to set the data for the message.
* Note: Providing an "id" field here will be ignored.
*
* @param message the message data to set
*/
setData(message: ILivechatMessage): ILivechatMessageBuilder;

/**
* Sets the room where this message should be sent to.
*
* @param room the room where to send
*/
setRoom(room: IRoom): ILivechatMessageBuilder;

/**
* Gets the room where this message was sent to.
*/
getRoom(): IRoom;

/**
* Sets the sender of this message.
*
* @param sender the user sending the message
*/
setSender(sender: IUser): ILivechatMessageBuilder;

/**
* Gets the User which sent the message.
*/
getSender(): IUser;

/**
* Sets the text of the message.
*
* @param text the actual text
*/
setText(text: string): ILivechatMessageBuilder;

/**
* Gets the message text.
*/
getText(): string;

/**
* Sets the emoji to use for the avatar, this overwrites the current avatar
* whether it be the user's or the avatar url provided.
*
* @param emoji the emoji code
*/
setEmojiAvatar(emoji: string): ILivechatMessageBuilder;

/**
* Gets the emoji used for the avatar.
*/
getEmojiAvatar(): string;

/**
* Sets the url which to display for the avatar, this overwrites the current
* avatar whether it be the user's or an emoji one.
*
* @param avatarUrl image url to use as the avatar
*/
setAvatarUrl(avatarUrl: string): ILivechatMessageBuilder;

/**
* Gets the url used for the avatar.
*/
getAvatarUrl(): string;

/**
* Sets the display text of the sender's username that is visible.
*
* @param alias the username alias to display
*/
setUsernameAlias(alias: string): ILivechatMessageBuilder;

/**
* Gets the display text of the sender's username that is visible.
*/
getUsernameAlias(): string;

/**
* Adds one attachment to the message's list of attachments, this will not
* overwrite any existing ones but just adds.
*
* @param attachment the attachment to add
*/
addAttachment(attachment: IMessageAttachment): ILivechatMessageBuilder;

/**
* Sets the attachments for the message, replacing and destroying all of the current attachments.
*
* @param attachments array of the attachments
*/
setAttachments(attachments: Array<IMessageAttachment>): ILivechatMessageBuilder;

/**
* Gets the attachments array for the message
*/
getAttachments(): Array<IMessageAttachment>;

/**
* Replaces an attachment at the given position (index).
* If there is no attachment at that position, there will be an error thrown.
*
* @param position the index of the attachment to replace
* @param attachment the attachment to replace with
*/
replaceAttachment(position: number, attachment: IMessageAttachment): ILivechatMessageBuilder;

/**
* Removes an attachment at the given position (index).
* If there is no attachment at that position, there will be an error thrown.
*
* @param position the index of the attachment to remove
*/
removeAttachment(position: number): ILivechatMessageBuilder;

/**
* Sets the user who is editing this message.
* This is required if you are modifying an existing message.
*
* @param user the editor
*/
setEditor(user: IUser): ILivechatMessageBuilder;

/**
* Gets the user who edited the message
*/
getEditor(): IUser;

/**
* Sets whether this message can group with others.
* This is desirable if you want to avoid confusion with other integrations.
*
* @param groupable whether this message can group with others
*/
setGroupable(groupable: boolean): ILivechatMessageBuilder;

/**
* Gets whether this message can group with others.
*/
getGroupable(): boolean;

/**
* Sets whether this message should have any URLs in the text
* parsed by Rocket.Chat and get the details added to the message's
* attachments.
*
* @param parseUrls whether URLs should be parsed in this message
*/
setParseUrls(parseUrls: boolean): ILivechatMessageBuilder;

/**
* Gets whether this message should have its URLs parsed
*/
getParseUrls(): boolean;

/**
* Set the token of the livechat visitor that
* sent the message
*
* @param token The Livechat visitor's token
*/
setToken(token: string): ILivechatMessageBuilder;

/**
* Gets the token of the livechat visitor that
* sent the message
*/
getToken(): string;

/**
* If the sender of the message is a Livechat Visitor,
* set the visitor who sent the message.
*
* If you set the visitor property of a message, the
* sender will be emptied
*
* @param visitor The visitor who sent the message
*/
setVisitor(visitor: IVisitor): ILivechatMessageBuilder;

/**
* Get the visitor who sent the message,
* if any
*/
getVisitor(): IVisitor;

/**
* Gets the resulting message that has been built up to the point of calling it.
*
* *Note:* This will error out if the Room has not been defined OR if the room
* is not of type RoomType.LIVE_CHAT.
*/
getMessage(): ILivechatMessage;

/**
* Returns a message builder based on the
* livechat message of this builder
*/
getMessageBuilder(): IMessageBuilder;
}

/**
* Interface for building out a room.
* Please note, a room creator, name, and type must be set otherwise you will NOT
Expand Down
5 changes: 5 additions & 0 deletions src/definition/accessors/IRead.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { IEnvironmentRead } from './IEnvironmentRead';
import { ILivechatRead } from './ILivechatRead';
import { IMessageRead } from './IMessageRead';
import { INotifier } from './IModify';
import { IPersistenceRead } from './IPersistenceRead';
import { IRoomRead } from './IRoomRead';
import { IUploadRead } from './IUploadRead';
import { IUserRead } from './IUserRead';

/**
Expand All @@ -28,4 +30,7 @@ export interface IRead {

/** Gets the INotifier for notifying users/rooms. */
getNotifier(): INotifier;

getLivechatReader(): ILivechatRead;
getUploadReader(): IUploadRead;
}
8 changes: 8 additions & 0 deletions src/definition/accessors/IUploadRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import { IUpload } from '../uploads';

export interface IUploadRead {
getById(id: string): Promise<IUpload>;
getBufferById(id: string): Promise<Buffer>;
getBuffer(upload: IUpload): Promise<Buffer>;
}
Loading