mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da06ed1185 | ||
|
|
67afbd6a77 | ||
|
|
8fce53b4af | ||
|
|
65bba23519 | ||
|
|
283b497788 | ||
|
|
8cc1b8daa8 | ||
|
|
9ccdb45a7a | ||
|
|
f78d360c38 | ||
|
|
6144fbe856 | ||
|
|
8446be7646 | ||
|
|
8875ab1e93 | ||
|
|
7c207a50e1 | ||
|
|
dcc32479ff | ||
|
|
09911c472d | ||
|
|
7a0149ee23 | ||
|
|
3ae8cf32b0 | ||
|
|
11cf947bbb | ||
|
|
60a20f61af | ||
|
|
e65c7b6bcf | ||
|
|
80c892aca3 | ||
|
|
39ee266598 | ||
|
|
aa58d7744e | ||
|
|
ea3b0b3712 | ||
|
|
d9d8707123 | ||
|
|
8e9a1e2ba5 | ||
|
|
e29b4865e8 | ||
|
|
4b60ca175d | ||
|
|
2fbbc7b5a9 | ||
|
|
633dbb82d3 | ||
|
|
95907b3cea | ||
|
|
14c210c771 | ||
|
|
00e7fcc46b | ||
|
|
720efcbcbf | ||
|
|
d95791cc18 | ||
|
|
d45b7af3b6 | ||
|
|
0ad3acaf07 | ||
|
|
e27818ecda | ||
|
|
ff21cf4d4c | ||
|
|
dc19c7fdec | ||
|
|
6c8ffd8ec6 | ||
|
|
96fdb210be | ||
|
|
84ad8e0d6e | ||
|
|
53361682f4 | ||
|
|
0ee243f284 | ||
|
|
26ff0b634f | ||
|
|
f44ab0f678 | ||
|
|
1f128747bb | ||
|
|
3bf975d90f | ||
|
|
92f8951be4 | ||
|
|
e071f56767 | ||
|
|
c85619efcf | ||
|
|
27f9ae1e56 | ||
|
|
7449102d95 | ||
|
|
234a2c71b5 | ||
|
|
4dd5533202 | ||
|
|
a4d1740754 | ||
|
|
1a2ea1c38a | ||
|
|
bb974e10f5 |
83
.github/workflows/publish_docker_image.yml
vendored
83
.github/workflows/publish_docker_image.yml
vendored
@@ -2,63 +2,52 @@ name: Build Docker image
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags: ['v*']
|
branches:
|
||||||
|
- develop
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-amd:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GIT_REF: ${{ github.head_ref || github.ref_name }} # ref_name to get tags/branches
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Extract existing image metadata
|
- name: Set up QEMU
|
||||||
id: image-meta
|
uses: docker/setup-qemu-action@v3
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: atendai/evolution-api
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: set docker tag
|
||||||
uses: docker/login-action@v2
|
run: |
|
||||||
|
echo "DOCKER_TAG=ghcr.io/atendai/evolution-api:$GIT_REF" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: replace docker tag if main
|
||||||
|
if: github.ref_name == 'main'
|
||||||
|
run: |
|
||||||
|
echo "DOCKER_TAG=ghcr.io/atendai/evolution-api:latest" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
registry: ghcr.io
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push AMD image
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
labels: ${{ steps.image-meta.outputs.labels }}
|
file: ./Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
|
||||||
|
|
||||||
build-arm:
|
|
||||||
runs-on: buildjet-4vcpu-ubuntu-2204-arm
|
|
||||||
steps:
|
|
||||||
- name: Check out the repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Extract existing image metadata
|
|
||||||
id: image-meta
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: atendai/evolution-api
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Build and push ARM image
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
labels: ${{ steps.image-meta.outputs.labels }}
|
|
||||||
platforms: linux/arm64
|
|
||||||
push: true
|
push: true
|
||||||
|
tags: ${{ env.DOCKER_TAG }}
|
||||||
|
|||||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,3 +1,24 @@
|
|||||||
|
# 1.7.5 (2024-05-21 08:50)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Add merge_brazil_contacts function to solve nine digit in brazilian numbers
|
||||||
|
* Optimize ChatwootService method for updating contact
|
||||||
|
* Fix swagger auth
|
||||||
|
* Update aws sdk v3
|
||||||
|
* Fix getOpenConversationByContact and init queries error
|
||||||
|
* Method to mark chat as unread
|
||||||
|
* Added environment variable to manually select the WhatsApp web version for the baileys lib (optional)
|
||||||
|
|
||||||
|
# 1.7.4 (2024-04-28 09:46)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Adjusts in proxy on fetchAgent
|
||||||
|
* Recovering messages lost with redis cache
|
||||||
|
* Log when init redis cache service
|
||||||
|
* Recovering messages lost with redis cache
|
||||||
|
* Chatwoot inbox name
|
||||||
|
* Update Baileys version
|
||||||
|
|
||||||
# 1.7.3 (2024-04-18 12:07)
|
# 1.7.3 (2024-04-18 12:07)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
FROM node:20.7.0-alpine AS builder
|
FROM node:20.7.0-alpine AS builder
|
||||||
|
|
||||||
LABEL version="1.7.3" description="Api to control whatsapp features through http requests."
|
LABEL version="1.7.5" description="Api to control whatsapp features through http requests."
|
||||||
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||||
LABEL contact="contato@agenciadgcode.com"
|
LABEL contact="contato@agenciadgcode.com"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.7.3",
|
"version": "1.7.5",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -46,10 +46,10 @@
|
|||||||
"@figuro/chatwoot-sdk": "^1.1.16",
|
"@figuro/chatwoot-sdk": "^1.1.16",
|
||||||
"@hapi/boom": "^10.0.1",
|
"@hapi/boom": "^10.0.1",
|
||||||
"@sentry/node": "^7.59.2",
|
"@sentry/node": "^7.59.2",
|
||||||
"@whiskeysockets/baileys": "github:AtendAI/Baileys",
|
|
||||||
"amqplib": "^0.10.3",
|
"amqplib": "^0.10.3",
|
||||||
"aws-sdk": "^2.1499.0",
|
"@aws-sdk/client-sqs": "^3.569.0",
|
||||||
"axios": "^1.6.5",
|
"axios": "^1.6.5",
|
||||||
|
"@whiskeysockets/baileys": "^6.7.2",
|
||||||
"class-validator": "^0.14.1",
|
"class-validator": "^0.14.1",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
BlockUserDto,
|
BlockUserDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
|
MarkChatUnreadDto,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
PrivacySettingDto,
|
PrivacySettingDto,
|
||||||
ProfileNameDto,
|
ProfileNameDto,
|
||||||
@@ -40,6 +41,11 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].archiveChat(data);
|
return await this.waMonitor.waInstances[instanceName].archiveChat(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async markChatUnread({ instanceName }: InstanceDto, data: MarkChatUnreadDto) {
|
||||||
|
logger.verbose('requested markChatUnread from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].markChatUnread(data);
|
||||||
|
}
|
||||||
|
|
||||||
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
|
public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) {
|
||||||
logger.verbose('requested deleteMessage from ' + instanceName + ' instance');
|
logger.verbose('requested deleteMessage from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].deleteMessage(data);
|
return await this.waMonitor.waInstances[instanceName].deleteMessage(data);
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ import { WebsocketService } from '../integrations/websocket/services/websocket.s
|
|||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { AuthService, OldToken } from '../services/auth.service';
|
import { AuthService, OldToken } from '../services/auth.service';
|
||||||
import { CacheService } from '../services/cache.service';
|
import { CacheService } from '../services/cache.service';
|
||||||
|
import { BaileysStartupService } from '../services/channels/whatsapp.baileys.service';
|
||||||
|
import { BusinessStartupService } from '../services/channels/whatsapp.business.service';
|
||||||
import { IntegrationService } from '../services/integration.service';
|
import { IntegrationService } from '../services/integration.service';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
import { SettingsService } from '../services/settings.service';
|
import { SettingsService } from '../services/settings.service';
|
||||||
import { WebhookService } from '../services/webhook.service';
|
import { WebhookService } from '../services/webhook.service';
|
||||||
import { BaileysStartupService } from '../services/whatsapp/whatsapp.baileys.service';
|
|
||||||
import { BusinessStartupService } from '../services/whatsapp/whatsapp.business.service';
|
|
||||||
import { Events, Integration, wa } from '../types/wa.types';
|
import { Events, Integration, wa } from '../types/wa.types';
|
||||||
import { ProxyController } from './proxy.controller';
|
import { ProxyController } from './proxy.controller';
|
||||||
|
|
||||||
@@ -65,6 +65,8 @@ export class InstanceController {
|
|||||||
chatwoot_reopen_conversation,
|
chatwoot_reopen_conversation,
|
||||||
chatwoot_conversation_pending,
|
chatwoot_conversation_pending,
|
||||||
chatwoot_import_contacts,
|
chatwoot_import_contacts,
|
||||||
|
chatwoot_name_inbox,
|
||||||
|
chatwoot_merge_brazil_contacts,
|
||||||
chatwoot_import_messages,
|
chatwoot_import_messages,
|
||||||
chatwoot_days_limit_import_messages,
|
chatwoot_days_limit_import_messages,
|
||||||
reject_call,
|
reject_call,
|
||||||
@@ -513,11 +515,12 @@ export class InstanceController {
|
|||||||
token: chatwoot_token,
|
token: chatwoot_token,
|
||||||
url: chatwoot_url,
|
url: chatwoot_url,
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
name_inbox: instance.instanceName.split('-cwId-')[0],
|
name_inbox: chatwoot_name_inbox ?? instance.instanceName.split('-cwId-')[0],
|
||||||
number,
|
number,
|
||||||
reopen_conversation: chatwoot_reopen_conversation || false,
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
conversation_pending: chatwoot_conversation_pending || false,
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
import_contacts: chatwoot_import_contacts ?? true,
|
import_contacts: chatwoot_import_contacts ?? true,
|
||||||
|
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
|
||||||
import_messages: chatwoot_import_messages ?? true,
|
import_messages: chatwoot_import_messages ?? true,
|
||||||
days_limit_import_messages: chatwoot_days_limit_import_messages ?? 60,
|
days_limit_import_messages: chatwoot_days_limit_import_messages ?? 60,
|
||||||
auto_create: true,
|
auto_create: true,
|
||||||
@@ -573,11 +576,12 @@ export class InstanceController {
|
|||||||
sign_msg: chatwoot_sign_msg || false,
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
reopen_conversation: chatwoot_reopen_conversation || false,
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
conversation_pending: chatwoot_conversation_pending || false,
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
|
merge_brazil_contacts: chatwoot_merge_brazil_contacts ?? false,
|
||||||
import_contacts: chatwoot_import_contacts ?? true,
|
import_contacts: chatwoot_import_contacts ?? true,
|
||||||
import_messages: chatwoot_import_messages ?? true,
|
import_messages: chatwoot_import_messages ?? true,
|
||||||
days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
|
days_limit_import_messages: chatwoot_days_limit_import_messages || 60,
|
||||||
number,
|
number,
|
||||||
name_inbox: instance.instanceName,
|
name_inbox: chatwoot_name_inbox ?? instance.instanceName,
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
webhook_url: `${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ export class ArchiveChatDto {
|
|||||||
archive: boolean;
|
archive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class MarkChatUnreadDto {
|
||||||
|
lastMessage?: LastMessage;
|
||||||
|
chat?: string;
|
||||||
|
}
|
||||||
|
|
||||||
class PrivacySetting {
|
class PrivacySetting {
|
||||||
readreceipts: WAReadReceiptsValue;
|
readreceipts: WAReadReceiptsValue;
|
||||||
profile: WAPrivacyValue;
|
profile: WAPrivacyValue;
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ export class InstanceDto {
|
|||||||
chatwoot_sign_msg?: boolean;
|
chatwoot_sign_msg?: boolean;
|
||||||
chatwoot_reopen_conversation?: boolean;
|
chatwoot_reopen_conversation?: boolean;
|
||||||
chatwoot_conversation_pending?: boolean;
|
chatwoot_conversation_pending?: boolean;
|
||||||
|
chatwoot_merge_brazil_contacts?: boolean;
|
||||||
chatwoot_import_contacts?: boolean;
|
chatwoot_import_contacts?: boolean;
|
||||||
chatwoot_import_messages?: boolean;
|
chatwoot_import_messages?: boolean;
|
||||||
chatwoot_days_limit_import_messages?: number;
|
chatwoot_days_limit_import_messages?: number;
|
||||||
|
chatwoot_name_inbox?: string;
|
||||||
websocket_enabled?: boolean;
|
websocket_enabled?: boolean;
|
||||||
websocket_events?: string[];
|
websocket_events?: string[];
|
||||||
rabbitmq_enabled?: boolean;
|
rabbitmq_enabled?: boolean;
|
||||||
|
|||||||
@@ -53,11 +53,15 @@ export class ChatwootController {
|
|||||||
data.conversation_pending = false;
|
data.conversation_pending = false;
|
||||||
data.import_contacts = false;
|
data.import_contacts = false;
|
||||||
data.import_messages = false;
|
data.import_messages = false;
|
||||||
|
data.merge_brazil_contacts = false;
|
||||||
data.days_limit_import_messages = 0;
|
data.days_limit_import_messages = 0;
|
||||||
data.auto_create = false;
|
data.auto_create = false;
|
||||||
|
data.name_inbox = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
data.name_inbox = instance.instanceName;
|
if (!data.name_inbox || data.name_inbox === '') {
|
||||||
|
data.name_inbox = instance.instanceName;
|
||||||
|
}
|
||||||
|
|
||||||
const result = await this.chatwootService.create(instance, data);
|
const result = await this.chatwootService.create(instance, data);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export class ChatwootDto {
|
|||||||
number?: string;
|
number?: string;
|
||||||
reopen_conversation?: boolean;
|
reopen_conversation?: boolean;
|
||||||
conversation_pending?: boolean;
|
conversation_pending?: boolean;
|
||||||
|
merge_brazil_contacts?: boolean;
|
||||||
import_contacts?: boolean;
|
import_contacts?: boolean;
|
||||||
import_messages?: boolean;
|
import_messages?: boolean;
|
||||||
days_limit_import_messages?: number;
|
days_limit_import_messages?: number;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export class ChatwootRaw {
|
|||||||
number?: string;
|
number?: string;
|
||||||
reopen_conversation?: boolean;
|
reopen_conversation?: boolean;
|
||||||
conversation_pending?: boolean;
|
conversation_pending?: boolean;
|
||||||
|
merge_brazil_contacts?: boolean;
|
||||||
import_contacts?: boolean;
|
import_contacts?: boolean;
|
||||||
import_messages?: boolean;
|
import_messages?: boolean;
|
||||||
days_limit_import_messages?: number;
|
days_limit_import_messages?: number;
|
||||||
@@ -31,6 +32,7 @@ const chatwootSchema = new Schema<ChatwootRaw>({
|
|||||||
number: { type: String, required: true },
|
number: { type: String, required: true },
|
||||||
reopen_conversation: { type: Boolean, required: true },
|
reopen_conversation: { type: Boolean, required: true },
|
||||||
conversation_pending: { type: Boolean, required: true },
|
conversation_pending: { type: Boolean, required: true },
|
||||||
|
merge_brazil_contacts: { type: Boolean, required: true },
|
||||||
import_contacts: { type: Boolean, required: true },
|
import_contacts: { type: Boolean, required: true },
|
||||||
import_messages: { type: Boolean, required: true },
|
import_messages: { type: Boolean, required: true },
|
||||||
days_limit_import_messages: { type: Number, required: true },
|
days_limit_import_messages: { type: Number, required: true },
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import ChatwootClient, {
|
|||||||
inbox,
|
inbox,
|
||||||
} from '@figuro/chatwoot-sdk';
|
} from '@figuro/chatwoot-sdk';
|
||||||
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
import { request as chatwootRequest } from '@figuro/chatwoot-sdk/dist/core/request';
|
||||||
|
import { proto } from '@whiskeysockets/baileys';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
import { createReadStream, unlinkSync, writeFileSync } from 'fs';
|
||||||
@@ -85,12 +86,14 @@ export class ChatwootService {
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getClientCwConfig(): ChatwootAPIConfig {
|
public getClientCwConfig(): ChatwootAPIConfig & { name_inbox: string; merge_brazil_contacts: boolean } {
|
||||||
return {
|
return {
|
||||||
basePath: this.provider.url,
|
basePath: this.provider.url,
|
||||||
with_credentials: true,
|
with_credentials: true,
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
token: this.provider.token,
|
token: this.provider.token,
|
||||||
|
name_inbox: this.provider.name_inbox,
|
||||||
|
merge_brazil_contacts: this.provider.merge_brazil_contacts,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +113,7 @@ export class ChatwootService {
|
|||||||
|
|
||||||
await this.initInstanceChatwoot(
|
await this.initInstanceChatwoot(
|
||||||
instance,
|
instance,
|
||||||
instance.instanceName.split('-cwId-')[0],
|
data.name_inbox ?? instance.instanceName.split('-cwId-')[0],
|
||||||
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
`${urlServer}/chatwoot/webhook/${encodeURIComponent(instance.instanceName)}`,
|
||||||
true,
|
true,
|
||||||
data.number,
|
data.number,
|
||||||
@@ -416,10 +419,49 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async mergeBrazilianContacts(contacts: any[]) {
|
||||||
|
try {
|
||||||
|
//sdk chatwoot não tem função merge
|
||||||
|
this.logger.verbose('merging contacts');
|
||||||
|
const contact = await chatwootRequest(this.getClientCwConfig(), {
|
||||||
|
method: 'POST',
|
||||||
|
url: `/api/v1/accounts/${this.provider.account_id}/actions/contact_merge`,
|
||||||
|
body: {
|
||||||
|
base_contact_id: contacts.find((contact) => contact.phone_number.length === 14)?.id,
|
||||||
|
mergee_contact_id: contacts.find((contact) => contact.phone_number.length === 13)?.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return contact;
|
||||||
|
} catch {
|
||||||
|
this.logger.error('Error merging contacts');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private findContactInContactList(contacts: any[], query: string) {
|
private findContactInContactList(contacts: any[], query: string) {
|
||||||
const phoneNumbers = this.getNumbers(query);
|
const phoneNumbers = this.getNumbers(query);
|
||||||
const searchableFields = this.getSearchableFields();
|
const searchableFields = this.getSearchableFields();
|
||||||
|
|
||||||
|
// eslint-disable-next-line prettier/prettier
|
||||||
|
if(contacts.length === 2 && this.getClientCwConfig().merge_brazil_contacts && query.startsWith('+55')){
|
||||||
|
|
||||||
|
const contact = this.mergeBrazilianContacts(contacts);
|
||||||
|
if (contact) {
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const phone = phoneNumbers.reduce(
|
||||||
|
(savedNumber, number) => (number.length > savedNumber.length ? number : savedNumber),
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
const contact_with9 = contacts.find((contact) => contact.phone_number === phone);
|
||||||
|
if (contact_with9) {
|
||||||
|
return contact_with9;
|
||||||
|
}
|
||||||
|
|
||||||
for (const contact of contacts) {
|
for (const contact of contacts) {
|
||||||
for (const field of searchableFields) {
|
for (const field of searchableFields) {
|
||||||
if (contact[field] && phoneNumbers.includes(contact[field])) {
|
if (contact[field] && phoneNumbers.includes(contact[field])) {
|
||||||
@@ -447,7 +489,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getSearchableFields() {
|
private getSearchableFields() {
|
||||||
return ['phone_number', 'identifier'];
|
return ['phone_number'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFilterPayload(query: string) {
|
private getFilterPayload(query: string) {
|
||||||
@@ -461,7 +503,7 @@ export class ChatwootService {
|
|||||||
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
|
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
|
||||||
filterPayload.push({
|
filterPayload.push({
|
||||||
attribute_key: field,
|
attribute_key: field,
|
||||||
filter_operator: ['phone_number', 'identifier'].includes(field) ? 'equal_to' : 'contains',
|
filter_operator: 'equal_to',
|
||||||
values: [number.replace('+', '')],
|
values: [number.replace('+', '')],
|
||||||
query_operator: queryOperator,
|
query_operator: queryOperator,
|
||||||
});
|
});
|
||||||
@@ -559,53 +601,44 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId);
|
const picture_url = await this.waMonitor.waInstances[instance.instanceName].profilePicture(chatId);
|
||||||
|
|
||||||
const findContact = await this.findContact(instance, chatId);
|
let contact = await this.findContact(instance, chatId);
|
||||||
|
|
||||||
let contact: any;
|
if (contact) {
|
||||||
if (body.key.fromMe) {
|
if (!body.key.fromMe) {
|
||||||
if (findContact) {
|
const waProfilePictureFile =
|
||||||
contact = await this.updateContact(instance, findContact.id, {
|
picture_url?.profilePictureUrl?.split('#')[0].split('?')[0].split('/').pop() || '';
|
||||||
avatar_url: picture_url.profilePictureUrl || null,
|
const chatwootProfilePictureFile = contact?.thumbnail?.split('#')[0].split('?')[0].split('/').pop() || '';
|
||||||
});
|
const pictureNeedsUpdate = waProfilePictureFile !== chatwootProfilePictureFile;
|
||||||
} else {
|
const nameNeedsUpdate =
|
||||||
const jid = isGroup ? null : body.key.remoteJid;
|
!contact.name ||
|
||||||
contact = await this.createContact(
|
contact.name === chatId ||
|
||||||
instance,
|
(`+${chatId}`.startsWith('+55')
|
||||||
chatId,
|
? this.getNumbers(`+${chatId}`).some(
|
||||||
filterInbox.id,
|
(v) => contact.name === v || contact.name === v.substring(3) || contact.name === v.substring(1),
|
||||||
isGroup,
|
)
|
||||||
nameContact,
|
: false);
|
||||||
picture_url.profilePictureUrl || null,
|
|
||||||
jid,
|
const contactNeedsUpdate = pictureNeedsUpdate || nameNeedsUpdate;
|
||||||
);
|
if (contactNeedsUpdate) {
|
||||||
|
this.logger.verbose('update contact in chatwoot');
|
||||||
|
contact = await this.updateContact(instance, contact.id, {
|
||||||
|
...(nameNeedsUpdate && { name: nameContact }),
|
||||||
|
...(waProfilePictureFile === '' && { avatar: null }),
|
||||||
|
...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (findContact) {
|
const jid = isGroup ? null : body.key.remoteJid;
|
||||||
if (!findContact.name || findContact.name === chatId) {
|
contact = await this.createContact(
|
||||||
contact = await this.updateContact(instance, findContact.id, {
|
instance,
|
||||||
name: nameContact,
|
chatId,
|
||||||
avatar_url: picture_url.profilePictureUrl || null,
|
filterInbox.id,
|
||||||
});
|
isGroup,
|
||||||
} else {
|
nameContact,
|
||||||
contact = await this.updateContact(instance, findContact.id, {
|
picture_url.profilePictureUrl || null,
|
||||||
avatar_url: picture_url.profilePictureUrl || null,
|
jid,
|
||||||
});
|
);
|
||||||
}
|
|
||||||
if (!contact) {
|
|
||||||
contact = await this.findContact(instance, chatId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const jid = isGroup ? null : body.key.remoteJid;
|
|
||||||
contact = await this.createContact(
|
|
||||||
instance,
|
|
||||||
chatId,
|
|
||||||
filterInbox.id,
|
|
||||||
isGroup,
|
|
||||||
nameContact,
|
|
||||||
picture_url.profilePictureUrl || null,
|
|
||||||
jid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
@@ -615,20 +648,13 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
|
const contactId = contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
|
||||||
|
|
||||||
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
|
|
||||||
this.logger.verbose('update contact name in chatwoot');
|
|
||||||
await this.updateContact(instance, contactId, {
|
|
||||||
name: nameContact,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.verbose('get contact conversations in chatwoot');
|
this.logger.verbose('get contact conversations in chatwoot');
|
||||||
const contactConversations = (await client.contacts.listConversations({
|
const contactConversations = (await client.contacts.listConversations({
|
||||||
accountId: this.provider.account_id,
|
accountId: this.provider.account_id,
|
||||||
id: contactId,
|
id: contactId,
|
||||||
})) as any;
|
})) as any;
|
||||||
|
|
||||||
if (contactConversations) {
|
if (contactConversations?.payload?.length) {
|
||||||
let conversation: any;
|
let conversation: any;
|
||||||
if (this.provider.reopen_conversation) {
|
if (this.provider.reopen_conversation) {
|
||||||
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
|
conversation = contactConversations.payload.find((conversation) => conversation.inbox_id == filterInbox.id);
|
||||||
@@ -710,7 +736,7 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('find inbox by name');
|
this.logger.verbose('find inbox by name');
|
||||||
const findByName = inbox.payload.find((inbox) => inbox.name === instance.instanceName.split('-cwId-')[0]);
|
const findByName = inbox.payload.find((inbox) => inbox.name === this.getClientCwConfig().name_inbox);
|
||||||
|
|
||||||
if (!findByName) {
|
if (!findByName) {
|
||||||
this.logger.warn('inbox not found');
|
this.logger.warn('inbox not found');
|
||||||
@@ -787,26 +813,15 @@ export class ChatwootService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = [
|
const conversations = (await client.contacts.listConversations({
|
||||||
['inbox_id', inbox.id.toString()],
|
accountId: this.provider.account_id,
|
||||||
['contact_id', contact.id.toString()],
|
id: contact.id,
|
||||||
['status', 'open'],
|
})) as any;
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(
|
conversations.payload.find(
|
||||||
(await client.conversations.filter({
|
(conversation) => conversation.inbox_id === inbox.id && conversation.status === 'open',
|
||||||
accountId: this.provider.account_id,
|
) || undefined
|
||||||
payload: payload.map((item, i, payload) => {
|
|
||||||
return {
|
|
||||||
attribute_key: item[0],
|
|
||||||
filter_operator: 'equal_to',
|
|
||||||
values: [item[1]],
|
|
||||||
query_operator: i < payload.length - 1 ? 'AND' : null,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
})) as { payload: conversation[] }
|
|
||||||
).payload[0] || undefined
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,6 +1121,26 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) {
|
||||||
|
const client = await this.clientCw(instance);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.messages.create({
|
||||||
|
accountId: this.provider.account_id,
|
||||||
|
conversationId: conversation,
|
||||||
|
data: {
|
||||||
|
content: i18next.t('cw.message.notsent', {
|
||||||
|
error: error?.length > 0 ? `_${error}_` : '',
|
||||||
|
}),
|
||||||
|
message_type: 'outgoing',
|
||||||
|
private: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async receiveWebhook(instance: InstanceDto, body: any) {
|
public async receiveWebhook(instance: InstanceDto, body: any) {
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
@@ -1274,6 +1309,11 @@ export class ChatwootService {
|
|||||||
return { message: 'bot' };
|
return { message: 'bot' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!waInstance && body.conversation?.id) {
|
||||||
|
this.onSendMessageError(instance, body.conversation?.id, 'Instance not found');
|
||||||
|
return { message: 'bot' };
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('Format message to send');
|
this.logger.verbose('Format message to send');
|
||||||
let formatText: string;
|
let formatText: string;
|
||||||
if (senderName === null || senderName === undefined) {
|
if (senderName === null || senderName === undefined) {
|
||||||
@@ -1310,6 +1350,9 @@ export class ChatwootService {
|
|||||||
formatText,
|
formatText,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
if (!messageSent && body.conversation?.id) {
|
||||||
|
this.onSendMessageError(instance, body.conversation?.id);
|
||||||
|
}
|
||||||
|
|
||||||
this.updateChatwootMessageId(
|
this.updateChatwootMessageId(
|
||||||
{
|
{
|
||||||
@@ -1343,23 +1386,34 @@ export class ChatwootService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageSent = await waInstance?.textMessage(data, true);
|
let messageSent: MessageRaw | proto.WebMessageInfo;
|
||||||
|
try {
|
||||||
|
messageSent = await waInstance?.textMessage(data, true);
|
||||||
|
if (!messageSent) {
|
||||||
|
throw new Error('Message not sent');
|
||||||
|
}
|
||||||
|
|
||||||
this.updateChatwootMessageId(
|
this.updateChatwootMessageId(
|
||||||
{
|
{
|
||||||
...messageSent,
|
...messageSent,
|
||||||
owner: instance.instanceName,
|
owner: instance.instanceName,
|
||||||
},
|
|
||||||
{
|
|
||||||
messageId: body.id,
|
|
||||||
inboxId: body.inbox?.id,
|
|
||||||
conversationId: body.conversation?.id,
|
|
||||||
contactInbox: {
|
|
||||||
sourceId: body.conversation?.contact_inbox?.source_id,
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
instance,
|
messageId: body.id,
|
||||||
);
|
inboxId: body.inbox?.id,
|
||||||
|
conversationId: body.conversation?.id,
|
||||||
|
contactInbox: {
|
||||||
|
sourceId: body.conversation?.contact_inbox?.source_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
instance,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
if (!messageSent && body.conversation?.id) {
|
||||||
|
this.onSendMessageError(instance, body.conversation?.id, error.toString());
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,12 @@ export const chatwootSchema: JSONSchema7 = {
|
|||||||
url: { type: 'string' },
|
url: { type: 'string' },
|
||||||
sign_msg: { type: 'boolean', enum: [true, false] },
|
sign_msg: { type: 'boolean', enum: [true, false] },
|
||||||
sign_delimiter: { type: ['string', 'null'] },
|
sign_delimiter: { type: ['string', 'null'] },
|
||||||
|
name_inbox: { type: ['string', 'null'] },
|
||||||
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
||||||
conversation_pending: { type: 'boolean', enum: [true, false] },
|
conversation_pending: { type: 'boolean', enum: [true, false] },
|
||||||
auto_create: { type: 'boolean', enum: [true, false] },
|
auto_create: { type: 'boolean', enum: [true, false] },
|
||||||
import_contacts: { type: 'boolean', enum: [true, false] },
|
import_contacts: { type: 'boolean', enum: [true, false] },
|
||||||
|
merge_brazil_contacts: { type: 'boolean', enum: [true, false] },
|
||||||
import_messages: { type: 'boolean', enum: [true, false] },
|
import_messages: { type: 'boolean', enum: [true, false] },
|
||||||
days_limit_import_messages: { type: 'number' },
|
days_limit_import_messages: { type: 'number' },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SQS } from 'aws-sdk';
|
import { SQS } from '@aws-sdk/client-sqs';
|
||||||
|
|
||||||
import { configService, Sqs } from '../../../../config/env.config';
|
import { configService, Sqs } from '../../../../config/env.config';
|
||||||
import { Logger } from '../../../../config/logger.config';
|
import { Logger } from '../../../../config/logger.config';
|
||||||
@@ -12,8 +12,11 @@ export const initSQS = () => {
|
|||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const awsConfig = configService.get<Sqs>('SQS');
|
const awsConfig = configService.get<Sqs>('SQS');
|
||||||
sqs = new SQS({
|
sqs = new SQS({
|
||||||
accessKeyId: awsConfig.ACCESS_KEY_ID,
|
credentials: {
|
||||||
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
|
accessKeyId: awsConfig.ACCESS_KEY_ID,
|
||||||
|
secretAccessKey: awsConfig.SECRET_ACCESS_KEY,
|
||||||
|
},
|
||||||
|
|
||||||
region: awsConfig.REGION,
|
region: awsConfig.REGION,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ export class IntegrationRaw {
|
|||||||
token?: string;
|
token?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sqsSchema = new Schema<IntegrationRaw>({
|
const integrationSchema = new Schema<IntegrationRaw>({
|
||||||
_id: { type: String, _id: true },
|
_id: { type: String, _id: true },
|
||||||
integration: { type: String, required: true },
|
integration: { type: String, required: true },
|
||||||
number: { type: String, required: true },
|
number: { type: String, required: true },
|
||||||
token: { type: String, required: true },
|
token: { type: String, required: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const IntegrationModel = dbserver?.model(IntegrationRaw.name, sqsSchema, 'integration');
|
export const IntegrationModel = dbserver?.model(IntegrationRaw.name, integrationSchema, 'integration');
|
||||||
export type IntegrationModel = typeof IntegrationModel;
|
export type IntegrationModel = typeof IntegrationModel;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export class MessageRaw {
|
|||||||
source_reply_id?: string;
|
source_reply_id?: string;
|
||||||
chatwoot?: ChatwootMessage;
|
chatwoot?: ChatwootMessage;
|
||||||
contextInfo?: any;
|
contextInfo?: any;
|
||||||
|
status?: wa.StatusMessage | any;
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageRawBoolean<T> = {
|
type MessageRawBoolean<T> = {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
blockUserSchema,
|
blockUserSchema,
|
||||||
contactValidateSchema,
|
contactValidateSchema,
|
||||||
deleteMessageSchema,
|
deleteMessageSchema,
|
||||||
|
markChatUnreadSchema,
|
||||||
messageUpSchema,
|
messageUpSchema,
|
||||||
messageValidateSchema,
|
messageValidateSchema,
|
||||||
presenceSchema,
|
presenceSchema,
|
||||||
@@ -24,6 +25,7 @@ import {
|
|||||||
BlockUserDto,
|
BlockUserDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
|
MarkChatUnreadDto,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
PrivacySettingDto,
|
PrivacySettingDto,
|
||||||
ProfileNameDto,
|
ProfileNameDto,
|
||||||
@@ -98,6 +100,23 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
|
.put(this.routerPath('markChatUnread'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in markChatUnread');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
|
||||||
|
const response = await this.dataValidate<MarkChatUnreadDto>({
|
||||||
|
request: req,
|
||||||
|
schema: markChatUnreadSchema,
|
||||||
|
ClassRef: MarkChatUnreadDto,
|
||||||
|
execute: (instance, data) => chatController.markChatUnread(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
.delete(this.routerPath('deleteMessageForEveryone'), ...guards, async (req, res) => {
|
.delete(this.routerPath('deleteMessageForEveryone'), ...guards, async (req, res) => {
|
||||||
logger.verbose('request received in deleteMessageForEveryone');
|
logger.verbose('request received in deleteMessageForEveryone');
|
||||||
logger.verbose('request body: ');
|
logger.verbose('request body: ');
|
||||||
|
|||||||
@@ -38,17 +38,17 @@ import { waMonitor } from '../server.module';
|
|||||||
import { Events, wa } from '../types/wa.types';
|
import { Events, wa } from '../types/wa.types';
|
||||||
import { CacheService } from './cache.service';
|
import { CacheService } from './cache.service';
|
||||||
|
|
||||||
export class WAStartupService {
|
export class ChannelStartupService {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly configService: ConfigService,
|
public readonly configService: ConfigService,
|
||||||
public readonly eventEmitter: EventEmitter2,
|
public readonly eventEmitter: EventEmitter2,
|
||||||
public readonly repository: RepositoryBroker,
|
public readonly repository: RepositoryBroker,
|
||||||
public readonly chatwootCache: CacheService,
|
public readonly chatwootCache: CacheService,
|
||||||
) {
|
) {
|
||||||
this.logger.verbose('WAStartupService initialized');
|
this.logger.verbose('ChannelStartupService initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly logger = new Logger(WAStartupService.name);
|
public readonly logger = new Logger(ChannelStartupService.name);
|
||||||
|
|
||||||
public client: WASocket;
|
public client: WASocket;
|
||||||
public readonly instance: wa.Instance = {};
|
public readonly instance: wa.Instance = {};
|
||||||
@@ -136,11 +136,13 @@ export class WAStartupService {
|
|||||||
|
|
||||||
public async findIntegration() {
|
public async findIntegration() {
|
||||||
this.logger.verbose('Finding integration');
|
this.logger.verbose('Finding integration');
|
||||||
const data = await this.repository.integration.find(this.instanceName);
|
let data: any;
|
||||||
|
|
||||||
|
data = await this.repository.integration.find(this.instanceName);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
this.logger.verbose('Integration not found');
|
this.repository.integration.create({ integration: 'WHATSAPP-BAILEYS', number: '', token: '' }, this.instanceName);
|
||||||
throw new NotFoundException('Integration not found');
|
data = { integration: 'WHATSAPP-BAILEYS', number: '', token: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose(`Integration: ${data.integration}`);
|
this.logger.verbose(`Integration: ${data.integration}`);
|
||||||
@@ -354,6 +356,7 @@ export class WAStartupService {
|
|||||||
this.logger.verbose(`Chatwoot sign delimiter: ${data.sign_delimiter}`);
|
this.logger.verbose(`Chatwoot sign delimiter: ${data.sign_delimiter}`);
|
||||||
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
||||||
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
||||||
|
this.logger.verbose(`Chatwoot merge brazilian contacts: ${data.import_contacts}`);
|
||||||
this.logger.verbose(`Chatwoot import contacts: ${data.import_contacts}`);
|
this.logger.verbose(`Chatwoot import contacts: ${data.import_contacts}`);
|
||||||
this.logger.verbose(`Chatwoot import messages: ${data.import_messages}`);
|
this.logger.verbose(`Chatwoot import messages: ${data.import_messages}`);
|
||||||
this.logger.verbose(`Chatwoot days limit import messages: ${data.days_limit_import_messages}`);
|
this.logger.verbose(`Chatwoot days limit import messages: ${data.days_limit_import_messages}`);
|
||||||
@@ -368,6 +371,7 @@ export class WAStartupService {
|
|||||||
sign_delimiter: data.sign_delimiter || null,
|
sign_delimiter: data.sign_delimiter || null,
|
||||||
reopen_conversation: data.reopen_conversation,
|
reopen_conversation: data.reopen_conversation,
|
||||||
conversation_pending: data.conversation_pending,
|
conversation_pending: data.conversation_pending,
|
||||||
|
merge_brazil_contacts: data.merge_brazil_contacts,
|
||||||
import_contacts: data.import_contacts,
|
import_contacts: data.import_contacts,
|
||||||
import_messages: data.import_messages,
|
import_messages: data.import_messages,
|
||||||
days_limit_import_messages: data.days_limit_import_messages,
|
days_limit_import_messages: data.days_limit_import_messages,
|
||||||
@@ -740,7 +744,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendData-RabbitMQ',
|
local: ChannelStartupService.name + '.sendData-RabbitMQ',
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
data,
|
data,
|
||||||
@@ -796,7 +800,7 @@ export class WAStartupService {
|
|||||||
sqs.sendMessage(params, (err, data) => {
|
sqs.sendMessage(params, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: WAStartupService.name + '.sendData-SQS',
|
local: ChannelStartupService.name + '.sendData-SQS',
|
||||||
message: err?.message,
|
message: err?.message,
|
||||||
hostName: err?.hostname,
|
hostName: err?.hostname,
|
||||||
code: err?.code,
|
code: err?.code,
|
||||||
@@ -808,7 +812,7 @@ export class WAStartupService {
|
|||||||
} else {
|
} else {
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendData-SQS',
|
local: ChannelStartupService.name + '.sendData-SQS',
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
data,
|
data,
|
||||||
@@ -852,7 +856,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendData-WebsocketGlobal',
|
local: ChannelStartupService.name + '.sendData-WebsocketGlobal',
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
data,
|
data,
|
||||||
@@ -882,7 +886,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendData-Websocket',
|
local: ChannelStartupService.name + '.sendData-Websocket',
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
data,
|
data,
|
||||||
@@ -916,7 +920,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendDataWebhook-local',
|
local: ChannelStartupService.name + '.sendDataWebhook-local',
|
||||||
url: baseURL,
|
url: baseURL,
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
@@ -956,7 +960,7 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: WAStartupService.name + '.sendDataWebhook-local',
|
local: ChannelStartupService.name + '.sendDataWebhook-local',
|
||||||
message: error?.message,
|
message: error?.message,
|
||||||
hostName: error?.hostname,
|
hostName: error?.hostname,
|
||||||
syscall: error?.syscall,
|
syscall: error?.syscall,
|
||||||
@@ -988,7 +992,7 @@ export class WAStartupService {
|
|||||||
|
|
||||||
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
if (this.configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS')) {
|
||||||
const logData = {
|
const logData = {
|
||||||
local: WAStartupService.name + '.sendDataWebhook-global',
|
local: ChannelStartupService.name + '.sendDataWebhook-global',
|
||||||
url: globalURL,
|
url: globalURL,
|
||||||
event,
|
event,
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
@@ -1027,7 +1031,7 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: WAStartupService.name + '.sendDataWebhook-global',
|
local: ChannelStartupService.name + '.sendDataWebhook-global',
|
||||||
message: error?.message,
|
message: error?.message,
|
||||||
hostName: error?.hostname,
|
hostName: error?.hostname,
|
||||||
syscall: error?.syscall,
|
syscall: error?.syscall,
|
||||||
@@ -40,7 +40,7 @@ import { Label } from '@whiskeysockets/baileys/lib/Types/Label';
|
|||||||
import { LabelAssociation } from '@whiskeysockets/baileys/lib/Types/LabelAssociation';
|
import { LabelAssociation } from '@whiskeysockets/baileys/lib/Types/LabelAssociation';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
import { isBase64, isURL } from 'class-validator';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
// import ffmpeg from 'fluent-ffmpeg';
|
// import ffmpeg from 'fluent-ffmpeg';
|
||||||
import fs, { existsSync, readFileSync } from 'fs';
|
import fs, { existsSync, readFileSync } from 'fs';
|
||||||
@@ -68,6 +68,7 @@ import {
|
|||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
getBase64FromMediaMessageDto,
|
getBase64FromMediaMessageDto,
|
||||||
LastMessage,
|
LastMessage,
|
||||||
|
MarkChatUnreadDto,
|
||||||
NumberBusiness,
|
NumberBusiness,
|
||||||
OnWhatsAppDto,
|
OnWhatsAppDto,
|
||||||
PrivacySettingDto,
|
PrivacySettingDto,
|
||||||
@@ -97,7 +98,6 @@ import {
|
|||||||
MediaMessage,
|
MediaMessage,
|
||||||
Options,
|
Options,
|
||||||
SendAudioDto,
|
SendAudioDto,
|
||||||
SendButtonDto,
|
|
||||||
SendContactDto,
|
SendContactDto,
|
||||||
SendListDto,
|
SendListDto,
|
||||||
SendLocationDto,
|
SendLocationDto,
|
||||||
@@ -118,9 +118,9 @@ import { RepositoryBroker } from '../../repository/repository.manager';
|
|||||||
import { waMonitor } from '../../server.module';
|
import { waMonitor } from '../../server.module';
|
||||||
import { Events, MessageSubtype, TypeMediaMessage, wa } from '../../types/wa.types';
|
import { Events, MessageSubtype, TypeMediaMessage, wa } from '../../types/wa.types';
|
||||||
import { CacheService } from './../cache.service';
|
import { CacheService } from './../cache.service';
|
||||||
import { WAStartupService } from './../whatsapp.service';
|
import { ChannelStartupService } from './../channel.service';
|
||||||
|
|
||||||
export class BaileysStartupService extends WAStartupService {
|
export class BaileysStartupService extends ChannelStartupService {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly configService: ConfigService,
|
public readonly configService: ConfigService,
|
||||||
public readonly eventEmitter: EventEmitter2,
|
public readonly eventEmitter: EventEmitter2,
|
||||||
@@ -148,17 +148,17 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
public mobile: boolean;
|
public mobile: boolean;
|
||||||
|
|
||||||
private async recoveringMessages() {
|
private async recoveringMessages() {
|
||||||
|
this.logger.info('Recovering messages lost');
|
||||||
const cacheConf = this.configService.get<CacheConf>('CACHE');
|
const cacheConf = this.configService.get<CacheConf>('CACHE');
|
||||||
|
|
||||||
if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) {
|
if ((cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') || cacheConf?.LOCAL?.ENABLED) {
|
||||||
setTimeout(async () => {
|
setInterval(async () => {
|
||||||
this.logger.info('Recovering messages');
|
|
||||||
this.messagesLostCache.keys().then((keys) => {
|
this.messagesLostCache.keys().then((keys) => {
|
||||||
keys.forEach(async (key) => {
|
keys.forEach(async (key) => {
|
||||||
const message = await this.messagesLostCache.get(key.split(':')[2]);
|
const message = await this.messagesLostCache.get(key.split(':')[2]);
|
||||||
|
|
||||||
if (message.messageStubParameters && message.messageStubParameters[0] === 'Message absent from node') {
|
if (message.messageStubParameters && message.messageStubParameters[0] === 'Message absent from node') {
|
||||||
this.logger.verbose('Message absent from node, retrying to send, key: ' + key.split(':')[2]);
|
this.logger.info('Message absent from node, retrying to send, key: ' + key.split(':')[2]);
|
||||||
await this.client.sendMessageAck(JSON.parse(message.messageStubParameters[1], BufferJSON.reviver));
|
await this.client.sendMessageAck(JSON.parse(message.messageStubParameters[1], BufferJSON.reviver));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -496,13 +496,24 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
this.mobile = mobile;
|
this.mobile = mobile;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { version } = await fetchLatestBaileysVersion();
|
|
||||||
|
|
||||||
this.logger.verbose('Baileys version: ' + version);
|
|
||||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
||||||
this.logger.verbose('Browser: ' + JSON.stringify(browser));
|
this.logger.verbose('Browser: ' + JSON.stringify(browser));
|
||||||
|
|
||||||
|
let version;
|
||||||
|
let log;
|
||||||
|
|
||||||
|
if (session.VERSION) {
|
||||||
|
version = session.VERSION.split(',');
|
||||||
|
log = `Baileys version env: ${version}`;
|
||||||
|
} else {
|
||||||
|
const baileysVersion = await fetchLatestBaileysVersion();
|
||||||
|
version = baileysVersion.version;
|
||||||
|
log = `Baileys version: ${version}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(log);
|
||||||
|
|
||||||
let options;
|
let options;
|
||||||
|
|
||||||
if (this.localProxy.enabled) {
|
if (this.localProxy.enabled) {
|
||||||
@@ -517,6 +528,7 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
const proxyUrl = 'http://' + proxyUrls[rand];
|
const proxyUrl = 'http://' + proxyUrls[rand];
|
||||||
options = {
|
options = {
|
||||||
agent: makeProxyAgent(proxyUrl),
|
agent: makeProxyAgent(proxyUrl),
|
||||||
|
fetchAgent: makeProxyAgent(proxyUrl),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.localProxy.enabled = false;
|
this.localProxy.enabled = false;
|
||||||
@@ -524,6 +536,7 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
} else {
|
} else {
|
||||||
options = {
|
options = {
|
||||||
agent: makeProxyAgent(this.localProxy.proxy),
|
agent: makeProxyAgent(this.localProxy.proxy),
|
||||||
|
fetchAgent: makeProxyAgent(this.localProxy.proxy),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -669,10 +682,23 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
try {
|
try {
|
||||||
this.instance.authState = await this.defineAuthState();
|
this.instance.authState = await this.defineAuthState();
|
||||||
|
|
||||||
const { version } = await fetchLatestBaileysVersion();
|
|
||||||
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
const session = this.configService.get<ConfigSessionPhone>('CONFIG_SESSION_PHONE');
|
||||||
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
const browser: WABrowserDescription = [session.CLIENT, session.NAME, release()];
|
||||||
|
|
||||||
|
let version;
|
||||||
|
let log;
|
||||||
|
|
||||||
|
if (session.VERSION) {
|
||||||
|
version = session.VERSION.split(',');
|
||||||
|
log = `Baileys version env: ${version}`;
|
||||||
|
} else {
|
||||||
|
const baileysVersion = await fetchLatestBaileysVersion();
|
||||||
|
version = baileysVersion.version;
|
||||||
|
log = `Baileys version: ${version}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(log);
|
||||||
|
|
||||||
let options;
|
let options;
|
||||||
|
|
||||||
if (this.localProxy.enabled) {
|
if (this.localProxy.enabled) {
|
||||||
@@ -687,6 +713,7 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
const proxyUrl = 'http://' + proxyUrls[rand];
|
const proxyUrl = 'http://' + proxyUrls[rand];
|
||||||
options = {
|
options = {
|
||||||
agent: makeProxyAgent(proxyUrl),
|
agent: makeProxyAgent(proxyUrl),
|
||||||
|
fetchAgent: makeProxyAgent(proxyUrl),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.localProxy.enabled = false;
|
this.localProxy.enabled = false;
|
||||||
@@ -694,6 +721,7 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
} else {
|
} else {
|
||||||
options = {
|
options = {
|
||||||
agent: makeProxyAgent(this.localProxy.proxy),
|
agent: makeProxyAgent(this.localProxy.proxy),
|
||||||
|
fetchAgent: makeProxyAgent(this.localProxy.proxy),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -997,6 +1025,15 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const status: Record<number, wa.StatusMessage> = {
|
||||||
|
0: 'ERROR',
|
||||||
|
1: 'PENDING',
|
||||||
|
2: 'SERVER_ACK',
|
||||||
|
3: 'DELIVERY_ACK',
|
||||||
|
4: 'READ',
|
||||||
|
5: 'PLAYED',
|
||||||
|
};
|
||||||
|
|
||||||
messagesRaw.push({
|
messagesRaw.push({
|
||||||
key: m.key,
|
key: m.key,
|
||||||
pushName: m.pushName || m.key.remoteJid.split('@')[0],
|
pushName: m.pushName || m.key.remoteJid.split('@')[0],
|
||||||
@@ -1005,6 +1042,7 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
messageType: getContentType(m.message),
|
messageType: getContentType(m.message),
|
||||||
messageTimestamp: m.messageTimestamp as number,
|
messageTimestamp: m.messageTimestamp as number,
|
||||||
owner: this.instance.name,
|
owner: this.instance.name,
|
||||||
|
status: m.status ? status[m.status] : null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2193,15 +2231,6 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
|
|
||||||
mimetype = response.headers['content-type'];
|
mimetype = response.headers['content-type'];
|
||||||
}
|
}
|
||||||
// if (isURL(mediaMessage.media)) {
|
|
||||||
// const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' });
|
|
||||||
|
|
||||||
// mimetype = response.headers['content-type'];
|
|
||||||
// console.log('mediaMessage.mimetype2', mimetype);
|
|
||||||
// } else {
|
|
||||||
// mimetype = getMIMEType(mediaMessage.fileName);
|
|
||||||
// console.log('mediaMessage.mimetype3', mimetype);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('Mimetype: ' + mimetype);
|
this.logger.verbose('Mimetype: ' + mimetype);
|
||||||
@@ -2316,82 +2345,6 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
|
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async processAudio(audio: string, number: string) {
|
|
||||||
// this.logger.verbose('Processing audio');
|
|
||||||
// let tempAudioPath: string;
|
|
||||||
// let outputAudio: string;
|
|
||||||
|
|
||||||
// number = number.replace(/\D/g, '');
|
|
||||||
// const hash = `${number}-${new Date().getTime()}`;
|
|
||||||
// this.logger.verbose('Hash to audio name: ' + hash);
|
|
||||||
|
|
||||||
// if (isURL(audio)) {
|
|
||||||
// this.logger.verbose('Audio is url');
|
|
||||||
|
|
||||||
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
|
|
||||||
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
|
|
||||||
|
|
||||||
// this.logger.verbose('Output audio path: ' + outputAudio);
|
|
||||||
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
|
|
||||||
|
|
||||||
// const timestamp = new Date().getTime();
|
|
||||||
// const url = `${audio}?timestamp=${timestamp}`;
|
|
||||||
|
|
||||||
// this.logger.verbose('Including timestamp in url: ' + url);
|
|
||||||
|
|
||||||
// let config: any = {
|
|
||||||
// responseType: 'arraybuffer',
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if (this.localProxy.enabled) {
|
|
||||||
// config = {
|
|
||||||
// ...config,
|
|
||||||
// httpsAgent: makeProxyAgent(this.localProxy.proxy),
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const response = await axios.get(url, config);
|
|
||||||
// this.logger.verbose('Getting audio from url');
|
|
||||||
|
|
||||||
// fs.writeFileSync(tempAudioPath, response.data);
|
|
||||||
// } else {
|
|
||||||
// this.logger.verbose('Audio is base64');
|
|
||||||
|
|
||||||
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
|
|
||||||
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
|
|
||||||
|
|
||||||
// this.logger.verbose('Output audio path: ' + outputAudio);
|
|
||||||
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
|
|
||||||
|
|
||||||
// const audioBuffer = Buffer.from(audio, 'base64');
|
|
||||||
// fs.writeFileSync(tempAudioPath, audioBuffer);
|
|
||||||
// this.logger.verbose('Temp audio created');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.logger.verbose('Converting audio to mp4');
|
|
||||||
// return new Promise((resolve, reject) => {
|
|
||||||
// // This fix was suggested by @PurpShell
|
|
||||||
// ffmpeg.setFfmpegPath(ffmpegPath.path);
|
|
||||||
|
|
||||||
// ffmpeg()
|
|
||||||
// .input(tempAudioPath)
|
|
||||||
// .outputFormat('ogg')
|
|
||||||
// .noVideo()
|
|
||||||
// .audioCodec('libopus')
|
|
||||||
// .save(outputAudio)
|
|
||||||
// .on('error', function (error) {
|
|
||||||
// console.log('error', error);
|
|
||||||
// fs.unlinkSync(tempAudioPath);
|
|
||||||
// if (error) reject(error);
|
|
||||||
// })
|
|
||||||
// .on('end', async function () {
|
|
||||||
// fs.unlinkSync(tempAudioPath);
|
|
||||||
// resolve(outputAudio);
|
|
||||||
// })
|
|
||||||
// .run();
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
public async processAudio(audio: string, number: string) {
|
public async processAudio(audio: string, number: string) {
|
||||||
this.logger.verbose('Processing audio');
|
this.logger.verbose('Processing audio');
|
||||||
let tempAudioPath: string;
|
let tempAudioPath: string;
|
||||||
@@ -2492,50 +2445,8 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async buttonMessage(data: SendButtonDto) {
|
public async buttonMessage() {
|
||||||
this.logger.verbose('Sending button message');
|
throw new BadRequestException('Method not available on WhatsApp Baileys');
|
||||||
const embeddedMedia: any = {};
|
|
||||||
let mediatype = 'TEXT';
|
|
||||||
|
|
||||||
if (data.buttonMessage?.mediaMessage) {
|
|
||||||
mediatype = data.buttonMessage.mediaMessage?.mediatype.toUpperCase() ?? 'TEXT';
|
|
||||||
embeddedMedia.mediaKey = mediatype.toLowerCase() + 'Message';
|
|
||||||
const generate = await this.prepareMediaMessage(data.buttonMessage.mediaMessage);
|
|
||||||
embeddedMedia.message = generate.message[embeddedMedia.mediaKey];
|
|
||||||
embeddedMedia.contentText = `*${data.buttonMessage.title}*\n\n${data.buttonMessage.description}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const btnItems = {
|
|
||||||
text: data.buttonMessage.buttons.map((btn) => btn.buttonText),
|
|
||||||
ids: data.buttonMessage.buttons.map((btn) => btn.buttonId),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!arrayUnique(btnItems.text) || !arrayUnique(btnItems.ids)) {
|
|
||||||
throw new BadRequestException('Button texts cannot be repeated', 'Button IDs cannot be repeated.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.sendMessageWithTyping(
|
|
||||||
data.number,
|
|
||||||
{
|
|
||||||
buttonsMessage: {
|
|
||||||
text: !embeddedMedia?.mediaKey ? data.buttonMessage.title : undefined,
|
|
||||||
contentText: embeddedMedia?.contentText ?? data.buttonMessage.description,
|
|
||||||
footerText: data.buttonMessage?.footerText,
|
|
||||||
buttons: data.buttonMessage.buttons.map((button) => {
|
|
||||||
return {
|
|
||||||
buttonText: {
|
|
||||||
displayText: button.buttonText,
|
|
||||||
},
|
|
||||||
buttonId: button.buttonId,
|
|
||||||
type: 1,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
headerType: proto.Message.ButtonsMessage.HeaderType[mediatype],
|
|
||||||
[embeddedMedia?.mediaKey]: embeddedMedia?.message,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data?.options,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async locationMessage(data: SendLocationDto) {
|
public async locationMessage(data: SendLocationDto) {
|
||||||
@@ -2828,6 +2739,45 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async markChatUnread(data: MarkChatUnreadDto) {
|
||||||
|
this.logger.verbose('Marking chat as unread');
|
||||||
|
|
||||||
|
try {
|
||||||
|
let last_message = data.lastMessage;
|
||||||
|
let number = data.chat;
|
||||||
|
|
||||||
|
if (!last_message && number) {
|
||||||
|
last_message = await this.getLastMessage(number);
|
||||||
|
} else {
|
||||||
|
last_message = data.lastMessage;
|
||||||
|
last_message.messageTimestamp = last_message?.messageTimestamp ?? Date.now();
|
||||||
|
number = last_message?.key?.remoteJid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!last_message || Object.keys(last_message).length === 0) {
|
||||||
|
throw new NotFoundException('Last message not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.client.chatModify(
|
||||||
|
{
|
||||||
|
markRead: false,
|
||||||
|
lastMessages: [last_message],
|
||||||
|
},
|
||||||
|
this.createJid(number),
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
chatId: number,
|
||||||
|
markedChatUnread: true,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new InternalServerErrorException({
|
||||||
|
markedChatUnread: false,
|
||||||
|
message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async deleteMessage(del: DeleteMessage) {
|
public async deleteMessage(del: DeleteMessage) {
|
||||||
this.logger.verbose('Deleting message');
|
this.logger.verbose('Deleting message');
|
||||||
try {
|
try {
|
||||||
@@ -26,9 +26,9 @@ import { ContactRaw, MessageRaw, MessageUpdateRaw, SettingsRaw } from '../../mod
|
|||||||
import { RepositoryBroker } from '../../repository/repository.manager';
|
import { RepositoryBroker } from '../../repository/repository.manager';
|
||||||
import { Events, wa } from '../../types/wa.types';
|
import { Events, wa } from '../../types/wa.types';
|
||||||
import { CacheService } from './../cache.service';
|
import { CacheService } from './../cache.service';
|
||||||
import { WAStartupService } from './../whatsapp.service';
|
import { ChannelStartupService } from './../channel.service';
|
||||||
|
|
||||||
export class BusinessStartupService extends WAStartupService {
|
export class BusinessStartupService extends ChannelStartupService {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly configService: ConfigService,
|
public readonly configService: ConfigService,
|
||||||
public readonly eventEmitter: EventEmitter2,
|
public readonly eventEmitter: EventEmitter2,
|
||||||
@@ -1258,6 +1258,9 @@ export class BusinessStartupService extends WAStartupService {
|
|||||||
public async archiveChat() {
|
public async archiveChat() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
|
public async markChatUnread() {
|
||||||
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
|
}
|
||||||
public async fetchProfile() {
|
public async fetchProfile() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,8 @@ export class IntegrationService {
|
|||||||
const result = await this.waMonitor.waInstances[instance.instanceName].findIntegration();
|
const result = await this.waMonitor.waInstances[instance.instanceName].findIntegration();
|
||||||
|
|
||||||
if (Object.keys(result).length === 0) {
|
if (Object.keys(result).length === 0) {
|
||||||
throw new Error('Integration not found');
|
this.create(instance, { integration: 'WHATSAPP-BAILEYS', number: '', token: '' });
|
||||||
|
return { integration: 'WHATSAPP-BAILEYS', number: '', token: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import {
|
|||||||
import { RepositoryBroker } from '../repository/repository.manager';
|
import { RepositoryBroker } from '../repository/repository.manager';
|
||||||
import { Integration } from '../types/wa.types';
|
import { Integration } from '../types/wa.types';
|
||||||
import { CacheService } from './cache.service';
|
import { CacheService } from './cache.service';
|
||||||
import { BaileysStartupService } from './whatsapp/whatsapp.baileys.service';
|
import { BaileysStartupService } from './channels/whatsapp.baileys.service';
|
||||||
import { BusinessStartupService } from './whatsapp/whatsapp.business.service';
|
import { BusinessStartupService } from './channels/whatsapp.business.service';
|
||||||
|
|
||||||
export class WAMonitoringService {
|
export class WAMonitoringService {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
5
src/cache/cacheengine.ts
vendored
5
src/cache/cacheengine.ts
vendored
@@ -1,8 +1,11 @@
|
|||||||
import { ICache } from '../api/abstract/abstract.cache';
|
import { ICache } from '../api/abstract/abstract.cache';
|
||||||
import { CacheConf, ConfigService } from '../config/env.config';
|
import { CacheConf, ConfigService } from '../config/env.config';
|
||||||
|
import { Logger } from '../config/logger.config';
|
||||||
import { LocalCache } from './localcache';
|
import { LocalCache } from './localcache';
|
||||||
import { RedisCache } from './rediscache';
|
import { RedisCache } from './rediscache';
|
||||||
|
|
||||||
|
const logger = new Logger('Redis');
|
||||||
|
|
||||||
export class CacheEngine {
|
export class CacheEngine {
|
||||||
private engine: ICache;
|
private engine: ICache;
|
||||||
|
|
||||||
@@ -14,6 +17,8 @@ export class CacheEngine {
|
|||||||
} else if (cacheConf?.LOCAL?.ENABLED) {
|
} else if (cacheConf?.LOCAL?.ENABLED) {
|
||||||
this.engine = new LocalCache(configService, module);
|
this.engine = new LocalCache(configService, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(`RedisCache initialized for ${module}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEngine() {
|
public getEngine() {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export type CacheConfLocal = {
|
|||||||
};
|
};
|
||||||
export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
|
export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
|
||||||
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
|
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
|
||||||
export type ConfigSessionPhone = { CLIENT: string; NAME: string };
|
export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string };
|
||||||
export type QrCode = { LIMIT: number; COLOR: string };
|
export type QrCode = { LIMIT: number; COLOR: string };
|
||||||
export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean };
|
export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean };
|
||||||
export type Chatwoot = {
|
export type Chatwoot = {
|
||||||
@@ -251,8 +251,8 @@ export class ConfigService {
|
|||||||
LABELS: process.env?.STORE_LABELS === 'true',
|
LABELS: process.env?.STORE_LABELS === 'true',
|
||||||
},
|
},
|
||||||
CLEAN_STORE: {
|
CLEAN_STORE: {
|
||||||
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_TERMINAL)
|
CLEANING_INTERVAL: Number.isInteger(process.env?.CLEAN_STORE_CLEANING_INTERVAL)
|
||||||
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_TERMINAL)
|
? Number.parseInt(process.env.CLEAN_STORE_CLEANING_INTERVAL)
|
||||||
: 7200,
|
: 7200,
|
||||||
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
MESSAGES: process.env?.CLEAN_STORE_MESSAGES === 'true',
|
||||||
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
MESSAGE_UP: process.env?.CLEAN_STORE_MESSAGE_UP === 'true',
|
||||||
@@ -360,6 +360,7 @@ export class ConfigService {
|
|||||||
CONFIG_SESSION_PHONE: {
|
CONFIG_SESSION_PHONE: {
|
||||||
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
|
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',
|
||||||
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'Chrome',
|
NAME: process.env?.CONFIG_SESSION_PHONE_NAME || 'Chrome',
|
||||||
|
VERSION: process.env?.CONFIG_SESSION_PHONE_VERSION || null,
|
||||||
},
|
},
|
||||||
QRCODE: {
|
QRCODE: {
|
||||||
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
LIMIT: Number.parseInt(process.env.QRCODE_LIMIT) || 30,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ info:
|
|||||||
</font>
|
</font>
|
||||||
|
|
||||||
[](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442)
|
[](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442)
|
||||||
version: 1.7.3
|
version: 1.7.5
|
||||||
contact:
|
contact:
|
||||||
name: DavidsonGomes
|
name: DavidsonGomes
|
||||||
email: contato@agenciadgcode.com
|
email: contato@agenciadgcode.com
|
||||||
@@ -194,6 +194,8 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
description: Check the connection state of your instance.
|
description: Check the connection state of your instance.
|
||||||
example: "evolution"
|
example: "evolution"
|
||||||
|
security:
|
||||||
|
- apikeyAuth: []
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Successful response
|
description: Successful response
|
||||||
@@ -2242,6 +2244,9 @@ paths:
|
|||||||
conversation_pending:
|
conversation_pending:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: "Indicates whether to mark conversations as pending."
|
description: "Indicates whether to mark conversations as pending."
|
||||||
|
merge_brazil_contacts:
|
||||||
|
type: boolean
|
||||||
|
description: "Indicates whether to merge Brazil numbers in case of numbers with and without ninth digit."
|
||||||
import_contacts:
|
import_contacts:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: "Indicates whether to import contacts from phone to Chatwoot when connecting."
|
description: "Indicates whether to import contacts from phone to Chatwoot when connecting."
|
||||||
|
|||||||
@@ -22,5 +22,6 @@
|
|||||||
"cw.contactMessage.contact": "Contact",
|
"cw.contactMessage.contact": "Contact",
|
||||||
"cw.contactMessage.name": "Name",
|
"cw.contactMessage.name": "Name",
|
||||||
"cw.contactMessage.number": "Number",
|
"cw.contactMessage.number": "Number",
|
||||||
|
"cw.message.notsent": "🚨 The message could not be sent. Please check your connection. {{error}}",
|
||||||
"cw.message.edited": "Edited Message"
|
"cw.message.edited": "Edited Message"
|
||||||
}
|
}
|
||||||
@@ -22,5 +22,6 @@
|
|||||||
"cw.contactMessage.contact": "Contacto",
|
"cw.contactMessage.contact": "Contacto",
|
||||||
"cw.contactMessage.name": "Nombre",
|
"cw.contactMessage.name": "Nombre",
|
||||||
"cw.contactMessage.number": "Numero",
|
"cw.contactMessage.number": "Numero",
|
||||||
|
"cw.message.notsent": "🚨 El mensaje no se pudo enviar. Comprueba tu conexión. {{error}}",
|
||||||
"cw.message.edited": "Mensaje editado"
|
"cw.message.edited": "Mensaje editado"
|
||||||
}
|
}
|
||||||
@@ -22,5 +22,6 @@
|
|||||||
"cw.contactMessage.contact": "Contato",
|
"cw.contactMessage.contact": "Contato",
|
||||||
"cw.contactMessage.name": "Nome",
|
"cw.contactMessage.name": "Nome",
|
||||||
"cw.contactMessage.number": "Número",
|
"cw.contactMessage.number": "Número",
|
||||||
|
"cw.message.notsent": "🚨 Não foi possível enviar a mensagem. Verifique sua conexão. {{error}}",
|
||||||
"cw.message.edited": "Mensagem editada"
|
"cw.message.edited": "Mensagem editada"
|
||||||
}
|
}
|
||||||
@@ -597,6 +597,33 @@ export const archiveChatSchema: JSONSchema7 = {
|
|||||||
required: ['archive'],
|
required: ['archive'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const markChatUnreadSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
chat: { type: 'string' },
|
||||||
|
lastMessage: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
key: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
id: { type: 'string' },
|
||||||
|
remoteJid: { type: 'string' },
|
||||||
|
fromMe: { type: 'boolean', enum: [true, false] },
|
||||||
|
},
|
||||||
|
required: ['id', 'fromMe', 'remoteJid'],
|
||||||
|
...isNotEmpty('id', 'remoteJid'),
|
||||||
|
},
|
||||||
|
messageTimestamp: { type: 'integer', minLength: 1 },
|
||||||
|
},
|
||||||
|
required: ['key'],
|
||||||
|
...isNotEmpty('messageTimestamp'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['lastMessage'],
|
||||||
|
};
|
||||||
|
|
||||||
export const deleteMessageSchema: JSONSchema7 = {
|
export const deleteMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="pt-br">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link rel="shortcut icon" href="https://evolution-api.com/files/evolution-api-favicon.png" type="image/x-icon">
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
|
|
||||||
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
|
|
||||||
<title>Instance Manager</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="container mt-4">
|
|
||||||
<!-- Botão para abrir o modal de adicionar nova instância -->
|
|
||||||
<button class="btn btn-primary mb-3" data-toggle="modal" data-target="#actionModal" data-action="add">Nova
|
|
||||||
Instância</button>
|
|
||||||
|
|
||||||
<!-- Tabela de instâncias -->
|
|
||||||
<table class="table table-bordered">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Nome da Instância</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th>API Key</th>
|
|
||||||
<th>Ações</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<!-- Iterando sobre as instâncias e preenchendo a tabela -->
|
|
||||||
{{#each instances}}
|
|
||||||
<tr>
|
|
||||||
<td>{{this.instance.instanceName}}</td>
|
|
||||||
<td>{{this.instance.status}}</td>
|
|
||||||
<td>{{this.instance.apikey}}</td>
|
|
||||||
<td>
|
|
||||||
<!-- Dropdown de ações para cada instância -->
|
|
||||||
<div class="dropdown">
|
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="actionDropdown"
|
|
||||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
Ações
|
|
||||||
</button>
|
|
||||||
<div class="dropdown-menu" aria-labelledby="actionDropdown">
|
|
||||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
|
|
||||||
data-action="connect">Connect</a>
|
|
||||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
|
|
||||||
data-action="restart">Restart</a>
|
|
||||||
<!-- Adicione mais itens de ação aqui -->
|
|
||||||
<!-- ... -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{/each}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Modal de ações -->
|
|
||||||
<div class="modal fade" id="actionModal" tabindex="-1" role="dialog" aria-labelledby="actionModalLabel"
|
|
||||||
aria-hidden="true">
|
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="actionModalLabel">Ação</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
|
|
||||||
<button type="button" class="btn btn-primary">Salvar</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
|
|
||||||
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
|
|
||||||
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js"
|
|
||||||
integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function(){
|
|
||||||
$('#actionModal').on('show.bs.modal', function(event) {
|
|
||||||
var button = $(event.relatedTarget);
|
|
||||||
var action = button.data('action');
|
|
||||||
|
|
||||||
console.log(action);
|
|
||||||
|
|
||||||
if (action === 'connect') {
|
|
||||||
|
|
||||||
} else if (action === 'restart') {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user