Parameter whatsappServiceWebhookUrl added.

This commit is contained in:
Jorge Ramos 2018-05-14 01:48:39 -03:00
parent 1bc4b37827
commit 3b6edd4f3a
4 changed files with 183 additions and 179 deletions

View file

@ -99,6 +99,8 @@ export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInst
@Column whatsappServiceUrl: string; @Column whatsappServiceUrl: string;
@Column whatsappServiceWebhookUrl: string;
@Column spellcheckerKey: string; @Column spellcheckerKey: string;
@Column theme: string; @Column theme: string;

View file

@ -104,6 +104,8 @@ export class GBConversationalService implements IGBConversationalService{
} else if (intent === "ShowSubjectMenu") { } else if (intent === "ShowSubjectMenu") {
session.replaceDialog("/menu"); session.replaceDialog("/menu");
} else { } else {
// TODO testar diálogos v2
// inclui diálogo
session.sendTyping(); session.sendTyping();
session.send("Desculpe-me, não encontrei nada a respeito..."); session.send("Desculpe-me, não encontrei nada a respeito...");
} }

View file

@ -55,7 +55,7 @@ export class GBWhatsappPackage implements IGBPackage {
loadBot(min: GBMinInstance): void { loadBot(min: GBMinInstance): void {
this.channel = new WhatsappDirectLine(min.botId, min.instance.whatsappBotKey, min.instance.whatsappServiceKey, this.channel = new WhatsappDirectLine(min.botId, min.instance.whatsappBotKey, min.instance.whatsappServiceKey,
min.instance.whatsappServiceNumber, min.instance.whatsappServiceUrl); min.instance.whatsappServiceNumber, min.instance.whatsappServiceUrl, min.instance.whatsappServiceWebhookUrl);
} }
unloadBot(min: GBMinInstance): void { unloadBot(min: GBMinInstance): void {

View file

@ -54,12 +54,13 @@ export class WhatsappDirectLine extends GBService {
whatsappServiceKey: string; whatsappServiceKey: string;
whatsappServiceNumber: string; whatsappServiceNumber: string;
whatsappServiceUrl: string; whatsappServiceUrl: string;
whatsappServiceWebhookUrl: string;
botId: string; botId: string;
watermark: string = null; watermark: string = null;
conversationIds = {}; conversationIds = {};
constructor(botId, directLineSecret, whatsappServiceKey, whatsappServiceNumber, whatsappServiceUrl) { constructor(botId, directLineSecret, whatsappServiceKey, whatsappServiceNumber, whatsappServiceUrl, whatsappServiceWebhookUrl) {
super(); super();
@ -67,6 +68,7 @@ export class WhatsappDirectLine extends GBService {
this.whatsappServiceKey = whatsappServiceKey; this.whatsappServiceKey = whatsappServiceKey;
this.whatsappServiceNumber = whatsappServiceNumber; this.whatsappServiceNumber = whatsappServiceNumber;
this.whatsappServiceUrl = whatsappServiceUrl; this.whatsappServiceUrl = whatsappServiceUrl;
this.whatsappServiceWebhookUrl = whatsappServiceWebhookUrl;
// TODO: Migrate to Swagger 3. // TODO: Migrate to Swagger 3.
this.directLineClient = rp(this.directLineSpecUrl) this.directLineClient = rp(this.directLineSpecUrl)
@ -81,15 +83,13 @@ export class WhatsappDirectLine extends GBService {
new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' + new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' +
directLineSecret, 'header')); directLineSecret, 'header'));
var options = { var options = {
method: 'POST', method: 'POST',
url: UrlJoin(this.whatsappServiceUrl, "webhook"), url: UrlJoin(this.whatsappServiceUrl, "webhook"),
qs: qs:
{ {
token: this.whatsappServiceKey, token: this.whatsappServiceKey,
webhookUrl: `https://a2fc0900.ngrok.io/instances/${this.botId}/whatsapp` webhookUrl: `${this.whatsappServiceWebhookUrl}/instances/${this.botId}/whatsapp`
}, },
headers: headers:
{ {