new(all): hubspot.gblib introduced.
This commit is contained in:
parent
74e0a01f6a
commit
68369c24ad
10 changed files with 215 additions and 5 deletions
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -1768,6 +1768,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"@hubspot/api-client": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@hubspot/api-client/-/api-client-5.0.0.tgz",
|
||||
"integrity": "sha512-ywgS7A79v9Y2Wyc3CWJ6dF1i3iEK+9tsdYdt48osQkW8ypvby7PvcHJV5WTkvdkYXAXTcWjGJoji06JCcSAqgQ==",
|
||||
"requires": {
|
||||
"bluebird": "^3.7.2",
|
||||
"bottleneck": "^2.19.5",
|
||||
"lodash": "^4.17.21",
|
||||
"request": "^2.88.0"
|
||||
}
|
||||
},
|
||||
"@iarna/toml": {
|
||||
"version": "2.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.3.tgz",
|
||||
|
@ -5333,8 +5344,7 @@
|
|||
"bottleneck": {
|
||||
"version": "2.19.5",
|
||||
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
|
||||
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
|
||||
},
|
||||
"boxen": {
|
||||
"version": "1.3.0",
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
"@azure/ms-rest-js": "2.5.1",
|
||||
"@google-cloud/pubsub": "2.13.0",
|
||||
"@google-cloud/translate": "6.2.6",
|
||||
"@hubspot/api-client": "5.0.0",
|
||||
"@microsoft/microsoft-graph-client": "2.2.1",
|
||||
"@semantic-release/changelog": "5.0.1",
|
||||
"@semantic-release/exec": "5.0.0",
|
||||
|
|
|
@ -40,6 +40,7 @@ import { GBDeployer } from '../../core.gbapp/services/GBDeployer';
|
|||
import { SecService } from '../../security.gbapp/services/SecService';
|
||||
import { SystemKeywords } from './SystemKeywords';
|
||||
import { GBMinService } from '../../core.gbapp/services/GBMinService';
|
||||
import { HubSpotServices } from '../../hubspot.gblib/services/HubSpotServices';
|
||||
var DateDiff = require('date-diff');
|
||||
|
||||
|
||||
|
@ -123,6 +124,16 @@ export class DialogKeywords {
|
|||
await step.endDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the dialog, currently required to get out of VM context.
|
||||
*
|
||||
* @example list = ACTIVE TASKS
|
||||
*/
|
||||
public async getActiveTasks (){
|
||||
let s = new HubSpotServices(null, null, 'ddcc3f4e-edfe-4dc5-a337-3d39bcc2d833');
|
||||
return await s.getActiveTasks();
|
||||
}
|
||||
|
||||
public getContentLocaleWithCulture(contentLocale) {
|
||||
switch (contentLocale) {
|
||||
case 'pt':
|
||||
|
|
|
@ -264,6 +264,10 @@ export class GBVMService extends GBService {
|
|||
return `${$1} = sys().find(${$2})\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`;
|
||||
});
|
||||
|
@ -565,6 +569,9 @@ export class GBVMService extends GBService {
|
|||
code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.transfer' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bgetActiveTasks\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.getActiveTasks' : $1;
|
||||
});
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bmenu\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.menu' : $1;
|
||||
});
|
||||
|
|
|
@ -57,6 +57,7 @@ import { GBSharePointPackage } from '../../sharepoint.gblib';
|
|||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import { GBBasicPackage } from '../../basic.gblib';
|
||||
import { GBGoogleChatPackage } from '../../google-chat.gblib';
|
||||
import { GBHubSpotPackage } from '../../hubspot.gblib';
|
||||
|
||||
const opn = require('opn');
|
||||
const cron = require('node-cron');
|
||||
|
@ -462,7 +463,8 @@ ENDPOINT_UPDATE=true
|
|||
GBAzureDeployerPackage,
|
||||
GBSharePointPackage,
|
||||
GBGoogleChatPackage,
|
||||
GBBasicPackage
|
||||
GBBasicPackage,
|
||||
GBHubSpotPackage
|
||||
],
|
||||
async e => {
|
||||
GBLog.info(`Loading sys package: ${e.name}...`);
|
||||
|
|
|
@ -915,7 +915,8 @@ export class GBDeployer implements IGBDeployer {
|
|||
'customer-satisfaction.gbapp',
|
||||
'kb.gbapp',
|
||||
'google-chat.gblib',
|
||||
'teams.gblib'
|
||||
'teams.gblib',
|
||||
'hubspot.gblib'
|
||||
];
|
||||
|
||||
return names.indexOf(name) > -1;
|
||||
|
|
71
packages/hubspot.gblib/index.ts
Normal file
71
packages/hubspot.gblib/index.ts
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*****************************************************************************\
|
||||
| ( )_ _ |
|
||||
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
|
||||
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
|
||||
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| (˅) |( (_) ) |
|
||||
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
|
||||
| | | ( )_) | |
|
||||
| (_) \___/' |
|
||||
| |
|
||||
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
|
||||
| Licensed under the AGPL-3.0. |
|
||||
| |
|
||||
| According to our dual licensing model, this program can be used either |
|
||||
| under the terms of the GNU Affero General Public License, version 3, |
|
||||
| or under a proprietary license. |
|
||||
| |
|
||||
| The texts of the GNU Affero General Public License with an additional |
|
||||
| permission and of our proprietary license can be found at and |
|
||||
| in the LICENSE file you have received along with this program. |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| "General Bots" is a registered trademark of Pragmatismo.io. |
|
||||
| The licensing of the program under the AGPLv3 does not imply a |
|
||||
| trademark license. Therefore any rights, title and interest in |
|
||||
| our trademarks remain entirely with us. |
|
||||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
/**
|
||||
* @fileoverview General Bots server core.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { GBDialogStep, GBLog, GBMinInstance, IGBCoreService, IGBPackage } from 'botlib';
|
||||
import { Sequelize } from 'sequelize-typescript';
|
||||
|
||||
/**
|
||||
* Package for GoogleChat.gblib
|
||||
*/
|
||||
export class GBHubSpotPackage implements IGBPackage {
|
||||
public sysPackages: IGBPackage[];
|
||||
|
||||
public async loadBot(min: GBMinInstance): Promise<void> {
|
||||
|
||||
}
|
||||
|
||||
public async getDialogs(min: GBMinInstance) {
|
||||
GBLog.verbose(`getDialogs called.`);
|
||||
}
|
||||
public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
|
||||
GBLog.verbose(`loadPackage called.`);
|
||||
}
|
||||
public async unloadPackage(core: IGBCoreService): Promise<void> {
|
||||
GBLog.verbose(`unloadPackage called.`);
|
||||
}
|
||||
public async unloadBot(min: GBMinInstance): Promise<void> {
|
||||
GBLog.verbose(`unloadBot called.`);
|
||||
}
|
||||
public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
|
||||
GBLog.verbose(`onNewSession called.`);
|
||||
}
|
||||
public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
|
||||
GBLog.verbose(`onExchangeData called.`);
|
||||
}
|
||||
|
||||
}
|
99
packages/hubspot.gblib/services/HubSpotServices.ts
Normal file
99
packages/hubspot.gblib/services/HubSpotServices.ts
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*****************************************************************************\
|
||||
| ( )_ _ |
|
||||
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
|
||||
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
|
||||
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| (˅) |( (_) ) |
|
||||
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
|
||||
| | | ( )_) | |
|
||||
| (_) \___/' |
|
||||
| |
|
||||
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
|
||||
| Licensed under the AGPL-3.0. |
|
||||
| |
|
||||
| According to our dual licensing model, this program can be used either |
|
||||
| under the terms of the GNU Affero General Public License, version 3, |
|
||||
| or under a proprietary license. |
|
||||
| |
|
||||
| The texts of the GNU Affero General Public License with an additional |
|
||||
| permission and of our proprietary license can be found at and |
|
||||
| in the LICENSE file you have received along with this program. |
|
||||
| |
|
||||
| This program is distributed in the hope that it will be useful, |
|
||||
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
| GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| "General Bots" is a registered trademark of Pragmatismo.io. |
|
||||
| The licensing of the program under the AGPLv3 does not imply a |
|
||||
| trademark license. Therefore any rights, title and interest in |
|
||||
| our trademarks remain entirely with us. |
|
||||
| |
|
||||
\*****************************************************************************/
|
||||
|
||||
const Swagger = require('swagger-client');
|
||||
const fs = require('fs');
|
||||
const { promisify } = require('util');
|
||||
import { GBLog, GBMinInstance, GBService } from 'botlib';
|
||||
import { GBServer } from '../../../src/app';
|
||||
import { SecService } from '../../security.gbapp/services/SecService';
|
||||
|
||||
/**
|
||||
* Support for Hub Spot XRM.
|
||||
*/
|
||||
export class HubSpotServices extends GBService {
|
||||
|
||||
public static conversationIds = {};
|
||||
public pollInterval = 5000;
|
||||
|
||||
public botId: string;
|
||||
public min: GBMinInstance;
|
||||
private key: any;
|
||||
|
||||
constructor(
|
||||
min: GBMinInstance,
|
||||
botId,
|
||||
key
|
||||
) {
|
||||
super();
|
||||
|
||||
this.min = min;
|
||||
this.botId = botId;
|
||||
this.key = key;
|
||||
|
||||
}
|
||||
public static async asyncForEach(array, callback) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
}
|
||||
|
||||
public async getActiveTasks(): Promise<[]> {
|
||||
|
||||
const hubspot = require('@hubspot/api-client');
|
||||
const client = new hubspot.Client({ apiKey: this.key });
|
||||
let properties = ['hs_task_subject', 'hubspot_owner_id', 'hs_task_status', 'hs_task_priority'];
|
||||
const pageSize = 100;
|
||||
let list;
|
||||
list = [];
|
||||
|
||||
let r = await client.crm.objects.basicApi.getPage("TASK", pageSize, 0, properties);
|
||||
list = list.concat(r.body.results);
|
||||
|
||||
while (r.body.results && r.body.results.length === pageSize) {
|
||||
r = await client.crm.objects.basicApi.getPage("TASK", pageSize, r.body.paging.next.after, properties);
|
||||
list = list.concat(r.body.results);
|
||||
}
|
||||
|
||||
let final;
|
||||
final = [];
|
||||
list.forEach(e => {
|
||||
if (e.properties.hs_task_status === "NOT_STARTED")
|
||||
{
|
||||
final.push(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return final;
|
||||
}
|
||||
}
|
8
packages/hubspot.gblib/strings.ts
Normal file
8
packages/hubspot.gblib/strings.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
export const Messages = {
|
||||
'en-US': {
|
||||
|
||||
},
|
||||
'pt-BR': {
|
||||
|
||||
}
|
||||
};
|
|
@ -67,7 +67,6 @@ export class RootData {
|
|||
public wwwroot: string; // .gbui or a static webapp.
|
||||
public entryPointDialog: string; // To replace default welcome dialog.
|
||||
}
|
||||
|
||||
/**
|
||||
* General Bots open-core entry point.
|
||||
*/
|
||||
|
@ -106,6 +105,7 @@ export class GBServer {
|
|||
|
||||
server.listen(port, () => {
|
||||
(async () => {
|
||||
|
||||
try {
|
||||
GBLog.info(`Now accepting connections on ${port}...`);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue