diff --git a/src/definition/accessors/ILivechatCreator.ts b/src/definition/accessors/ILivechatCreator.ts index def2a9857..8524ba251 100644 --- a/src/definition/accessors/ILivechatCreator.ts +++ b/src/definition/accessors/ILivechatCreator.ts @@ -16,13 +16,22 @@ export interface ILivechatCreator { * @param agent The agent responsible for the room */ createRoom(visitor: IVisitor, agent: IUser, extraParams?: IExtraRoomParams): Promise; + /** + * @deprecated Use `createAndReturnVisitor` instead. * Creates a Livechat visitor * * @param visitor Data of the visitor to be created */ createVisitor(visitor: IVisitor): Promise; + /** + * Creates a Livechat visitor + * + * @param visitor Data of the visitor to be created + */ + createAndReturnVisitor(visitor: IVisitor): Promise; + /** * Creates a token to be used when * creating a new livechat visitor diff --git a/src/server/accessors/LivechatCreator.ts b/src/server/accessors/LivechatCreator.ts index 937827cd8..8cd527159 100644 --- a/src/server/accessors/LivechatCreator.ts +++ b/src/server/accessors/LivechatCreator.ts @@ -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 { return this.bridges.getLivechatBridge().doCreateVisitor(visitor, this.appId); } + public createAndReturnVisitor(visitor: IVisitor): Promise { + 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); } diff --git a/src/server/bridges/LivechatBridge.ts b/src/server/bridges/LivechatBridge.ts index ea9e50f1b..9fc830767 100644 --- a/src/server/bridges/LivechatBridge.ts +++ b/src/server/bridges/LivechatBridge.ts @@ -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 { if (this.hasWritePermission(appId, 'livechat-visitor')) { return this.createVisitor(visitor, appId); } } + public async doCreateAndReturnVisitor(visitor: IVisitor, appId: string): Promise { + if (this.hasWritePermission(appId, 'livechat-visitor')) { + return this.createAndReturnVisitor(visitor, appId); + } + } + public async doFindVisitors(query: object, appId: string): Promise> { if (this.hasReadPermission(appId, 'livechat-visitor')) { return this.findVisitors(query, appId); @@ -160,8 +169,14 @@ export abstract class LivechatBridge extends BaseBridge { protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise; + /** + * @deprecated please use `createAndReturnVisitor` instead. + * It returns the created record rather than the ID. + */ protected abstract createVisitor(visitor: IVisitor, appId: string): Promise; + protected abstract createAndReturnVisitor(visitor: IVisitor, appId: string): Promise; + /** * @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. diff --git a/tests/test-data/bridges/livechatBridge.ts b/tests/test-data/bridges/livechatBridge.ts index 83eb45e13..27a884ea5 100644 --- a/tests/test-data/bridges/livechatBridge.ts +++ b/tests/test-data/bridges/livechatBridge.ts @@ -33,6 +33,10 @@ export class TestLivechatBridge extends LivechatBridge { throw new Error('Method not implemented'); } + public createAndReturnVisitor(visitor: IVisitor, appId: string): Promise { + throw new Error('Method not implemented'); + } + public transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData, appId: string): Promise { throw new Error('Method not implemented'); }