Skip to content

Commit 27ef037

Browse files
committed
- feat: Support sync log to multi contacts with same phone number(Warning: this may create duplicate log due to matching method change)
- feat: Set unread SMS as not done status
1 parent 222d107 commit 27ef037

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pipedrive-embeddable-ringcentral-phone-spa",
3-
"version": "2.9.0",
3+
"version": "2.10.0",
44
"description": "Add RingCentral Embeddable Voice widgets to Pipedrive",
55
"keywords": [
66
"RingCentral",

src/features/call-log-sync.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function doSync (body, formData, isManuallySync) {
150150
}
151151
}
152152

153-
function buildMsgs (body) {
153+
function buildMsgs (body, contactId) {
154154
let msgs = _.get(body, 'conversation.messages')
155155
const arr = []
156156
for (const m of msgs) {
@@ -170,13 +170,15 @@ function buildMsgs (body) {
170170
attachments = attachments ? `<p>attachments: </p>${attachments}` : ''
171171
arr.push({
172172
body: `<div>SMS: <b>${m.subject}</b> - ${desc} <b>${n}</b> - ${moment(m.creationTime).format('MMM DD, YYYY HH:mm')}${attachments}</div>`,
173-
id: m.id
173+
id: m.id,
174+
done: m.readStatus === 'Read',
175+
contactId
174176
})
175177
}
176178
return arr
177179
}
178180

179-
function buildVoiceMailMsgs (body) {
181+
function buildVoiceMailMsgs (body, contactId) {
180182
let msgs = _.get(body, 'conversation.messages')
181183
const arr = []
182184
for (const m of msgs) {
@@ -191,25 +193,27 @@ function buildVoiceMailMsgs (body) {
191193
let links = m.attachments.map(t => t.link).join(', ')
192194
arr.push({
193195
body: `<p>Voice mail: ${links} - ${n ? desc : ''} <b>${n}</b> ${moment(m.creationTime).format('MMM DD, YYYY HH:mm')}</p>`,
194-
id: m.id
196+
id: m.id,
197+
done: m.readStatus === 'Read',
198+
contactId
195199
})
196200
}
197201
return arr
198202
}
199203

200-
function buildKey (id) {
201-
return `rc-log-${userId}-${id}`
204+
function buildKey (id, cid) {
205+
return `rc-log-${userId}-${id}-${cid}`
202206
}
203207

204-
async function saveLog (id, engageId) {
205-
const key = buildKey(id)
208+
async function saveLog (id, cid, engageId) {
209+
const key = buildKey(id, cid)
206210
await ls.set(key, engageId)
207211
}
208212

209213
async function filterLoggered (arr) {
210214
const res = []
211215
for (const m of arr) {
212-
const key = buildKey(m.id)
216+
const key = buildKey(m.id, m.contactId)
213217
const ig = await ls.get(key)
214218
if (!ig) {
215219
res.push(m)
@@ -261,15 +265,16 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
261265
if (body.call) {
262266
mainBody = `[${_.get(body, 'call.direction')} ${_.get(body, 'call.result')}] CALL from <b>${body.call.fromMatches.map(d => d.name).join(', ')}</b>(<b>${formatPhoneLocal(fromNumber)}</b>) to <b>${body.call.toMatches.map(d => d.name).join(', ')}</b>(<b>${formatPhoneLocal(toNumber)}</b>)`
263267
} else if (ctype === 'SMS') {
264-
mainBody = buildMsgs(body)
268+
mainBody = buildMsgs(body, id)
265269
} else if (isVoiceMail) {
266-
mainBody = buildVoiceMailMsgs(body)
270+
mainBody = buildVoiceMailMsgs(body, id)
267271
}
268272
let logType = body.call ? 'Call' : ctype
269273
if (!_.isArray(mainBody)) {
270274
mainBody = [{
271275
body: mainBody,
272-
id: externalId
276+
id: externalId,
277+
contactId: id
273278
}]
274279
}
275280
if (!isManuallySync) {
@@ -282,6 +287,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
282287
let bodyAll = mainBody.map(mm => {
283288
return {
284289
id: mm.id,
290+
...mm,
285291
body: `<div>${descFormatted}</div><p>${mm.body}</p>${recording}`
286292
}
287293
})
@@ -297,7 +303,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
297303
note: uit.body,
298304
type: 'call',
299305
subject: logType,
300-
done: true,
306+
done: _.isUndefined(uit.done) ? true : uit.done,
301307
participants: [
302308
{
303309
person_id: parseInt(id, 10) || '',

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Ringcentral Embeddable Widgets for Pipedrive",
3-
"version": "2.9.0",
3+
"version": "2.10.0",
44
"description": "Add RingCentral Embeddable Voice widgets to Pipedrive",
55
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1YqYvCEeGGNOgtKrx8DfG33ujx7NgAwbyVpikug4mHiNvKZYWulw7lY5fjaD8wAy5bmXnkfULDzqMkL8UOxUcf8qD2lJFcLm+BqBtqNnoSz00vwjSOxXrcDvpvsMrjEZkI7N/FD60sTWp1U+QOehua7OboUpXb4iV7TQfppz3PsCz7qGOa4PWjUMAZTTgomUtW47Es6f/vjIeejs7Ihro3Al5Jo3SWIbjpjSU9BK34XgFvtcZx3lZQgfFiK+ZNyxlx8mgC/PLqJB+uX63ywMrT86TdcfxBuaThy98S8SCXjZTpHOP6X5pmGMk0lPM06hwxmSCBZgHOHL/Wk6r8FUlQIDAQAB",
66
"permissions": [

0 commit comments

Comments
 (0)