new(security.gblib): SMS Auth.
This commit is contained in:
parent
6112ce9a1c
commit
4cd64f8a90
1 changed files with 823 additions and 823 deletions
|
@ -372,10 +372,10 @@ export class GBConversationalService {
|
||||||
})
|
})
|
||||||
|
|
||||||
GBLogEx.info(min, `SMS sent, return: ${msg.sid}.`);
|
GBLogEx.info(min, `SMS sent, return: ${msg.sid}.`);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!min.instance.smsKey && min.instance.smsSecret) {
|
if (!min.instance.smsKey && min.instance.smsSecret) {
|
||||||
const url = 'http://sms-api.megaconecta.com.br/mt';
|
const url = 'http://sms-api.megaconecta.com.br/mt';
|
||||||
let options = {
|
let options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -401,7 +401,7 @@ export class GBConversationalService {
|
||||||
|
|
||||||
return Promise.reject(new Error(msg));
|
return Promise.reject(new Error(msg));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (min.instance.smsKey && min.instance.smsSecret) {
|
if (min.instance.smsKey && min.instance.smsSecret) {
|
||||||
return new Promise((resolve: any, reject: any): any => {
|
return new Promise((resolve: any, reject: any): any => {
|
||||||
const nexmo = new Nexmo({
|
const nexmo = new Nexmo({
|
||||||
|
@ -420,15 +420,15 @@ export class GBConversationalService {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendToMobile(min: GBMinInstance, mobile: string, message: string, conversationId) {
|
public async sendToMobile(min: GBMinInstance, mobile: string, message: string, conversationId) {
|
||||||
GBLog.info(`Sending message ${message} to ${mobile}...`);
|
GBLog.info(`Sending message ${message} to ${mobile}...`);
|
||||||
await min.whatsAppDirectLine.sendToDevice(mobile, message, conversationId);
|
await min.whatsAppDirectLine.sendToDevice(mobile, message, conversationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getAudioBufferFromText(text): Promise < string > {
|
public static async getAudioBufferFromText(text): Promise<string> {
|
||||||
return new Promise<string>(async (resolve, reject) => {
|
return new Promise<string>(async (resolve, reject) => {
|
||||||
const name = GBAdminService.getRndReadableIdentifier();
|
const name = GBAdminService.getRndReadableIdentifier();
|
||||||
|
|
||||||
|
@ -466,9 +466,9 @@ export class GBConversationalService {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getTextFromAudioBuffer(speechKey, cloudRegion, buffer, locale): Promise < string > {
|
public static async getTextFromAudioBuffer(speechKey, cloudRegion, buffer, locale): Promise<string> {
|
||||||
return new Promise<string>(async (resolve, reject) => {
|
return new Promise<string>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const oggFile = new Readable();
|
const oggFile = new Readable();
|
||||||
|
@ -536,7 +536,7 @@ export class GBConversationalService {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public static getIBMAudioModelNameFromLocale = locale => {
|
public static getIBMAudioModelNameFromLocale = locale => {
|
||||||
const locales = {
|
const locales = {
|
||||||
"ar": "ar-MS_BroadbandModel",
|
"ar": "ar-MS_BroadbandModel",
|
||||||
|
@ -554,7 +554,7 @@ export class GBConversationalService {
|
||||||
|
|
||||||
const languageCode = locale.substring(0, 2);
|
const languageCode = locale.substring(0, 2);
|
||||||
return locales[languageCode] || "en-US_BroadbandModel";
|
return locales[languageCode] || "en-US_BroadbandModel";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public async playMarkdown(min: GBMinInstance, answer: string, channel: string,
|
public async playMarkdown(min: GBMinInstance, answer: string, channel: string,
|
||||||
|
@ -626,7 +626,7 @@ export class GBConversationalService {
|
||||||
const html = marked(text);
|
const html = marked(text);
|
||||||
await min.conversationalService.sendText(min, step, html);
|
await min.conversationalService.sendText(min, step, html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sendHTMLToWeb(min, step: GBDialogStep, html: string, answer: string) {
|
private async sendHTMLToWeb(min, step: GBDialogStep, html: string, answer: string) {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
|
@ -641,7 +641,7 @@ export class GBConversationalService {
|
||||||
nextId: 0
|
nextId: 0
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:enable:no-unsafe-any
|
// tslint:enable:no-unsafe-any
|
||||||
|
|
||||||
|
@ -808,7 +808,7 @@ export class GBConversationalService {
|
||||||
await this.sendToMobile(min, mobile, currentText, null);
|
await this.sendToMobile(min, mobile, currentText, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async routeNLP(step: GBDialogStep, min: GBMinInstance, text: string) {
|
public async routeNLP(step: GBDialogStep, min: GBMinInstance, text: string) {
|
||||||
if (min.instance.nlpAppId === null || min.instance.nlpAppId === undefined) {
|
if (min.instance.nlpAppId === null || min.instance.nlpAppId === undefined) {
|
||||||
|
@ -912,11 +912,11 @@ export class GBConversationalService {
|
||||||
GBLog.info(`NLP NOT called: score: ${score} > required (nlpScore): ${instanceScore}`);
|
GBLog.info(`NLP NOT called: score: ${score} > required (nlpScore): ${instanceScore}`);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getLanguage(min: GBMinInstance, text: string): Promise < string > {
|
public async getLanguage(min: GBMinInstance, text: string): Promise<string> {
|
||||||
const key = min.core.getParam<string>(min.instance, 'textAnalyticsKey', null);
|
const key = min.core.getParam<string>(min.instance, 'textAnalyticsKey', null);
|
||||||
if(!key) {
|
if (!key) {
|
||||||
return process.env.DEFAULT_USER_LANGUAGE;
|
return process.env.DEFAULT_USER_LANGUAGE;
|
||||||
}
|
}
|
||||||
let language = await AzureText.getLocale(
|
let language = await AzureText.getLocale(
|
||||||
|
@ -926,12 +926,12 @@ export class GBConversationalService {
|
||||||
);
|
);
|
||||||
|
|
||||||
return language === '(Unknown)' ? 'en' : language;
|
return language === '(Unknown)' ? 'en' : language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async spellCheck(min: GBMinInstance, text: string): Promise < string > {
|
public async spellCheck(min: GBMinInstance, text: string): Promise<string> {
|
||||||
const key = min.core.getParam<string>(min.instance, 'spellcheckerKey', null);
|
const key = min.core.getParam<string>(min.instance, 'spellcheckerKey', null);
|
||||||
|
|
||||||
if(key) {
|
if (key) {
|
||||||
text = text.charAt(0).toUpperCase() + text.slice(1);
|
text = text.charAt(0).toUpperCase() + text.slice(1);
|
||||||
const data = await AzureText.getSpelledText(key, text);
|
const data = await AzureText.getSpelledText(key, text);
|
||||||
if (data !== text) {
|
if (data !== text) {
|
||||||
|
@ -941,9 +941,9 @@ export class GBConversationalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async translate(min: GBMinInstance, text: string, language: string): Promise < string > {
|
public async translate(min: GBMinInstance, text: string, language: string): Promise<string> {
|
||||||
|
|
||||||
const translatorEnabled = () => {
|
const translatorEnabled = () => {
|
||||||
if (min.instance.params) {
|
if (min.instance.params) {
|
||||||
|
@ -955,23 +955,23 @@ export class GBConversationalService {
|
||||||
const endPoint = min.core.getParam<string>(min.instance, 'translatorEndpoint', null);
|
const endPoint = min.core.getParam<string>(min.instance, 'translatorEndpoint', null);
|
||||||
const key = min.core.getParam<string>(min.instance, 'translatorKey', null);
|
const key = min.core.getParam<string>(min.instance, 'translatorKey', null);
|
||||||
|
|
||||||
if(
|
if (
|
||||||
(endPoint === null && !min.instance.googleProjectId) ||
|
(endPoint === null && !min.instance.googleProjectId) ||
|
||||||
!translatorEnabled() ||
|
!translatorEnabled() ||
|
||||||
process.env.TRANSLATOR_DISABLED === 'true'
|
process.env.TRANSLATOR_DISABLED === 'true'
|
||||||
) {
|
) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text.length > 5000) {
|
if (text.length > 5000) {
|
||||||
text = text.substr(0, 4999);
|
text = text.substr(0, 4999);
|
||||||
GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`);
|
GBLog.warn(`Text that bot will translate will be truncated due to MSFT service limitations.`);
|
||||||
} else if (text.length == 2) {
|
} else if (text.length == 2) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
text = text.replace('¿', '');
|
text = text.replace('¿', '');
|
||||||
|
|
||||||
if (min.instance.googleProjectId) {
|
if (min.instance.googleProjectId) {
|
||||||
// Instantiates a client
|
// Instantiates a client
|
||||||
|
|
||||||
const translate = new Translate.v2.Translate({
|
const translate = new Translate.v2.Translate({
|
||||||
|
@ -991,7 +991,7 @@ if (min.instance.googleProjectId) {
|
||||||
|
|
||||||
return Promise.reject(new Error(msg));
|
return Promise.reject(new Error(msg));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let url = urlJoin(
|
let url = urlJoin(
|
||||||
endPoint,
|
endPoint,
|
||||||
'translate');
|
'translate');
|
||||||
|
@ -1028,7 +1028,7 @@ if (min.instance.googleProjectId) {
|
||||||
|
|
||||||
return Promise.reject(new Error(msg));
|
return Promise.reject(new Error(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async handleText(min, user, step, text: string) {
|
public static async handleText(min, user, step, text: string) {
|
||||||
|
@ -1147,7 +1147,7 @@ if (min.instance.googleProjectId) {
|
||||||
GBLog.info(`After (processMessageActivity): ${text}.`);
|
GBLog.info(`After (processMessageActivity): ${text}.`);
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
|
@ -1168,17 +1168,17 @@ if (min.instance.googleProjectId) {
|
||||||
await this.sendText(min, step, text);
|
await this.sendText(min, step, text);
|
||||||
return await step.prompt('textPrompt', {});
|
return await step.prompt('textPrompt', {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendText(min: GBMinInstance, step, text) {
|
public async sendText(min: GBMinInstance, step, text) {
|
||||||
await this['sendTextWithOptions'](min, step, text, true, null);
|
await this['sendTextWithOptions'](min, step, text, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendTextWithOptions(min: GBMinInstance, step, text, translate, keepTextList) {
|
public async sendTextWithOptions(min: GBMinInstance, step, text, translate, keepTextList) {
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
|
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
|
||||||
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);
|
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendTextWithOptionsAndUser(min: GBMinInstance, user, step, text, translate, keepTextList) {
|
public async sendTextWithOptionsAndUser(min: GBMinInstance, user, step, text, translate, keepTextList) {
|
||||||
const member = step ? step.context.activity.from : null;
|
const member = step ? step.context.activity.from : null;
|
||||||
|
@ -1230,7 +1230,7 @@ if (min.instance.googleProjectId) {
|
||||||
} else {
|
} else {
|
||||||
await step.context.sendActivity(text);
|
await step.context.sendActivity(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async broadcast(min: GBMinInstance, message: string) {
|
public async broadcast(min: GBMinInstance, message: string) {
|
||||||
GBLog.info(`Sending broadcast notifications...`);
|
GBLog.info(`Sending broadcast notifications...`);
|
||||||
|
|
||||||
|
@ -1243,7 +1243,7 @@ if (min.instance.googleProjectId) {
|
||||||
GBLog.info(`User: ${user.Id} with no conversation ID while broadcasting.`);
|
GBLog.info(`User: ${user.Id} with no conversation ID while broadcasting.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -1268,7 +1268,7 @@ if (min.instance.googleProjectId) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static kmpSearch(pattern, text) {
|
public static kmpSearch(pattern, text) {
|
||||||
pattern = pattern.toLowerCase();
|
pattern = pattern.toLowerCase();
|
||||||
|
@ -1294,5 +1294,5 @@ if (min.instance.googleProjectId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1; // Not found
|
return -1; // Not found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue