Remove image sending capabilities - cant be tested
This commit is contained in:
1362
bridge/package-lock.json
generated
Normal file
1362
bridge/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -12,13 +12,6 @@ interface SendCommand {
|
|||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SendImageCommand {
|
|
||||||
type: 'send_image';
|
|
||||||
to: string;
|
|
||||||
imagePath: string;
|
|
||||||
caption?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BridgeMessage {
|
interface BridgeMessage {
|
||||||
type: 'message' | 'status' | 'qr' | 'error';
|
type: 'message' | 'status' | 'qr' | 'error';
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
@@ -79,7 +72,7 @@ export class BridgeServer {
|
|||||||
|
|
||||||
ws.on('message', async (data) => {
|
ws.on('message', async (data) => {
|
||||||
try {
|
try {
|
||||||
const cmd = JSON.parse(data.toString()) as SendCommand | SendImageCommand;
|
const cmd = JSON.parse(data.toString()) as SendCommand;
|
||||||
await this.handleCommand(cmd);
|
await this.handleCommand(cmd);
|
||||||
ws.send(JSON.stringify({ type: 'sent', to: cmd.to }));
|
ws.send(JSON.stringify({ type: 'sent', to: cmd.to }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -99,11 +92,9 @@ export class BridgeServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleCommand(cmd: SendCommand | SendImageCommand): Promise<void> {
|
private async handleCommand(cmd: SendCommand): Promise<void> {
|
||||||
if (cmd.type === 'send' && this.wa) {
|
if (cmd.type === 'send' && this.wa) {
|
||||||
await this.wa.sendMessage(cmd.to, cmd.text);
|
await this.wa.sendMessage(cmd.to, cmd.text);
|
||||||
} else if (cmd.type === 'send_image' && this.wa) {
|
|
||||||
await this.wa.sendImage(cmd.to, cmd.imagePath, cmd.caption);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import makeWASocket, {
|
|||||||
import { Boom } from '@hapi/boom';
|
import { Boom } from '@hapi/boom';
|
||||||
import qrcode from 'qrcode-terminal';
|
import qrcode from 'qrcode-terminal';
|
||||||
import pino from 'pino';
|
import pino from 'pino';
|
||||||
import { writeFile, mkdir, readFile } from 'fs/promises';
|
import { writeFile, mkdir } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { homedir } from 'os';
|
import { homedir } from 'os';
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
@@ -217,18 +217,6 @@ export class WhatsAppClient {
|
|||||||
await this.sock.sendMessage(to, { text });
|
await this.sock.sendMessage(to, { text });
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendImage(to: string, imagePath: string, caption?: string): Promise<void> {
|
|
||||||
if (!this.sock) {
|
|
||||||
throw new Error('Not connected');
|
|
||||||
}
|
|
||||||
|
|
||||||
const buffer = await readFile(imagePath);
|
|
||||||
await this.sock.sendMessage(to, {
|
|
||||||
image: buffer,
|
|
||||||
caption: caption || undefined,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async disconnect(): Promise<void> {
|
async disconnect(): Promise<void> {
|
||||||
if (this.sock) {
|
if (this.sock) {
|
||||||
this.sock.end(undefined);
|
this.sock.end(undefined);
|
||||||
|
|||||||
@@ -83,26 +83,12 @@ class WhatsAppChannel(BaseChannel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Send media files first
|
payload = {
|
||||||
for media_path in (msg.media or []):
|
"type": "send",
|
||||||
try:
|
"to": msg.chat_id,
|
||||||
payload = {
|
"text": msg.content
|
||||||
"type": "send_image",
|
}
|
||||||
"to": msg.chat_id,
|
await self._ws.send(json.dumps(payload, ensure_ascii=False))
|
||||||
"imagePath": media_path,
|
|
||||||
}
|
|
||||||
await self._ws.send(json.dumps(payload, ensure_ascii=False))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Error sending WhatsApp media {}: {}", media_path, e)
|
|
||||||
|
|
||||||
# Send text message if there's content
|
|
||||||
if msg.content:
|
|
||||||
payload = {
|
|
||||||
"type": "send",
|
|
||||||
"to": msg.chat_id,
|
|
||||||
"text": msg.content
|
|
||||||
}
|
|
||||||
await self._ws.send(json.dumps(payload, ensure_ascii=False))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error sending WhatsApp message: {}", e)
|
logger.error("Error sending WhatsApp message: {}", e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user