new(whatsapp.gblib): General Bots WhatsApp provider.
This commit is contained in:
parent
b84d1a6983
commit
6891b8c8c4
2 changed files with 65 additions and 35 deletions
|
@ -384,12 +384,10 @@ export class SystemKeywords {
|
|||
public async getRandomId() {
|
||||
|
||||
const idGeneration = this.dk['idGeneration'];
|
||||
if (idGeneration && idGeneration.trim().toLowerCase() === 'number')
|
||||
{
|
||||
if (idGeneration && idGeneration.trim().toLowerCase() === 'number') {
|
||||
return GBAdminService.getNumberIdentifier();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return GBAdminService.getRndReadableIdentifier().substr(5);
|
||||
}
|
||||
|
||||
|
|
|
@ -271,6 +271,38 @@ export class GBConversationalService {
|
|||
// tslint:disable:no-unsafe-any due to Nexmo.
|
||||
public async sendSms(min: GBMinInstance, mobile: string, text: string): Promise<any> {
|
||||
GBLog.info(`Sending SMS to ${mobile} with text: '${text}'.`);
|
||||
|
||||
if (!min.instance.smsKey && min.instance.smsSecret) {
|
||||
let options = {
|
||||
method: 'POST',
|
||||
url: 'http://sms-api.megaconecta.com.br/mt',
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"authorization": `Bearer ${min.instance.smsSecret}`
|
||||
},
|
||||
body: [
|
||||
{
|
||||
"numero": `${mobile}`,
|
||||
"servico": "short",
|
||||
"mensagem": text,
|
||||
"parceiro_id": "",
|
||||
"codificacao": "0"
|
||||
}
|
||||
],
|
||||
json: true
|
||||
};
|
||||
|
||||
try {
|
||||
const results = await request(options);
|
||||
|
||||
return results[0].translations[0].text;
|
||||
} catch (error) {
|
||||
const msg = `Error calling SMS service. Error is: ${error}.`;
|
||||
|
||||
return Promise.reject(new Error(msg));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new Promise((resolve: any, reject: any): any => {
|
||||
const nexmo = new Nexmo({
|
||||
apiKey: min.instance.smsKey,
|
||||
|
@ -288,13 +320,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();
|
||||
|
||||
|
@ -416,8 +450,7 @@ export class GBConversationalService {
|
|||
let text = answer;
|
||||
|
||||
// Calls language translator.
|
||||
if (user)
|
||||
{
|
||||
if (user) {
|
||||
text = await min.conversationalService.translate(
|
||||
min,
|
||||
answer,
|
||||
|
@ -527,7 +560,7 @@ export class GBConversationalService {
|
|||
|
||||
let conversationId = null;
|
||||
|
||||
if(step ){
|
||||
if (step) {
|
||||
conversationId = step.context.activity.conversation.id;
|
||||
}
|
||||
|
||||
|
@ -895,7 +928,7 @@ export class GBConversationalService {
|
|||
if (step.activeDialog.state.options['kind'] === "file") {
|
||||
return await step.prompt('attachmentPrompt', {});
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return await step.prompt('textPrompt', text ? text : {});
|
||||
}
|
||||
|
||||
|
@ -927,7 +960,7 @@ export class GBConversationalService {
|
|||
});
|
||||
}
|
||||
|
||||
const locale = systemUser?systemUser.locale:null;
|
||||
const locale = systemUser ? systemUser.locale : null;
|
||||
text = await min.conversationalService.translate(
|
||||
min,
|
||||
text,
|
||||
|
@ -948,8 +981,7 @@ export class GBConversationalService {
|
|||
}
|
||||
|
||||
const analytics = new AnalyticsService();
|
||||
if (!user.conversation)
|
||||
{
|
||||
if (!user.conversation) {
|
||||
user.conversation = await analytics.createConversation(user);
|
||||
}
|
||||
analytics.createMessage(min.instance.instanceId, user.conversation, null, text);
|
||||
|
|
Loading…
Add table
Reference in a new issue