2023-02-07 15:47:40 +00:00
|
|
|
import { getIO } from "../libs/socket";
|
|
|
|
import Ticket from "../models/Ticket";
|
2023-09-08 19:50:51 +00:00
|
|
|
import sendWhatsAppMessageOfficialAPI from "./sendWhatsAppMessageOfficialAPI"
|
2023-02-07 15:47:40 +00:00
|
|
|
|
2023-09-08 19:50:51 +00:00
|
|
|
function sendWhatsAppMessageSocket(
|
|
|
|
ticket: Ticket,
|
|
|
|
body: string,
|
|
|
|
quotedMsgSerializedId?: string | undefined,
|
|
|
|
number?: string
|
|
|
|
) {
|
|
|
|
const { phoneNumberId } = ticket;
|
2023-02-07 15:47:40 +00:00
|
|
|
|
2023-09-08 19:50:51 +00:00
|
|
|
if (phoneNumberId) {
|
|
|
|
sendWhatsAppMessageOfficialAPI(ticket, body, quotedMsgSerializedId);
|
|
|
|
return;
|
|
|
|
}
|
2023-02-07 15:47:40 +00:00
|
|
|
|
2023-09-08 19:50:51 +00:00
|
|
|
const io = getIO();
|
2023-02-07 15:47:40 +00:00
|
|
|
|
2023-09-08 19:50:51 +00:00
|
|
|
io.to(`session_${ticket.whatsappId.toString()}`).emit("send_message", {
|
|
|
|
action: "create",
|
|
|
|
msg: {
|
|
|
|
number: number
|
|
|
|
? number
|
|
|
|
: `${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
|
|
|
|
body: body,
|
|
|
|
quotedMessageId: quotedMsgSerializedId,
|
|
|
|
linkPreview: false
|
|
|
|
}
|
|
|
|
});
|
2023-02-07 15:47:40 +00:00
|
|
|
}
|
|
|
|
|
2023-09-08 19:50:51 +00:00
|
|
|
export default sendWhatsAppMessageSocket;
|