diff --git a/src/lib/api/Livechat.ts b/src/lib/api/Livechat.ts index 714f3cd..6ce3b74 100644 --- a/src/lib/api/Livechat.ts +++ b/src/lib/api/Livechat.ts @@ -35,9 +35,10 @@ export default class ApiLivechat extends ApiBase { token: visitor.token } return visitor - } - async agent ({ rid }: any) { return (await this.get(`livechat/agent.info/${rid}/${this.credentials.token}`)).agent } + } + async deleteVisitor () { return (await this.del(`livechat/visitor/${this.credentials.token}`)).visitor} async nextAgent ({ department }: any) { return (await this.get(`livechat/agent.next/${this.credentials.token}`, { department })).agent } + async agent ({ rid }: any) { return (await this.get(`livechat/agent.info/${rid}/${this.credentials.token}`)).agent } sendMessage (message: INewLivechatMessageAPI) { return (this.post('livechat/message', { ...message, token: this.credentials.token }, false)) } editMessage (id: string, message: INewLivechatMessageAPI) { return (this.put(`livechat/message/${id}`, message, false)) } deleteMessage (id: string, { rid }: ILivechatRoom) { return (this.del(`livechat/message/${id}`, { rid, token: this.credentials.token }, false)) } diff --git a/src/lib/api/api.ts b/src/lib/api/api.ts index 02bf7e1..9c30935 100644 --- a/src/lib/api/api.ts +++ b/src/lib/api/api.ts @@ -138,7 +138,7 @@ class Client implements IClient { delete (url: string, options?: any): Promise { return fetch(`${this.host}/api/v1/${encodeURI(url)}`, { - method: 'DEL', + method: 'DELETE', headers: this.getHeaders(options) }).then(this.handle) as Promise } @@ -220,7 +220,8 @@ export default class Api extends EventEmitter { if (!result) throw new Error(`API ${ method } ${ endpoint } result undefined`) if (!this.success(result, ignore)) throw result this.logger && this.logger.debug(`[API] ${method} ${endpoint} result ${result.status}`) - return (method === 'DELETE') ? result : result.data + const hasDataInsideResult = result && !result.data; + return (method === 'DELETE') && hasDataInsideResult ? result : result.data } catch (err) { this.logger && this.logger.error(`[API] POST error(${ endpoint }): ${ JSON.stringify(err) }`) throw err