new(basic.gblib): WhatsApp buttons.
This commit is contained in:
parent
8b84a9201a
commit
b23111dfad
9 changed files with 17355 additions and 38 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -26839,6 +26839,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"yarn": {
|
||||
"version": "1.22.19",
|
||||
"resolved": "https://registry.npmjs.org/yarn/-/yarn-1.22.19.tgz",
|
||||
"integrity": "sha512-/0V5q0WbslqnwP91tirOvldvYISzaqhClxzyUKXYxs07yUILIs5jx/k6CFe8bvKSkds5w+eiOqta39Wk3WxdcQ=="
|
||||
},
|
||||
"yauzl": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.7.0.tgz",
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
"@semantic-release/exec": "5.0.0",
|
||||
"@semantic-release/git": "9.0.0",
|
||||
"@sendgrid/mail": "7.4.4",
|
||||
"@types/node": "8.0.0",
|
||||
"@types/validator": "13.1.4",
|
||||
"adal-node": "0.2.2",
|
||||
"adm-zip": "0.5.6",
|
||||
|
@ -147,9 +148,10 @@
|
|||
"vhost": "^3.0.2",
|
||||
"walk-promise": "0.2.0",
|
||||
"washyourmouthoutwithsoap": "1.0.2",
|
||||
"whatsapp-web.js": "1.17.0",
|
||||
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#fix-buttons-list",
|
||||
"winston": "^2.4.2",
|
||||
"winston-logs-display": "^1.0.0"
|
||||
"winston-logs-display": "^1.0.0",
|
||||
"yarn": "^1.22.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/puppeteer": "5.4.6",
|
||||
|
|
|
@ -57,20 +57,20 @@ export class AnalyticsService {
|
|||
}
|
||||
|
||||
public async updateConversationSuggestion(instanceId: number,
|
||||
conversationId: string, feedback: string, locale: string): Promise<number> {
|
||||
conversationId: string, feedback: string, locale: string): Promise<number> {
|
||||
|
||||
const minBoot = GBServer.globals.minBoot as any;
|
||||
const rate = await AzureText.getSentiment(
|
||||
minBoot.instance.textAnalyticsKey ? minBoot.instance.textAnalyticsKey :
|
||||
minBoot.instance.textAnalyticsKey,
|
||||
minBoot.instance.textAnalyticsEndpoint ? minBoot.instance.textAnalyticsEndpoint :
|
||||
minBoot.instance.textAnalyticsEndpoint,
|
||||
minBoot.instance.textAnalyticsEndpoint,
|
||||
locale,
|
||||
feedback
|
||||
);
|
||||
|
||||
const options = <FindOptions>{ where: { } };
|
||||
options.where = { conversationId: conversationId, instanceId: instanceId };
|
||||
const options = <FindOptions>{ where: {} };
|
||||
options.where = { conversationId: conversationId, instanceId: instanceId };
|
||||
const item = await GuaribasConversation.findOne(options);
|
||||
|
||||
item.feedback = feedback;
|
||||
|
@ -90,7 +90,7 @@ export class AnalyticsService {
|
|||
): Promise<GuaribasConversationMessage> {
|
||||
|
||||
const message = GuaribasConversationMessage.build();
|
||||
message.content = content;
|
||||
message.content = typeof (content) === 'object' ? JSON.stringify(content) : content;
|
||||
message.instanceId = instanceId;
|
||||
message.userId = userId;
|
||||
message.conversationId = conversation.conversationId;
|
||||
|
|
|
@ -39,11 +39,12 @@ import { CollectionUtil } from 'pragmatismo-io-framework';
|
|||
import * as request from 'request-promise-native';
|
||||
import { Messages } from '../strings';
|
||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService';
|
||||
import { GBConfigService } from '../../core.gbapp/services/GBConfigService';
|
||||
const { Buttons } = require('whatsapp-web.js');
|
||||
const Path = require('path');
|
||||
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
|
||||
const phone = require('phone');
|
||||
|
||||
|
||||
//tslint:disable-next-line:no-submodule-imports
|
||||
/**
|
||||
* HEAR Bot Framework support.
|
||||
|
@ -52,7 +53,7 @@ export class HearDialog {
|
|||
|
||||
private static async downloadAttachmentAndWrite(attachment) {
|
||||
|
||||
|
||||
|
||||
const url = attachment.contentUrl;
|
||||
const localFolder = Path.join('work'); // TODO: , '${botId}', 'uploads');
|
||||
const localFileName = Path.join(localFolder, attachment.name);
|
||||
|
@ -60,23 +61,23 @@ export class HearDialog {
|
|||
try {
|
||||
|
||||
let response;
|
||||
if (url.startsWith('data:')){
|
||||
if (url.startsWith('data:')) {
|
||||
var regex = /^data:.+\/(.+);base64,(.*)$/;
|
||||
var matches = url.match(regex);
|
||||
var ext = matches[1];
|
||||
var data = matches[2];
|
||||
response = Buffer.from(data, 'base64');
|
||||
}
|
||||
else{
|
||||
// arraybuffer is necessary for images
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
};
|
||||
response = await request.get(options);
|
||||
}
|
||||
|
||||
else {
|
||||
// arraybuffer is necessary for images
|
||||
const options = {
|
||||
url: url,
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
};
|
||||
response = await request.get(options);
|
||||
}
|
||||
|
||||
fs.writeFile(localFileName, response, (fsError) => {
|
||||
if (fsError) {
|
||||
throw fsError;
|
||||
|
@ -102,7 +103,21 @@ export class HearDialog {
|
|||
step.activeDialog.state.options.id = (step.options as any).id;
|
||||
step.activeDialog.state.options.previousResolve = (step.options as any).previousResolve;
|
||||
|
||||
if (step.options['args']) {
|
||||
|
||||
const args = step.options['args'];
|
||||
if (args) {
|
||||
|
||||
let choices = [];
|
||||
let i = 0;
|
||||
args.forEach(arg => {
|
||||
i++;
|
||||
choices.push({ body: arg, id: `button${i}` });
|
||||
});
|
||||
|
||||
const locale = step.context.activity.locale;
|
||||
const button = new Buttons(Messages[locale].choices, choices, ' ', ' ');
|
||||
|
||||
await min.conversationalService.sendText(min, step, button);
|
||||
|
||||
GBLog.info(`BASIC: Asking for input (HEAR with ${step.options['args'][0]}).`);
|
||||
}
|
||||
|
@ -126,9 +141,9 @@ export class HearDialog {
|
|||
} else {
|
||||
|
||||
if (step.activeDialog.state.options['kind'] === "file") {
|
||||
return await step.prompt('attachmentPrompt', {});
|
||||
return await step.prompt('attachmentPrompt', {});
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return await min.conversationalService.prompt(min, step, null);
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +177,7 @@ export class HearDialog {
|
|||
// The current TurnContext is bound so `replyForReceivedAttachments` can also send replies.
|
||||
const replyPromises = successfulSaves.map(replyForReceivedAttachments.bind(step.context));
|
||||
await Promise.all(replyPromises);
|
||||
|
||||
|
||||
result = {
|
||||
data: fs.readFileSync(successfulSaves[0].localPath),
|
||||
filename: successfulSaves[0].fileName
|
||||
|
|
|
@ -317,9 +317,8 @@ export class DialogKeywords {
|
|||
|
||||
private async debugStepWeb(page) {
|
||||
|
||||
let refresh = false;
|
||||
if (this.lastDebugWeb)
|
||||
{
|
||||
let refresh = true;
|
||||
if (this.lastDebugWeb) {
|
||||
refresh = (new Date().getTime() - this.lastDebugWeb.getTime()) > 5000;
|
||||
}
|
||||
|
||||
|
@ -979,11 +978,12 @@ export class DialogKeywords {
|
|||
|
||||
// Handles SEND FILE TO mobile, element in Web Automation.
|
||||
|
||||
const page = filename._page;
|
||||
if (page) {
|
||||
const element = filename._page ? filename._page : (filename.screenshot ? filename : null);
|
||||
|
||||
if (element) {
|
||||
const gbaiName = `${this.min.botId}.gbai`;
|
||||
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
|
||||
await filename.screenshot({ path: localName, fullPage: true });
|
||||
await element.screenshot({ path: localName, fullPage: true });
|
||||
|
||||
const url = urlJoin(
|
||||
GBServer.globals.publicAddress,
|
||||
|
|
|
@ -83,7 +83,7 @@ export class GBVMService extends GBService {
|
|||
let writeVBS = true;
|
||||
if (fs.existsSync(fullVbsFile)) {
|
||||
const vbsStat = fs.statSync(fullVbsFile);
|
||||
if (docxStat.mtimeMs < vbsStat.mtimeMs + interval) {
|
||||
if (docxStat['mtimeMs'] < vbsStat['mtimeMs'] + interval) {
|
||||
writeVBS = false;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ export class GBVMService extends GBService {
|
|||
if (fs.existsSync(jsfile)) {
|
||||
const jsStat = fs.statSync(jsfile);
|
||||
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
||||
if (compiledAt.isFile() && compiledAt.mtimeMs > jsStat.mtimeMs + interval) {
|
||||
if (compiledAt.isFile() && compiledAt['mtimeMs'] > jsStat['mtimeMs'] + interval) {
|
||||
await this.executeBASIC(fullFilename, min, deployer, mainName);
|
||||
} else {
|
||||
const parsedCode: string = fs.readFileSync(jsfile, 'utf8');
|
||||
|
@ -594,7 +594,7 @@ export class GBVMService extends GBService {
|
|||
|
||||
const vbsCode = this.convertGBASICToVBS(basicCode);
|
||||
const vbsFile = `${filename}.compiled`;
|
||||
fs.writeFileSync(vbsFile, vbsCode, 'utf8');
|
||||
fs.writeFileSync(vbsFile, vbsCode);
|
||||
|
||||
// Converts VBS into TS.
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
|
||||
export const Messages = {
|
||||
'en-US': {
|
||||
affirmative_sentences: /^(\bsim\b|\bs\b|\bpositivo\b|\bafirmativo\b|\bclaro\b|\bevidente\b|\bsem dúvida\b|\bconfirmo\b|\bconfirmar\b|\bconfirmado\b|\buhum\b|\bsi\b|\by\b|\byes\b|\bsure\b)/i
|
||||
affirmative_sentences: /^(\bsim\b|\bs\b|\bpositivo\b|\bafirmativo\b|\bclaro\b|\bevidente\b|\bsem dúvida\b|\bconfirmo\b|\bconfirmar\b|\bconfirmado\b|\buhum\b|\bsi\b|\by\b|\byes\b|\bsure\b)/i,
|
||||
choices: 'Please, select one:'
|
||||
},
|
||||
'pt-BR': {
|
||||
affirmative_sentences: /^(\bsim\b|\bs\b|\bpositivo\b|\bafirmativo\b|\bclaro\b|\bevidente\b|\bsem dúvida\b|\bconfirmo\b|\bconfirmar\b|\bconfirmado\b|\buhum\b|\bsi\b|\by\b|\byes\b|\bsure\b)/i
|
||||
affirmative_sentences: /^(\bsim\b|\bs\b|\bpositivo\b|\bafirmativo\b|\bclaro\b|\bevidente\b|\bsem dúvida\b|\bconfirmo\b|\bconfirmar\b|\bconfirmado\b|\buhum\b|\bsi\b|\by\b|\byes\b|\bsure\b)/i,
|
||||
choices: 'Por favor, selecione:'
|
||||
}
|
||||
};
|
||||
|
|
|
@ -668,7 +668,8 @@ export class WhatsappDirectLine extends GBService {
|
|||
watermark = response.obj.watermark;
|
||||
await this.printMessages(response.obj.activities, conversationId, from, fromName);
|
||||
} catch (err) {
|
||||
GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data === undefined ? err : err.data}`);
|
||||
GBLog.error(`Error calling printMessages on Whatsapp channel ${err.data === undefined ?
|
||||
err : err.data} ${err.errObj ? err.errObj.message : ''}`);
|
||||
}
|
||||
};
|
||||
setInterval(worker, this.pollInterval);
|
||||
|
@ -858,7 +859,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
let chatId = WhatsappDirectLine.chatIds[conversationId];
|
||||
|
||||
if (msg.startsWith(cmd)) {
|
||||
if (typeof (msg) !== 'object' && msg.startsWith(cmd)) {
|
||||
msg = msg.substr(cmd.length);
|
||||
|
||||
return await this.sendTextAsAudioToDevice(to, msg, chatId);
|
||||
|
@ -1059,7 +1060,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
const botId = getKeyByValue(WhatsappDirectLine.botGroups, group);
|
||||
if (botId && user.instanceId !== this.min.instance.instanceId || !user) {
|
||||
user = await sec.ensureUser(this.min.instance.instanceId, id, senderName, '', 'whatsApp', senderName, null);
|
||||
|
||||
|
||||
}
|
||||
if (botId) {
|
||||
activeMin = GBServer.globals.minInstances.filter
|
||||
|
|
Loading…
Add table
Reference in a new issue