Parameter whatsappServiceWebhookUrl added.
This commit is contained in:
parent
1bc4b37827
commit
3b6edd4f3a
4 changed files with 183 additions and 179 deletions
|
@ -33,27 +33,27 @@
|
|||
"use strict";
|
||||
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
DataTypeUUIDv4,
|
||||
DataTypeDate,
|
||||
DataTypeDecimal
|
||||
} from "sequelize";
|
||||
import {
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
HasMany,
|
||||
BelongsTo,
|
||||
BelongsToMany,
|
||||
Length,
|
||||
ForeignKey,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DataType,
|
||||
IsUUID,
|
||||
PrimaryKey,
|
||||
AutoIncrement
|
||||
Table,
|
||||
Column,
|
||||
Model,
|
||||
HasMany,
|
||||
BelongsTo,
|
||||
BelongsToMany,
|
||||
Length,
|
||||
ForeignKey,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DataType,
|
||||
IsUUID,
|
||||
PrimaryKey,
|
||||
AutoIncrement
|
||||
} from "sequelize-typescript";
|
||||
import { IGBInstance } from "botlib";
|
||||
|
||||
|
@ -61,132 +61,134 @@ import { IGBInstance } from "botlib";
|
|||
@Table
|
||||
export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInstance {
|
||||
|
||||
@Column
|
||||
whoAmIVideo: string;
|
||||
@Column
|
||||
whoAmIVideo: string;
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
instanceId: number;
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@Column botId: string;
|
||||
@Column botId: string;
|
||||
|
||||
@Column title: string;
|
||||
@Column title: string;
|
||||
|
||||
@Column description: string;
|
||||
@Column description: string;
|
||||
|
||||
@Column version: string;
|
||||
@Column version: string;
|
||||
|
||||
@Column enabledAdmin: boolean;
|
||||
@Column enabledAdmin: boolean;
|
||||
|
||||
/* Services section on bot.json */
|
||||
/* Services section on bot.json */
|
||||
|
||||
@Column engineName: string;
|
||||
@Column engineName: string;
|
||||
|
||||
@Column marketplaceId: string;
|
||||
@Column marketplaceId: string;
|
||||
|
||||
@Column textAnalyticsKey: string;
|
||||
@Column textAnalyticsKey: string;
|
||||
|
||||
@Column marketplacePassword: string;
|
||||
@Column marketplacePassword: string;
|
||||
|
||||
@Column webchatKey: string;
|
||||
@Column webchatKey: string;
|
||||
|
||||
@Column whatsappBotKey: string;
|
||||
|
||||
@Column whatsappServiceKey: string;
|
||||
@Column whatsappBotKey: string;
|
||||
|
||||
@Column whatsappServiceNumber: string;
|
||||
@Column whatsappServiceKey: string;
|
||||
|
||||
@Column whatsappServiceUrl: string;
|
||||
@Column whatsappServiceNumber: string;
|
||||
|
||||
@Column spellcheckerKey: string;
|
||||
@Column whatsappServiceUrl: string;
|
||||
|
||||
@Column theme: string;
|
||||
@Column whatsappServiceWebhookUrl: string;
|
||||
|
||||
@Column ui: string;
|
||||
@Column spellcheckerKey: string;
|
||||
|
||||
@Column kb: string;
|
||||
@Column theme: string;
|
||||
|
||||
@Column
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
nlpServerUrl: string;
|
||||
@Column ui: string;
|
||||
|
||||
@Column searchHost: string;
|
||||
@Column kb: string;
|
||||
|
||||
@Column searchKey: string;
|
||||
@Column
|
||||
@Column({ type: DataType.STRING(512) })
|
||||
nlpServerUrl: string;
|
||||
|
||||
@Column searchIndex: string;
|
||||
@Column searchHost: string;
|
||||
|
||||
@Column searchIndexer: string;
|
||||
@Column searchKey: string;
|
||||
|
||||
/* Settings section of bot.json */
|
||||
@Column searchIndex: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpVsSearch: number;
|
||||
@Column searchIndexer: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
searchScore: number;
|
||||
/* Settings section of bot.json */
|
||||
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpScore: number;
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpVsSearch: number;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
searchScore: number;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
@Column({
|
||||
type: DataType.FLOAT
|
||||
})
|
||||
nlpScore: number;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
|
||||
@Column
|
||||
@UpdatedAt
|
||||
updatedOn: Date;
|
||||
}
|
||||
|
||||
@Table
|
||||
export class GuaribasPackage extends Model<GuaribasPackage> {
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
packageId: number;
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
packageId: number;
|
||||
|
||||
@Column
|
||||
packageName: string;
|
||||
@Column
|
||||
packageName: string;
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
}
|
||||
|
||||
@Table
|
||||
export class GuaribasChannel extends Model<GuaribasChannel> {
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
channelId: number;
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
channelId: number;
|
||||
|
||||
@Column title: string;
|
||||
@Column title: string;
|
||||
}
|
||||
|
||||
@Table
|
||||
export class GuaribasException extends Model<GuaribasException> {
|
||||
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
exceptionId: number;
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Column
|
||||
exceptionId: number;
|
||||
|
||||
@Column message: string;
|
||||
@Column message: string;
|
||||
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
@ForeignKey(() => GuaribasInstance)
|
||||
@Column
|
||||
instanceId: number;
|
||||
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
@Column
|
||||
@CreatedAt
|
||||
creationDate: Date;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,80 +41,82 @@ import { GBCoreService } from "./GBCoreService";
|
|||
|
||||
import { Session, Message, LuisRecognizer } from "botbuilder";
|
||||
|
||||
import { GBService, GBServiceCallback, IGBConversationalService} from "botlib";
|
||||
import { GBService, GBServiceCallback, IGBConversationalService } from "botlib";
|
||||
import { GBError } from "botlib";
|
||||
import { GBERROR_TYPE } from "botlib";
|
||||
import { GBMinInstance } from "botlib";
|
||||
|
||||
|
||||
export class GBConversationalService implements IGBConversationalService{
|
||||
|
||||
coreService: GBCoreService;
|
||||
export class GBConversationalService implements IGBConversationalService {
|
||||
|
||||
constructor(coreService: GBCoreService) {
|
||||
this.coreService = coreService;
|
||||
}
|
||||
coreService: GBCoreService;
|
||||
|
||||
sendEvent(session: Session, name: string, value: any) {
|
||||
var msg = new gBuilder.Message();
|
||||
msg.data.type = "event";
|
||||
msg.data.name = name;
|
||||
msg.data.value = value;
|
||||
session.send(msg);
|
||||
}
|
||||
constructor(coreService: GBCoreService) {
|
||||
this.coreService = coreService;
|
||||
}
|
||||
|
||||
runNLP(
|
||||
session: Session,
|
||||
min: GBMinInstance,
|
||||
text: string,
|
||||
cb: GBServiceCallback<any>
|
||||
) {
|
||||
LuisRecognizer.recognize(
|
||||
text,
|
||||
min.instance.nlpServerUrl,
|
||||
(err, intents, entities) => {
|
||||
if (err) {
|
||||
cb(null, new GBError(err, GBERROR_TYPE.nlpGeneralError));
|
||||
return;
|
||||
}
|
||||
sendEvent(session: Session, name: string, value: any) {
|
||||
var msg = new gBuilder.Message();
|
||||
msg.data.type = "event";
|
||||
msg.data.name = name;
|
||||
msg.data.value = value;
|
||||
session.send(msg);
|
||||
}
|
||||
|
||||
if (intents && intents.length > 0) {
|
||||
var intent = intents[0].intent;
|
||||
var entity =
|
||||
entities && entities.length > 0
|
||||
? entities[0].entity.toUpperCase()
|
||||
: null;
|
||||
logger.trace(
|
||||
"luis: intent: [" + intent + "] entity: [" + entity + "]"
|
||||
);
|
||||
runNLP(
|
||||
session: Session,
|
||||
min: GBMinInstance,
|
||||
text: string,
|
||||
cb: GBServiceCallback<any>
|
||||
) {
|
||||
LuisRecognizer.recognize(
|
||||
text,
|
||||
min.instance.nlpServerUrl,
|
||||
(err, intents, entities) => {
|
||||
if (err) {
|
||||
cb(null, new GBError(err, GBERROR_TYPE.nlpGeneralError));
|
||||
return;
|
||||
}
|
||||
|
||||
// PACKAGE: Send to packages.
|
||||
if (intents && intents.length > 0) {
|
||||
var intent = intents[0].intent;
|
||||
var entity =
|
||||
entities && entities.length > 0
|
||||
? entities[0].entity.toUpperCase()
|
||||
: null;
|
||||
logger.trace(
|
||||
"luis: intent: [" + intent + "] entity: [" + entity + "]"
|
||||
);
|
||||
|
||||
if (intent === "Student.CheckAttendance") {
|
||||
session.replaceDialog("/belagua-check-attendance", {entities: entities});
|
||||
}
|
||||
else if(intent === 'User.Authenticate'){
|
||||
session.replaceDialog("/belagua-user-login", {entities: entities});
|
||||
}
|
||||
else if (intent === "PerguntarSobreTermo") {
|
||||
session.send(
|
||||
"Vou mostrar um menu para ajudar você a formular sua pergunta..."
|
||||
);
|
||||
session.replaceDialog("/menu");
|
||||
} else if (intent === "ShowSubjectMenu") {
|
||||
session.replaceDialog("/menu");
|
||||
} else {
|
||||
session.sendTyping();
|
||||
session.send("Desculpe-me, não encontrei nada a respeito...");
|
||||
}
|
||||
// PACKAGE: Send to packages.
|
||||
|
||||
cb({ intent, entities }, null);
|
||||
} else {
|
||||
session.sendTyping();
|
||||
session.send("Lamento, não achei nada a respeito...");
|
||||
cb(null, null);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if (intent === "Student.CheckAttendance") {
|
||||
session.replaceDialog("/belagua-check-attendance", { entities: entities });
|
||||
}
|
||||
else if (intent === 'User.Authenticate') {
|
||||
session.replaceDialog("/belagua-user-login", { entities: entities });
|
||||
}
|
||||
else if (intent === "PerguntarSobreTermo") {
|
||||
session.send(
|
||||
"Vou mostrar um menu para ajudar você a formular sua pergunta..."
|
||||
);
|
||||
session.replaceDialog("/menu");
|
||||
} else if (intent === "ShowSubjectMenu") {
|
||||
session.replaceDialog("/menu");
|
||||
} else {
|
||||
// TODO testar diálogos v2
|
||||
// inclui diálogo
|
||||
session.sendTyping();
|
||||
session.send("Desculpe-me, não encontrei nada a respeito...");
|
||||
}
|
||||
|
||||
cb({ intent, entities }, null);
|
||||
} else {
|
||||
session.sendTyping();
|
||||
session.send("Lamento, não achei nada a respeito...");
|
||||
cb(null, null);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,26 +42,26 @@ import { WhatsappDirectLine } from "./services/WhatsappDirectLine";
|
|||
|
||||
|
||||
export class GBWhatsappPackage implements IGBPackage {
|
||||
|
||||
sysPackages: IGBPackage[] = null;
|
||||
channel: WhatsappDirectLine;
|
||||
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
}
|
||||
sysPackages: IGBPackage[] = null;
|
||||
channel: WhatsappDirectLine;
|
||||
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
loadPackage(core: IGBCoreService, sequelize: Sequelize): void {
|
||||
}
|
||||
|
||||
}
|
||||
unloadPackage(core: IGBCoreService): void {
|
||||
|
||||
loadBot(min: GBMinInstance): void {
|
||||
this.channel = new WhatsappDirectLine(min.botId, min.instance.whatsappBotKey, min.instance.whatsappServiceKey,
|
||||
min.instance.whatsappServiceNumber, min.instance.whatsappServiceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
loadBot(min: GBMinInstance): void {
|
||||
this.channel = new WhatsappDirectLine(min.botId, min.instance.whatsappBotKey, min.instance.whatsappServiceKey,
|
||||
min.instance.whatsappServiceNumber, min.instance.whatsappServiceUrl, min.instance.whatsappServiceWebhookUrl);
|
||||
}
|
||||
|
||||
}
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
unloadBot(min: GBMinInstance): void {
|
||||
|
||||
}
|
||||
}
|
||||
onNewSession(min: GBMinInstance, session: Session): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,13 @@ export class WhatsappDirectLine extends GBService {
|
|||
whatsappServiceKey: string;
|
||||
whatsappServiceNumber: string;
|
||||
whatsappServiceUrl: string;
|
||||
whatsappServiceWebhookUrl: string;
|
||||
botId: string;
|
||||
watermark: string = null;
|
||||
|
||||
conversationIds = {};
|
||||
|
||||
constructor(botId, directLineSecret, whatsappServiceKey, whatsappServiceNumber, whatsappServiceUrl) {
|
||||
constructor(botId, directLineSecret, whatsappServiceKey, whatsappServiceNumber, whatsappServiceUrl, whatsappServiceWebhookUrl) {
|
||||
|
||||
super();
|
||||
|
||||
|
@ -67,6 +68,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
this.whatsappServiceKey = whatsappServiceKey;
|
||||
this.whatsappServiceNumber = whatsappServiceNumber;
|
||||
this.whatsappServiceUrl = whatsappServiceUrl;
|
||||
this.whatsappServiceWebhookUrl = whatsappServiceWebhookUrl;
|
||||
|
||||
// TODO: Migrate to Swagger 3.
|
||||
this.directLineClient = rp(this.directLineSpecUrl)
|
||||
|
@ -81,15 +83,13 @@ export class WhatsappDirectLine extends GBService {
|
|||
new Swagger.ApiKeyAuthorization('Authorization', 'Bearer ' +
|
||||
directLineSecret, 'header'));
|
||||
|
||||
|
||||
|
||||
var options = {
|
||||
method: 'POST',
|
||||
url: UrlJoin(this.whatsappServiceUrl, "webhook"),
|
||||
qs:
|
||||
{
|
||||
token: this.whatsappServiceKey,
|
||||
webhookUrl: `https://a2fc0900.ngrok.io/instances/${this.botId}/whatsapp`
|
||||
webhookUrl: `${this.whatsappServiceWebhookUrl}/instances/${this.botId}/whatsapp`
|
||||
},
|
||||
headers:
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue