new(whatsapp.gblib): General Bots WhatsApp provider.
This commit is contained in:
parent
d898f962d1
commit
cbef720873
1 changed files with 15 additions and 13 deletions
|
@ -241,7 +241,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
|
url: urlJoin(this.whatsappServiceUrl, 'status') + `?token=${this.min.instance.whatsappServiceKey}`,
|
||||||
method: 'GET'};
|
method: 'GET'
|
||||||
|
};
|
||||||
|
|
||||||
const res = await request(options);
|
const res = await request(options);
|
||||||
const json = JSON.parse(res);
|
const json = JSON.parse(res);
|
||||||
|
@ -249,19 +250,20 @@ export class WhatsappDirectLine extends GBService {
|
||||||
return json.accountStatus === 'authenticated';
|
return json.accountStatus === 'authenticated';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static providerFromRequest(req) {
|
||||||
|
return req.body.messages ? 'chatapi' :
|
||||||
|
req.body.message ? 'maytapi' : 'GeneralBots';
|
||||||
|
}
|
||||||
|
|
||||||
public async received(req, res) {
|
public async received(req, res) {
|
||||||
|
|
||||||
if (this.provider === "chatapi" && req.body.messages === undefined) {
|
const provider = WhatsappDirectLine.providerFromRequest(req);
|
||||||
res.end();
|
|
||||||
|
|
||||||
return; // Exit here.
|
|
||||||
}
|
|
||||||
|
|
||||||
let message, from, fromName, text;
|
let message, from, fromName, text;
|
||||||
let group = "";
|
let group = "";
|
||||||
let answerText = null;
|
let answerText = null;
|
||||||
|
|
||||||
switch (this.provider) {
|
switch (provider) {
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
message = req;
|
message = req;
|
||||||
text = message.body;
|
text = message.body;
|
||||||
|
@ -301,7 +303,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
text = text.replace(/\@\d+ /gi, '');
|
text = text.replace(/\@\d+ /gi, '');
|
||||||
GBLog.info(`GBWhatsapp: RCV ${from}(${fromName}): ${text})`);
|
GBLog.info(`GBWhatsapp: RCV ${from}(${fromName}): ${text})`);
|
||||||
|
|
||||||
if (this.provider === "chatapi") {
|
if (provider === "chatapi") {
|
||||||
if (message.chatName.charAt(0) !== '+') {
|
if (message.chatName.charAt(0) !== '+') {
|
||||||
group = message.chatName;
|
group = message.chatName;
|
||||||
|
|
||||||
|
@ -392,7 +394,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
|
|
||||||
if (process.env.AUDIO_DISABLED !== 'true') {
|
if (process.env.AUDIO_DISABLED !== 'true') {
|
||||||
const options = {
|
const options = {
|
||||||
url: this.provider ? message.body : message.text,
|
url: provider ? message.body : message.text,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
encoding: 'binary'
|
encoding: 'binary'
|
||||||
};
|
};
|
||||||
|
@ -489,7 +491,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
const generatedConversationId = response.obj.conversationId;
|
const generatedConversationId = response.obj.conversationId;
|
||||||
|
|
||||||
WhatsappDirectLine.conversationIds[botId + from + group] = generatedConversationId;
|
WhatsappDirectLine.conversationIds[botId + from + group] = generatedConversationId;
|
||||||
if (this.provider === "GeneralBots") {
|
if (provider === "GeneralBots") {
|
||||||
WhatsappDirectLine.chatIds[generatedConversationId] = message.from;
|
WhatsappDirectLine.chatIds[generatedConversationId] = message.from;
|
||||||
}
|
}
|
||||||
WhatsappDirectLine.mobiles[generatedConversationId] = from;
|
WhatsappDirectLine.mobiles[generatedConversationId] = from;
|
||||||
|
|
Loading…
Add table
Reference in a new issue