Skip to content

Commit

Permalink
Change way of identifying when a chat is coming through widget
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Sep 10, 2021
1 parent abed911 commit e6a0e40
Show file tree
Hide file tree
Showing 13 changed files with 24,111 additions and 1,092 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { API } from '../api';
import { deprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';

API.helperMethods.set('deprecationWarning', function _deprecationWarning({ endpoint, versionWillBeRemoved, response }) {
(API as any).helperMethods.set('deprecationWarning', function _deprecationWarning({ endpoint, versionWillBeRemoved, response }: { endpoint: string; versionWillBeRemoved: string; response: any }) {
const warningMessage = `The endpoint "${ endpoint }" is deprecated and will be removed after version ${ versionWillBeRemoved }`;
deprecationLogger.api.warn(warningMessage);
(deprecationLogger as any).api.warn(warningMessage);
if (process.env.NODE_ENV === 'development') {
return {
warning: warningMessage,
Expand Down
13 changes: 13 additions & 0 deletions app/api/server/helpers/isWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { parse } from 'cookie';

import { API } from '../api';

(API as any).helperMethods.set('isWidget', function _isWidget() {
// @ts-expect-error
const { headers } = this.request;

const { rc_room_type: roomType, rc_is_widget: isWidget } = parse(headers.cookie);

const isLivechatRoom = roomType && roomType === 'l';
return !!(isLivechatRoom && isWidget === 't');
});
1 change: 1 addition & 0 deletions app/api/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './helpers/insertUserObject';
import './helpers/isUserFromParams';
import './helpers/parseJsonQuery';
import './helpers/requestParams';
import './helpers/isWidget';
import './default/info';
import './v1/assets';
import './v1/channels';
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/imports/server/rest/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ API.v1.addRoute('livechat/upload/:rid', {
uploadedFile.description = fields.description;

delete fields.description;
API.v1.success(Meteor.call('sendFileLivechatMessage', this.urlParams.rid, visitorToken, uploadedFile, fields));
return API.v1.success(Meteor.call('sendFileLivechatMessage', this.urlParams.rid, visitorToken, uploadedFile, fields));
},
});
6 changes: 2 additions & 4 deletions app/livechat/server/api/v1/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ API.v1.addRoute('livechat/message', {
agent,
roomInfo: {
source: {
type: OmnichannelSourceType.OTHER,
alias: 'livechat-api',
type: this.isWidget() ? OmnichannelSourceType.WIDGET : OmnichannelSourceType.API,
},
},
};
Expand Down Expand Up @@ -314,8 +313,7 @@ API.v1.addRoute('livechat/messages', { authRequired: true }, {
},
roomInfo: {
source: {
type: OmnichannelSourceType.OTHER,
alias: 'livechat-api',
type: this.isWidget() ? OmnichannelSourceType.WIDGET : OmnichannelSourceType.API,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/api/v1/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ API.v1.addRoute('livechat/room', {
const rid = Random.id();
const roomInfo = {
source: {
type: OmnichannelSourceType.WIDGET,
type: this.isWidget() ? OmnichannelSourceType.WIDGET : OmnichannelSourceType.API,
},
};

Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/api/v1/videoCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ API.v1.addRoute('livechat/video.call/:token', {
const roomInfo = {
jitsiTimeout: new Date(Date.now() + 3600 * 1000),
source: {
type: OmnichannelSourceType.OTHER,
type: OmnichannelSourceType.API,
alias: 'video-call',
},
};
Expand Down
3 changes: 1 addition & 2 deletions app/livechat/server/methods/sendMessageLivechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Meteor.methods({
agent,
roomInfo: {
source: {
type: OmnichannelSourceType.OTHER,
alias: 'livechat-api',
type: OmnichannelSourceType.API,
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/methods/startFileUploadRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Meteor.methods({
};

const roomInfo = {
source: OmnichannelSourceType.OTHER,
source: OmnichannelSourceType.API,
alias: 'file-upload',
};

Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/methods/startVideoCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Meteor.methods({
const roomInfo = {
jitsiTimeout: new Date(Date.now() + 3600 * 1000),
source: {
type: OmnichannelSourceType.OTHER,
type: OmnichannelSourceType.API,
alias: 'video-call',
},
};
Expand Down
3 changes: 2 additions & 1 deletion definition/IRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export enum OmnichannelSourceType {
EMAIL = 'email',
SMS = 'sms',
APP = 'app',
OTHER = 'other', // temporal, catch-all source type
API = 'api',
OTHER = 'other', // catch-all source type
}

export interface IOmnichannelRoom extends Omit<IRoom, 'default' | 'featured' | 'broadcast' | 'featured' | ''> {
Expand Down
Loading

0 comments on commit e6a0e40

Please sign in to comment.