diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 70932d70..21240b3b 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -125,15 +125,27 @@ export class DialogKeywords { } /** - * Quits the dialog, currently required to get out of VM context. + * Get active tasks. * * @example list = ACTIVE TASKS */ - public async getActiveTasks (){ - let s = new HubSpotServices(null, null, 'ddcc3f4e-edfe-4dc5-a337-3d39bcc2d833'); + public async getActiveTasks() { + let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY); return await s.getActiveTasks(); } + /** + * Creates a new deal. + * + * @example CREATE DEAL dealname, contato, empresa, amount + */ + public async createDeal(dealName, contact, company, amount) { + let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY); + let deal = await s.createDeal(dealName, contact, company, amount); + return deal; + } + + public getContentLocaleWithCulture(contentLocale) { switch (contentLocale) { case 'pt': diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 85b9a8c7..27174cbe 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -264,10 +264,14 @@ export class GBVMService extends GBService { return `${$1} = sys().find(${$2})\n`; }); + code = code.replace(/(\w)\s*\=\s*create deal(\s)(.*)/gi, ($0, $1, $2, $3) => { + return `${$1} =createDeal(${$3})\n`; + }); + code = code.replace(/(\w)\s*\=\s*active tasks/gi, ($0, $1) => { return `${$1} = getActiveTasks()\n`; }); - + code = code.replace(/(\w)\s*\=\s*append\s*(.*)/gi, ($0, $1, $2, $3) => { return `${$1} = sys().append(${$2})\n`; }); @@ -569,6 +573,9 @@ export class GBVMService extends GBService { code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => { return $1 === undefined ? 'this.transfer' : $1; }); + code = code.replace(/("[^"]*"|'[^']*')|\bcreateDeal\b/gi, ($0, $1) => { + return $1 === undefined ? 'this.createDeal' : $1; + }); code = code.replace(/("[^"]*"|'[^']*')|\bgetActiveTasks\b/gi, ($0, $1) => { return $1 === undefined ? 'this.getActiveTasks' : $1; }); diff --git a/packages/hubspot.gblib/services/HubSpotServices.ts b/packages/hubspot.gblib/services/HubSpotServices.ts index 7d512760..e9518b49 100644 --- a/packages/hubspot.gblib/services/HubSpotServices.ts +++ b/packages/hubspot.gblib/services/HubSpotServices.ts @@ -69,6 +69,106 @@ export class HubSpotServices extends GBService { } } + public async addDealNote(name, note) + { + + } + + public async createDeal(dealName, contact, company, amount) { + const dealObj = { + properties: { + dealname: dealName, + dealstage: 'appointmentscheduled', + pipeline: 'default', + amount: amount + }, + } + const contactObj = { + properties: { + firstname: contact + }, + } + const companyObj = { + properties: { + name: company, + }, + } + + const hubspotClient = new hubspot.Client({ apiKey: this.key }); + const createDealResponse = await hubspotClient.crm.deals.basicApi.create(dealObj); + const createContactResponse = await hubspotClient.crm.contacts.basicApi.create(contactObj); + const createCompanyResponse = await hubspotClient.crm.companies.basicApi.create(companyObj); + + await hubspotClient.crm.deals.associationsApi.create( + createDealResponse.body.id, + 'contacts', + createContactResponse.body.id, + 'deal_to_contact' + ) + + await hubspotClient.crm.deals.associationsApi.create( + createDealResponse.body.id, + 'companies', + createCompanyResponse.body.id, + 'deal_to_company' + ) + + return createDealResponse.body; + + } + + + public async createContact(firstName, lastName, domain, companyName) { + const contactObj = { + properties: { + firstname: firstName, + lastname: lastName, + }, + } + const companyObj = { + properties: { + domain: domain, + name: companyName, + }, + } + + const hubspotClient = new hubspot.Client({ apiKey: this.key }) + const createContactResponse = await hubspotClient.crm.contacts.basicApi.create(contactObj) + const createCompanyResponse = await hubspotClient.crm.companies.basicApi.create(companyObj) + + return await hubspotClient.crm.companies.associationsApi.create( + createCompanyResponse.body.id, + 'contacts', + createContactResponse.body.id, + 'company_to_contact' + ) + } + + 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 limit = 100 + const after = 0 + + const publicObjectSearchRequest = { + filterGroups: [filterGroup], + sorts: [sort], + query, + properties, + limit, + after, + } + + const result = await client.crm.contacts.searchApi.doSearch(publicObjectSearchRequest) + console.log(JSON.stringify(result.body)) + return result.body; + } + + public async getActiveTasks(): Promise<[]> { const client = new hubspot.Client({ apiKey: this.key });