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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ export class GBServer {
|
||||||
GBLog.verbose(`Error initializing storage: ${error}`);
|
GBLog.verbose(`Error initializing storage: ${error}`);
|
||||||
GBServer.globals.bootInstance =
|
GBServer.globals.bootInstance =
|
||||||
await core.createBootInstance(core, azureDeployer, GBServer.globals.publicAddress);
|
await core.createBootInstance(core, azureDeployer, GBServer.globals.publicAddress);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.ensureAdminIsSecured();
|
core.ensureAdminIsSecured();
|
||||||
|
@ -155,7 +155,7 @@ export class GBServer {
|
||||||
await deployer.deployPackages(core, server, GBServer.globals.appPackages);
|
await deployer.deployPackages(core, server, GBServer.globals.appPackages);
|
||||||
await core.syncDatabaseStructure();
|
await core.syncDatabaseStructure();
|
||||||
|
|
||||||
|
|
||||||
GBLog.info(`Publishing instances...`);
|
GBLog.info(`Publishing instances...`);
|
||||||
const instances: IGBInstance[] = await core.loadAllInstances(
|
const instances: IGBInstance[] = await core.loadAllInstances(
|
||||||
core,
|
core,
|
||||||
|
@ -164,7 +164,7 @@ export class GBServer {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (instances.length === 0) {
|
if (instances.length === 0) {
|
||||||
|
|
||||||
const instance = await importer.importIfNotExistsBotPackage(
|
const instance = await importer.importIfNotExistsBotPackage(
|
||||||
GBConfigService.get('BOT_ID'),
|
GBConfigService.get('BOT_ID'),
|
||||||
'boot.gbot',
|
'boot.gbot',
|
||||||
|
|
Loading…
Add table
Reference in a new issue