Skip to content

Commit

Permalink
[FIX] - Incoming SMSs no longer clash with ongoing livechat conversat…
Browse files Browse the repository at this point in the history
…ions by the same visitor (#26307)
  • Loading branch information
cauefcr authored Aug 12, 2022
1 parent 5d5c060 commit 662ffb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/imports/server/rest/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const defineDepartment = (idOrName) => {
};

const defineVisitor = async (smsNumber, targetDepartment) => {
const visitor = LivechatVisitors.findOneVisitorByPhone(smsNumber);
const visitor = await LivechatVisitors.findOneVisitorByPhone(smsNumber);
let data = {
token: (visitor && visitor.token) || Random.id(),
};
Expand Down Expand Up @@ -86,7 +86,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', {

const visitor = await defineVisitor(sms.from, targetDepartment);
const { token } = visitor;
const room = LivechatRooms.findOneOpenByVisitorTokenAndDepartmentId(token, targetDepartment);
const room = LivechatRooms.findOneOpenByVisitorTokenAndDepartmentIdAndSource(token, targetDepartment, OmnichannelSourceType.SMS);
const roomExists = !!room;
const location = normalizeLocationSharing(sms);
const rid = (room && room._id) || Random.id();
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/app/models/server/models/LivechatRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,16 @@ export class LivechatRooms extends Base {
return this.findOne(query, options);
}

findOneOpenByVisitorTokenAndDepartmentId(visitorToken, departmentId, options) {
findOneOpenByVisitorTokenAndDepartmentIdAndSource(visitorToken, departmentId, source, options) {
const query = {
't': 'l',
'open': true,
'v.token': visitorToken,
departmentId,
};
if (source) {
query['source.type'] = source;
}

return this.findOne(query, options);
}
Expand Down

0 comments on commit 662ffb8

Please sign in to comment.