new(WhatsApp.gblib): Official Twilio driver.
This commit is contained in:
parent
6217d3f8cd
commit
cae8408b59
4 changed files with 40 additions and 3 deletions
|
@ -199,6 +199,7 @@
|
||||||
"tabulator-tables": "5.4.2",
|
"tabulator-tables": "5.4.2",
|
||||||
"tedious": "15.1.2",
|
"tedious": "15.1.2",
|
||||||
"textract": "2.5.0",
|
"textract": "2.5.0",
|
||||||
|
"twilio": "^4.23.0",
|
||||||
"twitter-api-v2": "1.12.9",
|
"twitter-api-v2": "1.12.9",
|
||||||
"typescript": "4.9.5",
|
"typescript": "4.9.5",
|
||||||
"url-join": "5.0.0",
|
"url-join": "5.0.0",
|
||||||
|
|
|
@ -446,6 +446,10 @@ export class GBMinService {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return 'GeneralBots';
|
return 'GeneralBots';
|
||||||
}
|
}
|
||||||
|
if (req.NumMedia)
|
||||||
|
{
|
||||||
|
return 'Official';
|
||||||
|
}
|
||||||
return req.body.phone_id ? 'maytapi' : 'chatapi';
|
return req.body.phone_id ? 'maytapi' : 'chatapi';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ export class ChatServices {
|
||||||
const chain = new LLMChain({
|
const chain = new LLMChain({
|
||||||
memory: windowMemory,
|
memory: windowMemory,
|
||||||
prompt: chatPrompt,
|
prompt: chatPrompt,
|
||||||
llm: llmWithTools as any,
|
llm: llm as any,
|
||||||
});
|
});
|
||||||
|
|
||||||
const contextVectorStore = min['vectorStore'];
|
const contextVectorStore = min['vectorStore'];
|
||||||
|
|
|
@ -52,6 +52,8 @@ import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
import e from 'express';
|
import e from 'express';
|
||||||
import { GBUtil } from '../../../src/util.js';
|
import { GBUtil } from '../../../src/util.js';
|
||||||
const { WAState, List, Buttons, Client, MessageMedia } = pkg;
|
const { WAState, List, Buttons, Client, MessageMedia } = pkg;
|
||||||
|
import twilio from 'twilio';
|
||||||
|
const { MessagingResponse } = twilio.twiml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for Whatsapp.
|
* Support for Whatsapp.
|
||||||
|
@ -104,8 +106,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
this.provider =
|
this.provider =
|
||||||
whatsappServiceKey === 'internal'
|
whatsappServiceKey === 'internal'
|
||||||
? 'GeneralBots'
|
? 'GeneralBots'
|
||||||
: whatsappServiceNumber.indexOf(';') > -1
|
: whatsappServiceKey.indexOf('official') > -1
|
||||||
? 'maytapi'
|
? 'official'
|
||||||
: whatsappServiceKey !== 'internal'
|
: whatsappServiceKey !== 'internal'
|
||||||
? 'graphapi'
|
? 'graphapi'
|
||||||
: 'chatapi';
|
: 'chatapi';
|
||||||
|
@ -132,6 +134,12 @@ export class WhatsappDirectLine extends GBService {
|
||||||
let options: any;
|
let options: any;
|
||||||
|
|
||||||
switch (this.provider) {
|
switch (this.provider) {
|
||||||
|
case 'Official':
|
||||||
|
const accountSid = process.env.TWILIO_ACCOUNT_SID;
|
||||||
|
const authToken = process.env.TWILIO_AUTH_TOKEN;
|
||||||
|
this.customClient = twilio(accountSid, authToken);
|
||||||
|
|
||||||
|
break;
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
const minBoot = GBServer.globals.minBoot;
|
const minBoot = GBServer.globals.minBoot;
|
||||||
// Initialize the browser using a local profile for each bot.
|
// Initialize the browser using a local profile for each bot.
|
||||||
|
@ -872,6 +880,21 @@ export class WhatsappDirectLine extends GBService {
|
||||||
let options;
|
let options;
|
||||||
|
|
||||||
switch (this.provider) {
|
switch (this.provider) {
|
||||||
|
|
||||||
|
case 'Official':
|
||||||
|
const botNumber = this.min.core.getParam(this.min.instance, 'Bot Number', null);
|
||||||
|
if (to.charAt(0) !== '+') {
|
||||||
|
to = `+${to}`
|
||||||
|
}
|
||||||
|
await this.customClient.messages
|
||||||
|
.create({
|
||||||
|
body: msg,
|
||||||
|
from: `whatsapp:${botNumber}`,
|
||||||
|
to: `whatsapp:${to}`
|
||||||
|
// TODO: mediaUrl.
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
to = to.replace('+', '');
|
to = to.replace('+', '');
|
||||||
if (to.indexOf('@') == -1) {
|
if (to.indexOf('@') == -1) {
|
||||||
|
@ -953,6 +976,15 @@ export class WhatsappDirectLine extends GBService {
|
||||||
let text;
|
let text;
|
||||||
|
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
|
|
||||||
|
case 'Official':
|
||||||
|
|
||||||
|
const { body } = req;
|
||||||
|
|
||||||
|
let message;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
// Ignore E2E messages and status updates.
|
// Ignore E2E messages and status updates.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue