new(all): hubspot.gblib new methods. New Keyword FIND CONTACT.
This commit is contained in:
parent
d8044124e3
commit
0fe8b8c1b6
4 changed files with 22 additions and 9 deletions
|
@ -145,6 +145,16 @@ export class DialogKeywords {
|
||||||
return deal;
|
return deal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds contacts in XRM.
|
||||||
|
*
|
||||||
|
* @example list = FIND CONTACT "Sandra"
|
||||||
|
*/
|
||||||
|
public async fndContact(name) {
|
||||||
|
let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY);
|
||||||
|
return await s.searchContact(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public getContentLocaleWithCulture(contentLocale) {
|
public getContentLocaleWithCulture(contentLocale) {
|
||||||
switch (contentLocale) {
|
switch (contentLocale) {
|
||||||
|
|
|
@ -248,6 +248,10 @@ export class GBVMService extends GBService {
|
||||||
return `${$2} = hear()`;
|
return `${$2} = hear()`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
code = code.replace(/(\w)\s*\=\s*find contact\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
|
return `${$1} = fndContact(${$2})\n`;
|
||||||
|
});
|
||||||
|
|
||||||
code = code.replace(/(\w+)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(\w+)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
return `${$1} = sys().find(${$2})\n
|
return `${$1} = sys().find(${$2})\n
|
||||||
if (!${$1}) {
|
if (!${$1}) {
|
||||||
|
@ -576,6 +580,9 @@ export class GBVMService extends GBService {
|
||||||
code = code.replace(/("[^"]*"|'[^']*')|\bcreateDeal\b/gi, ($0, $1) => {
|
code = code.replace(/("[^"]*"|'[^']*')|\bcreateDeal\b/gi, ($0, $1) => {
|
||||||
return $1 === undefined ? 'this.createDeal' : $1;
|
return $1 === undefined ? 'this.createDeal' : $1;
|
||||||
});
|
});
|
||||||
|
code = code.replace(/("[^"]*"|'[^']*')|\bfndContact\b/gi, ($0, $1) => {
|
||||||
|
return $1 === undefined ? 'this.fndContact' : $1;
|
||||||
|
});
|
||||||
code = code.replace(/("[^"]*"|'[^']*')|\bgetActiveTasks\b/gi, ($0, $1) => {
|
code = code.replace(/("[^"]*"|'[^']*')|\bgetActiveTasks\b/gi, ($0, $1) => {
|
||||||
return $1 === undefined ? 'this.getActiveTasks' : $1;
|
return $1 === undefined ? 'this.getActiveTasks' : $1;
|
||||||
});
|
});
|
||||||
|
|
|
@ -146,16 +146,13 @@ export class HubSpotServices extends GBService {
|
||||||
|
|
||||||
public async searchContact(query) {
|
public async searchContact(query) {
|
||||||
const client = new hubspot.Client({ apiKey: this.key });
|
const client = new hubspot.Client({ apiKey: this.key });
|
||||||
const filter = { propertyName: 'createdate', operator: 'GTE', value: Date.now() - 30 * 60000 }
|
|
||||||
const filterGroup = { filters: [filter] }
|
|
||||||
const sort = JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })
|
const sort = JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })
|
||||||
|
|
||||||
const properties = ['createdate', 'firstname', 'lastname']
|
const properties = ['createdate', 'firstname', 'lastname', 'phone', 'email']
|
||||||
const limit = 100
|
const limit = 100
|
||||||
const after = 0
|
const after = 0
|
||||||
|
|
||||||
const publicObjectSearchRequest = {
|
const publicObjectSearchRequest = {
|
||||||
filterGroups: [filterGroup],
|
|
||||||
sorts: [sort],
|
sorts: [sort],
|
||||||
query,
|
query,
|
||||||
properties,
|
properties,
|
||||||
|
@ -164,8 +161,7 @@ export class HubSpotServices extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await client.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
|
const result = await client.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
|
||||||
console.log(JSON.stringify(result.body))
|
return result.body.results;
|
||||||
return result.body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue