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}.`);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
if(!min.instance.smsKey && min.instance.smsSecret) {
|
||||
if (!min.instance.smsKey && min.instance.smsSecret) {
|
||||
const url = 'http://sms-api.megaconecta.com.br/mt';
|
||||
let options = {
|
||||
method: 'POST',
|
||||
|
@ -401,7 +401,7 @@ export class GBConversationalService {
|
|||
|
||||
return Promise.reject(new Error(msg));
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
if (min.instance.smsKey && min.instance.smsSecret) {
|
||||
return new Promise((resolve: any, reject: any): any => {
|
||||
const nexmo = new Nexmo({
|
||||
|
@ -420,15 +420,15 @@ export class GBConversationalService {
|
|||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async sendToMobile(min: GBMinInstance, mobile: string, message: string, conversationId) {
|
||||
GBLog.info(`Sending message ${message} to ${mobile}...`);
|
||||
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) => {
|
||||
const name = GBAdminService.getRndReadableIdentifier();
|
||||
|
||||
|
@ -466,9 +466,9 @@ export class GBConversationalService {
|
|||
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) => {
|
||||
try {
|
||||
const oggFile = new Readable();
|
||||
|
@ -536,7 +536,7 @@ export class GBConversationalService {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public static getIBMAudioModelNameFromLocale = locale => {
|
||||
const locales = {
|
||||
"ar": "ar-MS_BroadbandModel",
|
||||
|
@ -554,7 +554,7 @@ export class GBConversationalService {
|
|||
|
||||
const languageCode = locale.substring(0, 2);
|
||||
return locales[languageCode] || "en-US_BroadbandModel";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
public async playMarkdown(min: GBMinInstance, answer: string, channel: string,
|
||||
|
@ -626,7 +626,7 @@ export class GBConversationalService {
|
|||
const html = marked(text);
|
||||
await min.conversationalService.sendText(min, step, html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async sendHTMLToWeb(min, step: GBDialogStep, html: string, answer: string) {
|
||||
const locale = step.context.activity.locale;
|
||||
|
@ -641,7 +641,7 @@ export class GBConversationalService {
|
|||
nextId: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:enable:no-unsafe-any
|
||||
|
||||
|
@ -808,7 +808,7 @@ export class GBConversationalService {
|
|||
await this.sendToMobile(min, mobile, currentText, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async routeNLP(step: GBDialogStep, min: GBMinInstance, text: string) {
|
||||
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}`);
|
||||
|
||||
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);
|
||||
if(!key) {
|
||||
if (!key) {
|
||||
return process.env.DEFAULT_USER_LANGUAGE;
|
||||
}
|
||||
let language = await AzureText.getLocale(
|
||||
|
@ -926,12 +926,12 @@ export class GBConversationalService {
|
|||
);
|
||||
|
||||
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);
|
||||
|
||||
if(key) {
|
||||
if (key) {
|
||||
text = text.charAt(0).toUpperCase() + text.slice(1);
|
||||
const data = await AzureText.getSpelledText(key, text);
|
||||
if (data !== text) {
|
||||
|
@ -941,9 +941,9 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
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 = () => {
|
||||
if (min.instance.params) {
|
||||
|
@ -955,23 +955,23 @@ export class GBConversationalService {
|
|||
const endPoint = min.core.getParam<string>(min.instance, 'translatorEndpoint', null);
|
||||
const key = min.core.getParam<string>(min.instance, 'translatorKey', null);
|
||||
|
||||
if(
|
||||
if (
|
||||
(endPoint === null && !min.instance.googleProjectId) ||
|
||||
!translatorEnabled() ||
|
||||
process.env.TRANSLATOR_DISABLED === 'true'
|
||||
) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
if (text.length > 5000) {
|
||||
if (text.length > 5000) {
|
||||
text = text.substr(0, 4999);
|
||||
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;
|
||||
}
|
||||
text = text.replace('¿', '');
|
||||
}
|
||||
text = text.replace('¿', '');
|
||||
|
||||
if (min.instance.googleProjectId) {
|
||||
if (min.instance.googleProjectId) {
|
||||
// Instantiates a client
|
||||
|
||||
const translate = new Translate.v2.Translate({
|
||||
|
@ -991,7 +991,7 @@ if (min.instance.googleProjectId) {
|
|||
|
||||
return Promise.reject(new Error(msg));
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
let url = urlJoin(
|
||||
endPoint,
|
||||
'translate');
|
||||
|
@ -1028,7 +1028,7 @@ if (min.instance.googleProjectId) {
|
|||
|
||||
return Promise.reject(new Error(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async handleText(min, user, step, text: string) {
|
||||
|
@ -1147,7 +1147,7 @@ if (min.instance.googleProjectId) {
|
|||
GBLog.info(`After (processMessageActivity): ${text}.`);
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public async prompt(min: GBMinInstance, step: GBDialogStep, text: string) {
|
||||
let sec = new SecService();
|
||||
|
@ -1168,17 +1168,17 @@ if (min.instance.googleProjectId) {
|
|||
await this.sendText(min, step, text);
|
||||
return await step.prompt('textPrompt', {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async sendText(min: GBMinInstance, step, text) {
|
||||
await this['sendTextWithOptions'](min, step, text, true, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendTextWithOptions(min: GBMinInstance, step, text, translate, keepTextList) {
|
||||
let sec = new SecService();
|
||||
let user = await sec.getUserFromSystemId(step.context.activity.from.id);
|
||||
await this['sendTextWithOptionsAndUser'](min, user, step, text, true, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendTextWithOptionsAndUser(min: GBMinInstance, user, step, text, translate, keepTextList) {
|
||||
const member = step ? step.context.activity.from : null;
|
||||
|
@ -1230,7 +1230,7 @@ if (min.instance.googleProjectId) {
|
|||
} else {
|
||||
await step.context.sendActivity(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
public async broadcast(min: GBMinInstance, message: string) {
|
||||
GBLog.info(`Sending broadcast notifications...`);
|
||||
|
||||
|
@ -1243,7 +1243,7 @@ if (min.instance.googleProjectId) {
|
|||
GBLog.info(`User: ${user.Id} with no conversation ID while broadcasting.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1268,7 +1268,7 @@ if (min.instance.googleProjectId) {
|
|||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static kmpSearch(pattern, text) {
|
||||
pattern = pattern.toLowerCase();
|
||||
|
@ -1294,5 +1294,5 @@ if (min.instance.googleProjectId) {
|
|||
}
|
||||
}
|
||||
return -1; // Not found
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue