Skip to content

Commit

Permalink
new(all): hubspot.gblib new methods. New Keyword FIND CONTACT.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Dec 20, 2021
1 parent d804412 commit 0fe8b8c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
10 changes: 10 additions & 0 deletions packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export class DialogKeywords {
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) {
switch (contentLocale) {
Expand Down
7 changes: 7 additions & 0 deletions packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export class GBVMService extends GBService {
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) => {
return `${$1} = sys().find(${$2})\n
if (!${$1}) {
Expand Down Expand Up @@ -576,6 +580,9 @@ export class GBVMService extends GBService {
code = code.replace(/("[^"]*"|'[^']*')|\bcreateDeal\b/gi, ($0, $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) => {
return $1 === undefined ? 'this.getActiveTasks' : $1;
});
Expand Down
8 changes: 2 additions & 6 deletions packages/hubspot.gblib/services/HubSpotServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,13 @@ export class HubSpotServices extends GBService {

public async searchContact(query) {
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 properties = ['createdate', 'firstname', 'lastname']
const properties = ['createdate', 'firstname', 'lastname', 'phone', 'email']
const limit = 100
const after = 0

const publicObjectSearchRequest = {
filterGroups: [filterGroup],
sorts: [sort],
query,
properties,
Expand All @@ -164,8 +161,7 @@ export class HubSpotServices extends GBService {
}

const result = await client.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
console.log(JSON.stringify(result.body))
return result.body;
return result.body.results;
}


Expand Down
6 changes: 3 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class GBServer {
GBLog.verbose(`Error initializing storage: ${error}`);
GBServer.globals.bootInstance =
await core.createBootInstance(core, azureDeployer, GBServer.globals.publicAddress);

}

core.ensureAdminIsSecured();
Expand All @@ -155,7 +155,7 @@ export class GBServer {
await deployer.deployPackages(core, server, GBServer.globals.appPackages);
await core.syncDatabaseStructure();


GBLog.info(`Publishing instances...`);
const instances: IGBInstance[] = await core.loadAllInstances(
core,
Expand All @@ -164,7 +164,7 @@ export class GBServer {
);

if (instances.length === 0) {

const instance = await importer.importIfNotExistsBotPackage(
GBConfigService.get('BOT_ID'),
'boot.gbot',
Expand Down

0 comments on commit 0fe8b8c

Please sign in to comment.