new(all): hubspot.gblib new methods. New Keyword CREATE DEAL.
This commit is contained in:
parent
7410085e99
commit
d8044124e3
3 changed files with 123 additions and 4 deletions
|
@ -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
|
* @example list = ACTIVE TASKS
|
||||||
*/
|
*/
|
||||||
public async getActiveTasks (){
|
public async getActiveTasks() {
|
||||||
let s = new HubSpotServices(null, null, 'ddcc3f4e-edfe-4dc5-a337-3d39bcc2d833');
|
let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY);
|
||||||
return await s.getActiveTasks();
|
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) {
|
public getContentLocaleWithCulture(contentLocale) {
|
||||||
switch (contentLocale) {
|
switch (contentLocale) {
|
||||||
case 'pt':
|
case 'pt':
|
||||||
|
|
|
@ -264,10 +264,14 @@ export class GBVMService extends GBService {
|
||||||
return `${$1} = sys().find(${$2})\n`;
|
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) => {
|
code = code.replace(/(\w)\s*\=\s*active tasks/gi, ($0, $1) => {
|
||||||
return `${$1} = getActiveTasks()\n`;
|
return `${$1} = getActiveTasks()\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
code = code.replace(/(\w)\s*\=\s*append\s*(.*)/gi, ($0, $1, $2, $3) => {
|
code = code.replace(/(\w)\s*\=\s*append\s*(.*)/gi, ($0, $1, $2, $3) => {
|
||||||
return `${$1} = sys().append(${$2})\n`;
|
return `${$1} = sys().append(${$2})\n`;
|
||||||
});
|
});
|
||||||
|
@ -569,6 +573,9 @@ export class GBVMService extends GBService {
|
||||||
code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
|
code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
|
||||||
return $1 === undefined ? 'this.transfer' : $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) => {
|
code = code.replace(/("[^"]*"|'[^']*')|\bgetActiveTasks\b/gi, ($0, $1) => {
|
||||||
return $1 === undefined ? 'this.getActiveTasks' : $1;
|
return $1 === undefined ? 'this.getActiveTasks' : $1;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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<[]> {
|
public async getActiveTasks(): Promise<[]> {
|
||||||
|
|
||||||
const client = new hubspot.Client({ apiKey: this.key });
|
const client = new hubspot.Client({ apiKey: this.key });
|
||||||
|
|
Loading…
Add table
Reference in a new issue