Skip to content

Commit 47b07b7

Browse files
committed
Fix sms/call log sync to deal(add search filter)
1 parent aa2e2dd commit 47b07b7

File tree

7 files changed

+744
-45
lines changed

7 files changed

+744
-45
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": "1.3.14",
3+
"version": "1.3.15",
44
"description": "Add RingCentral Embeddable Voice widgets to Pipedrive",
55
"keywords": [
66
"RingCentral",

src/features/call-log-sync-to-deal.js

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* sync call log to deal
33
*/
44

5-
import fetch from 'ringcentral-embeddable-extension-common/src/common/fetch'
5+
// import fetch from 'ringcentral-embeddable-extension-common/src/common/fetch'
66
import {
77
host, notify
88
} from 'ringcentral-embeddable-extension-common/src/common/helpers'
9-
import { getSessionToken } from './common'
9+
// import { getSessionToken } from './common'
1010
import extLinkSvg from 'ringcentral-embeddable-extension-common/src/common/link-external.svg'
1111
import { thirdPartyConfigs } from 'ringcentral-embeddable-extension-common/src/common/app-config'
1212
import { searchByPersonId } from './deals'
@@ -44,45 +44,44 @@ export function notifySyncSuccess ({
4444
notify(msg, type, 9000)
4545
}
4646

47-
export async function getDeals () {
48-
let token = getSessionToken()
49-
let url = `${host}/api/v1/pipelines/1/deals?limit=500&start=0&get_summary=0&totals_convert_currency=default_currency&session_token=${token}&strict_mode=true&status=open`
50-
let res = await fetch.get(url)
51-
let success = res && res.data
52-
return success || []
53-
}
47+
// async function getDeals () {
48+
// let token = getSessionToken()
49+
// let url = `${host}/api/v1/pipelines/1/deals?limit=500&start=0&get_summary=0&totals_convert_currency=default_currency&session_token=${token}&strict_mode=true&status=open`
50+
// let res = await fetch.get(url)
51+
// let success = res && res.data
52+
// return success || []
53+
// }
5454

55-
async function syncToDeal (form, deal) {
56-
let token = getSessionToken()
57-
let url = `${host}/api/v1/activities?session_token=${token}&strict_mode=true`
58-
let data = {
59-
...form,
60-
deal_id: deal.id
61-
}
62-
delete data.person_id
63-
// data.participants = []
64-
// data.person_id = ''
65-
let res = await fetch.post(url, data)
66-
let success = res && res.data
67-
if (success) {
68-
notifySyncSuccess({ id: form.person_id, logType: form.subject })
69-
} else {
70-
notify('call log sync to deals failed', 'warn')
71-
console.log('call log sync to deals failed')
72-
}
73-
}
55+
// async function syncToDeal (form, deal) {
56+
// let token = getSessionToken()
57+
// let url = `${host}/api/v1/activities?session_token=${token}&strict_mode=true`
58+
// let data = {
59+
// ...form,
60+
// deal_id: deal.id
61+
// }
62+
// delete data.person_id
63+
// // data.participants = []
64+
// // data.person_id = ''
65+
// let res = await fetch.post(url, data)
66+
// let success = res && res.data
67+
// if (success) {
68+
// notifySyncSuccess({ id: form.person_id, logType: form.subject })
69+
// } else {
70+
// notify('call log sync to deals failed', 'warn')
71+
// console.log('call log sync to deals failed')
72+
// }
73+
// }
7474

75-
export async function syncToDeals (form) {
76-
let deals = await searchByPersonId(form.person_id)
77-
for (let deal of deals) {
78-
await syncToDeal(form, deal)
79-
}
80-
return deals.length
81-
}
75+
// async function syncToDeals (form) {
76+
// let deals = await searchByPersonId(form.person_id)
77+
// for (let deal of deals) {
78+
// await syncToDeal(form, deal)
79+
// }
80+
// return deals.length
81+
// }
8282

83-
export async function getDealId (form) {
84-
let deals = await searchByPersonId(form.person_id)
83+
export async function getDealId (contact) {
84+
let deals = await searchByPersonId(contact)
8585
return deals
86-
.filter(d => d && d.person_id && d.person_id.toString() === form.person_id.toString())
8786
.map(d => d.id)[0]
8887
}

src/features/call-log-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async function doSyncOne (contact, body, formData) {
206206
notification_language_id: 1,
207207
assigned_to_user_id: userId
208208
}
209-
let dealId = await getDealId(bd)
209+
let dealId = await getDealId(contact)
210210
if (dealId) {
211211
bd.deal_id = dealId
212212
}

src/features/deals.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import fetch from 'ringcentral-embeddable-extension-common/src/common/fetch'
1010
// import { thirdPartyConfigs } from 'ringcentral-embeddable-extension-common/src/common/app-config'
1111
import _ from 'lodash'
12+
import { addFilter, delFilter } from './filter'
1213
// import * as ls from 'ringcentral-embeddable-extension-common/src/common/ls'
1314
// import {
1415
// connection
@@ -122,9 +123,13 @@ import _ from 'lodash'
122123
// })
123124
// }
124125

125-
export async function searchByPersonId (personId) {
126+
export async function searchByPersonId (contact) {
126127
let token = getSessionToken()
127-
const res = await getDeals(token, 0, personId)
128+
const filterId = await addFilter(contact)
129+
const res = await getDeals(token, 0, contact.id, filterId)
130+
if (filterId) {
131+
await delFilter(filterId)
132+
}
128133
if (!res || !res.data) {
129134
return []
130135
}
@@ -150,8 +155,8 @@ export async function searchByPersonId (personId) {
150155
// })
151156
// }
152157

153-
function getDeals (token, start, userId = '') {
154-
let url = `${host}/v1/deals?limit=500&person_id=${userId}&start=${start}&get_summary=0&totals_convert_currency=default_currency&session_token=${token}&strict_mode=true&status=open&sort=update_time%20ASC`
158+
function getDeals (token, start, userId = '', filterId = '') {
159+
let url = `${host}/v1/deals?limit=500&person_id=${userId}&start=${start}&get_summary=0&totals_convert_currency=default_currency&session_token=${token}&strict_mode=true&status=open&sort=update_time%20ASC&filter_id=${filterId}`
155160
return fetch.get(url)
156161
}
157162

src/features/filter.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* filter add/del
3+
*/
4+
5+
import { getSessionToken } from './common'
6+
import {
7+
host // ,
8+
// createElementFromHTML
9+
} from 'ringcentral-embeddable-extension-common/src/common/helpers'
10+
import fetch from 'ringcentral-embeddable-extension-common/src/common/fetch'
11+
import getFieldId from './person-fields'
12+
13+
export async function addFilter (contact) {
14+
const token = getSessionToken()
15+
const fid = await getFieldId()
16+
const url = `${host}/api/v1/filters?session_token=${token}&strict_mode=true`
17+
const res = await fetch.post(url, {
18+
name: 'temp filter, please delete',
19+
type: 'deals',
20+
visible_to: '1',
21+
conditions: {
22+
glue: 'and',
23+
conditions: [
24+
{
25+
glue: 'and',
26+
conditions: [
27+
{
28+
object: 'person',
29+
field_id: fid,
30+
operator: '=',
31+
value: contact.emails[0],
32+
extra_value: null
33+
}
34+
]
35+
},
36+
{
37+
glue: 'or',
38+
conditions: [
39+
]
40+
}
41+
]
42+
}
43+
})
44+
if (res && res.data) {
45+
return res.data.id
46+
}
47+
}
48+
49+
export async function delFilter (id) {
50+
const token = getSessionToken()
51+
const url = `${host}/api/v1/filters/${id}?session_token=${token}&strict_mode=true&active_flag=false`
52+
await fetch.delete(url)
53+
}

0 commit comments

Comments
 (0)