Merge branch 'main' of https://github.com/GeneralBots/BotServer
This commit is contained in:
commit
33a5efa17b
2 changed files with 29 additions and 50 deletions
|
@ -608,9 +608,6 @@ export class DialogKeywords {
|
||||||
|
|
||||||
private async setOption({pid, name, value})
|
private async setOption({pid, name, value})
|
||||||
{
|
{
|
||||||
if (this.isUserSystemParam(name)){
|
|
||||||
throw new Error(`Not possible to define ${name} as it is a reserved system param name.`);
|
|
||||||
}
|
|
||||||
const process = GBServer.globals.processes[pid];
|
const process = GBServer.globals.processes[pid];
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
||||||
const sec = new SecService();
|
const sec = new SecService();
|
||||||
|
@ -619,17 +616,6 @@ export class DialogKeywords {
|
||||||
return { min, user, params };
|
return { min, user, params };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getOption({pid, name})
|
|
||||||
{
|
|
||||||
if (this.isUserSystemParam(name)){
|
|
||||||
throw new Error(`Not possible to retrieve ${name} system param.`);
|
|
||||||
}
|
|
||||||
const process = GBServer.globals.processes[pid];
|
|
||||||
let { min, user, params } = await DialogKeywords.getProcessInfo(pid);
|
|
||||||
const sec = new SecService();
|
|
||||||
return await sec.getParam(user, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the maximum lines to scan in spreedsheets.
|
* Defines the maximum lines to scan in spreedsheets.
|
||||||
*
|
*
|
||||||
|
@ -825,14 +811,12 @@ export class DialogKeywords {
|
||||||
await sleep(DEFAULT_HEAR_POLL_INTERVAL);
|
await sleep(DEFAULT_HEAR_POLL_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
const answer = min.cbMap[userId].promise;
|
const text = min.cbMap[userId].promise;
|
||||||
|
|
||||||
if (kind === 'file') {
|
if (kind === 'file') {
|
||||||
GBLog.info(`BASIC (${min.botId}): Upload done for ${answer.filename}.`);
|
|
||||||
// TODO: answer.filename, answer.data.
|
|
||||||
|
|
||||||
} else if (kind === 'boolean') {
|
} else if (kind === 'boolean') {
|
||||||
if (isIntentYes('pt-BR', answer)) {
|
if (isIntentYes('pt-BR', text)) {
|
||||||
result = true;
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
|
@ -868,7 +852,7 @@ export class DialogKeywords {
|
||||||
return text.match(/\d+/gi);
|
return text.match(/\d+/gi);
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(answer);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk({ pid, text: 'Por favor, digite um número válido.' });
|
await this.talk({ pid, text: 'Por favor, digite um número válido.' });
|
||||||
|
@ -883,7 +867,7 @@ export class DialogKeywords {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(answer);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk({ pid, text: 'Por favor, digite uma data no formato 12/12/2020.' });
|
await this.talk({ pid, text: 'Por favor, digite uma data no formato 12/12/2020.' });
|
||||||
|
@ -896,7 +880,7 @@ export class DialogKeywords {
|
||||||
return text.match(/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/gi);
|
return text.match(/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/gi);
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(answer);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk({ pid, text: 'Por favor, digite um horário no formato hh:ss.' });
|
await this.talk({ pid, text: 'Por favor, digite um horário no formato hh:ss.' });
|
||||||
|
@ -915,7 +899,7 @@ export class DialogKeywords {
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(answer);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk({ pid, text: 'Por favor, digite um valor monetário.' });
|
await this.talk({ pid, text: 'Por favor, digite um valor monetário.' });
|
||||||
|
@ -927,7 +911,7 @@ export class DialogKeywords {
|
||||||
let phoneNumber;
|
let phoneNumber;
|
||||||
try {
|
try {
|
||||||
// https://github.com/GeneralBots/BotServer/issues/307
|
// https://github.com/GeneralBots/BotServer/issues/307
|
||||||
phoneNumber = phone(answer, { country: 'BRA' })[0];
|
phoneNumber = phone(text, { country: 'BRA' })[0];
|
||||||
phoneNumber = phoneUtil.parse(phoneNumber);
|
phoneNumber = phoneUtil.parse(phoneNumber);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.talk({ pid, text: Messages[locale].validation_enter_valid_mobile });
|
await this.talk({ pid, text: Messages[locale].validation_enter_valid_mobile });
|
||||||
|
@ -952,7 +936,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = extractEntity(answer);
|
const value = extractEntity(text);
|
||||||
|
|
||||||
if (value === null || value.length != 1) {
|
if (value === null || value.length != 1) {
|
||||||
await this.talk({ pid, text: 'Por favor, digite um CEP válido.' });
|
await this.talk({ pid, text: 'Por favor, digite um CEP válido.' });
|
||||||
|
@ -964,7 +948,7 @@ export class DialogKeywords {
|
||||||
const list = args;
|
const list = args;
|
||||||
result = null;
|
result = null;
|
||||||
await CollectionUtil.asyncForEach(list, async item => {
|
await CollectionUtil.asyncForEach(list, async item => {
|
||||||
if (GBConversationalService.kmpSearch(answer, item) != -1) {
|
if (GBConversationalService.kmpSearch(text, item) != -1) {
|
||||||
result = item;
|
result = item;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -994,8 +978,8 @@ export class DialogKeywords {
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(list, async item => {
|
await CollectionUtil.asyncForEach(list, async item => {
|
||||||
if (
|
if (
|
||||||
GBConversationalService.kmpSearch(answer.toLowerCase(), item.name.toLowerCase()) != -1 ||
|
GBConversationalService.kmpSearch(text.toLowerCase(), item.name.toLowerCase()) != -1 ||
|
||||||
GBConversationalService.kmpSearch(answer.toLowerCase(), item.code.toLowerCase()) != -1
|
GBConversationalService.kmpSearch(text.toLowerCase(), item.code.toLowerCase()) != -1
|
||||||
) {
|
) {
|
||||||
result = item.code;
|
result = item.code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -828,6 +828,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Get loaded user state
|
// Get loaded user state
|
||||||
|
|
||||||
|
const member = context.activity.from;
|
||||||
const step = await min.dialogs.createContext(context);
|
const step = await min.dialogs.createContext(context);
|
||||||
step.context.activity.locale = 'pt-BR';
|
step.context.activity.locale = 'pt-BR';
|
||||||
let firstTime = false;
|
let firstTime = false;
|
||||||
|
@ -1063,9 +1064,9 @@ export class GBMinService {
|
||||||
|
|
||||||
private static async downloadAttachmentAndWrite(attachment) {
|
private static async downloadAttachmentAndWrite(attachment) {
|
||||||
const url = attachment.contentUrl;
|
const url = attachment.contentUrl;
|
||||||
// TODO: https://github.com/GeneralBots/BotServer/issues/195 - '${botId}','uploads');
|
// https://github.com/GeneralBots/BotServer/issues/195 - '${botId}','uploads');
|
||||||
const localFolder = Path.join('work');
|
const localFolder = Path.join('work');
|
||||||
const localFileName = Path.join(localFolder, `${this['min'].botId}.gbai`, 'uploads', attachment.name);
|
const localFileName = Path.join(localFolder, this['botId'],'uploads', attachment.name);
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
if (url.startsWith('data:')) {
|
if (url.startsWith('data:')) {
|
||||||
|
@ -1127,29 +1128,21 @@ export class GBMinService {
|
||||||
|
|
||||||
context.activity.text = context.activity.text.trim();
|
context.activity.text = context.activity.text.trim();
|
||||||
|
|
||||||
const member = context.activity.from;
|
const user = await min.userProfile.get(context, {});
|
||||||
|
|
||||||
let user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name, null);
|
|
||||||
const userId = user.userId;
|
|
||||||
const params = user.params ? JSON.parse(user.params) : {};
|
|
||||||
|
|
||||||
let message: GuaribasConversationMessage;
|
let message: GuaribasConversationMessage;
|
||||||
if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
|
if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
|
||||||
// Adds message to the analytics layer.
|
// Adds message to the analytics layer.
|
||||||
|
|
||||||
const analytics = new AnalyticsService();
|
const analytics = new AnalyticsService();
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
let conversation;
|
if (!user.conversation) {
|
||||||
if (!user.conversationId) {
|
user.conversation = await analytics.createConversation(user.systemUser);
|
||||||
conversation = await analytics.createConversation(user);
|
|
||||||
user.conversationId = conversation.Id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message = await analytics.createMessage(
|
message = await analytics.createMessage(
|
||||||
min.instance.instanceId,
|
min.instance.instanceId,
|
||||||
user.conversationId,
|
user.conversation,
|
||||||
userId,
|
user.systemUser.userId,
|
||||||
context.activity.text
|
context.activity.text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1306,11 +1299,13 @@ export class GBMinService {
|
||||||
'Language Detector',
|
'Language Detector',
|
||||||
GBConfigService.getBoolean('LANGUAGE_DETECTOR')
|
GBConfigService.getBoolean('LANGUAGE_DETECTOR')
|
||||||
) === 'true';
|
) === 'true';
|
||||||
locale = user.locale;
|
const systemUser = user.systemUser;
|
||||||
|
locale = systemUser.locale;
|
||||||
if (text != '' && detectLanguage && !locale) {
|
if (text != '' && detectLanguage && !locale) {
|
||||||
locale = await min.conversationalService.getLanguage(min, text);
|
locale = await min.conversationalService.getLanguage(min, text);
|
||||||
if (user.locale != locale) {
|
if (systemUser.locale != locale) {
|
||||||
user = await sec.updateUserLocale(user.userId, locale);
|
user.systemUser = await sec.updateUserLocale(systemUser.userId, locale);
|
||||||
|
await min.userProfile.set(step.context, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1346,10 +1341,10 @@ export class GBMinService {
|
||||||
|
|
||||||
GBLog.info(`Text>: ${text}.`);
|
GBLog.info(`Text>: ${text}.`);
|
||||||
|
|
||||||
if (user.agentMode === 'self') {
|
if (user.systemUser.agentMode === 'self') {
|
||||||
const manualUser = await sec.getUserFromAgentSystemId(user.userSystemId);
|
const manualUser = await sec.getUserFromAgentSystemId(user.systemUser.userSystemId);
|
||||||
|
|
||||||
GBLog.info(`HUMAN AGENT (${user.userId}) TO USER ${manualUser.userSystemId}: ${text}`);
|
GBLog.info(`HUMAN AGENT (${user.systemUser.userSystemId}) TO USER ${manualUser.userSystemId}: ${text}`);
|
||||||
|
|
||||||
const cmd = 'SEND FILE ';
|
const cmd = 'SEND FILE ';
|
||||||
if (text.startsWith(cmd)) {
|
if (text.startsWith(cmd)) {
|
||||||
|
@ -1372,8 +1367,8 @@ export class GBMinService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (min.cbMap[userId] && min.cbMap[userId].promise == '!GBHEAR') {
|
if (min.cbMap[user.systemUser.userId] && min.cbMap[user.systemUser.userId].promise == '!GBHEAR') {
|
||||||
min.cbMap[userId].promise = text;
|
min.cbMap[user.systemUser.userId].promise = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a dialog in course, continue to the next step.
|
// If there is a dialog in course, continue to the next step.
|
||||||
|
|
Loading…
Add table
Reference in a new issue