fix(whatsapp.gblib): await fix.
This commit is contained in:
parent
0645c310c3
commit
5015fb15fb
3 changed files with 39 additions and 28 deletions
4
packages/default.gbdialog/simple-order.vbs
Normal file
4
packages/default.gbdialog/simple-order.vbs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
talk "Qual seu pedido?"
|
||||||
|
hear pedido
|
||||||
|
talk "Obrigado, seu pedido será processado e retornamos."
|
||||||
|
ask payment
|
|
@ -57,6 +57,9 @@ export class GBWhatsappPackage implements IGBPackage {
|
||||||
min.instance.whatsappServiceNumber,
|
min.instance.whatsappServiceNumber,
|
||||||
min.instance.whatsappServiceUrl
|
min.instance.whatsappServiceUrl
|
||||||
);
|
);
|
||||||
|
(async () => {
|
||||||
|
await min.whatsAppDirectLine.setup();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ const Swagger = require('swagger-client');
|
||||||
const rp = require('request-promise');
|
const rp = require('request-promise');
|
||||||
import { GBLog, GBService } from 'botlib';
|
import { GBLog, GBService } from 'botlib';
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
|
const fs = require('fs');
|
||||||
import { GBServer } from '../../../src/app';
|
import { GBServer } from '../../../src/app';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +51,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
public whatsappServiceNumber: string;
|
public whatsappServiceNumber: string;
|
||||||
public whatsappServiceUrl: string;
|
public whatsappServiceUrl: string;
|
||||||
public botId: string;
|
public botId: string;
|
||||||
|
private directLineSecret: string;
|
||||||
|
|
||||||
public conversationIds = {};
|
public conversationIds = {};
|
||||||
|
|
||||||
|
@ -63,23 +65,24 @@ export class WhatsappDirectLine extends GBService {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.botId = botId;
|
this.botId = botId;
|
||||||
|
this.directLineSecret = directLineSecret;
|
||||||
this.whatsappServiceKey = whatsappServiceKey;
|
this.whatsappServiceKey = whatsappServiceKey;
|
||||||
this.whatsappServiceNumber = whatsappServiceNumber;
|
this.whatsappServiceNumber = whatsappServiceNumber;
|
||||||
this.whatsappServiceUrl = whatsappServiceUrl;
|
this.whatsappServiceUrl = whatsappServiceUrl;
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
let directLineClient =
|
}
|
||||||
|
|
||||||
|
public async setup() {
|
||||||
|
this.directLineClient =
|
||||||
new Swagger({
|
new Swagger({
|
||||||
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')),
|
spec: JSON.parse(fs.readFileSync('directline-3.0.json', 'utf8')),
|
||||||
usePromise: true
|
usePromise: true
|
||||||
});
|
});
|
||||||
this.directLineClient = directLineClient;
|
let client = await this.directLineClient;
|
||||||
directLineClient
|
|
||||||
.then(async client => {
|
|
||||||
|
|
||||||
client.clientAuthorizations.add(
|
client.clientAuthorizations.add(
|
||||||
'AuthorizationBotConnector',
|
'AuthorizationBotConnector',
|
||||||
new Swagger.ApiKeyAuthorization('Authorization', `Bearer ${directLineSecret}`, 'header')
|
new Swagger.ApiKeyAuthorization('Authorization', `Bearer ${this.directLineSecret}`, 'header')
|
||||||
);
|
);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -100,7 +103,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`);
|
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async asyncForEach(array, callback) {
|
public static async asyncForEach(array, callback) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue