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

feat: ILivechatCreator createAndReturnVisitor method #771

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/definition/accessors/ILivechatCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ export interface ILivechatCreator {
* @param agent The agent responsible for the room
*/
createRoom(visitor: IVisitor, agent: IUser, extraParams?: IExtraRoomParams): Promise<ILivechatRoom>;

/**
* @deprecated Use `createAndReturnVisitor` instead.
* Creates a Livechat visitor
*
* @param visitor Data of the visitor to be created
*/
createVisitor(visitor: IVisitor): Promise<string>;

/**
* Creates a Livechat visitor
*
* @param visitor Data of the visitor to be created
*/
createAndReturnVisitor(visitor: IVisitor): Promise<IVisitor | undefined>;

/**
* Creates a token to be used when
* creating a new livechat visitor
Expand Down
7 changes: 7 additions & 0 deletions src/server/accessors/LivechatCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ export class LivechatCreator implements ILivechatCreator {
return this.bridges.getLivechatBridge().doCreateRoom(visitor, agent, this.appId, extraParams);
}

/**
* @deprecated Use `createAndReturnVisitor` instead.
*/
public createVisitor(visitor: IVisitor): Promise<string> {
return this.bridges.getLivechatBridge().doCreateVisitor(visitor, this.appId);
}

public createAndReturnVisitor(visitor: IVisitor): Promise<IVisitor | undefined> {
return this.bridges.getLivechatBridge().doCreateAndReturnVisitor(visitor, this.appId);
}

public createToken(): string {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
Expand Down
15 changes: 15 additions & 0 deletions src/server/bridges/LivechatBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ export abstract class LivechatBridge extends BaseBridge {
}
}

/**
* @deprecated please use the `doCreateAndReturnVisitor` method instead.
*/
public async doCreateVisitor(visitor: IVisitor, appId: string): Promise<string> {
if (this.hasWritePermission(appId, 'livechat-visitor')) {
return this.createVisitor(visitor, appId);
}
}

public async doCreateAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined> {
if (this.hasWritePermission(appId, 'livechat-visitor')) {
return this.createAndReturnVisitor(visitor, appId);
}
}

public async doFindVisitors(query: object, appId: string): Promise<Array<IVisitor>> {
if (this.hasReadPermission(appId, 'livechat-visitor')) {
return this.findVisitors(query, appId);
Expand Down Expand Up @@ -160,8 +169,14 @@ export abstract class LivechatBridge extends BaseBridge {

protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise<void>;

/**
* @deprecated please use `createAndReturnVisitor` instead.
* It returns the created record rather than the ID.
*/
protected abstract createVisitor(visitor: IVisitor, appId: string): Promise<string>;

protected abstract createAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined>;

/**
* @deprecated This method does not adhere to the conversion practices applied
* elsewhere in the Apps-Engine and will be removed in the next major version.
Expand Down
4 changes: 4 additions & 0 deletions tests/test-data/bridges/livechatBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class TestLivechatBridge extends LivechatBridge {
throw new Error('Method not implemented');
}

public createAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined> {
throw new Error('Method not implemented');
}

public transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData, appId: string): Promise<boolean> {
throw new Error('Method not implemented');
}
Expand Down
Loading