mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
feat: finished multiple whatsapp support
This commit is contained in:
@@ -7,6 +7,7 @@ const Sentry = require("@sentry/node");
|
|||||||
const Contact = require("../models/Contact");
|
const Contact = require("../models/Contact");
|
||||||
const Ticket = require("../models/Ticket");
|
const Ticket = require("../models/Ticket");
|
||||||
const Message = require("../models/Message");
|
const Message = require("../models/Message");
|
||||||
|
const Whatsapp = require("../models/Whatsapp");
|
||||||
|
|
||||||
const { getIO } = require("../libs/socket");
|
const { getIO } = require("../libs/socket");
|
||||||
const { getWbot, initWbot } = require("../libs/wbot");
|
const { getWbot, initWbot } = require("../libs/wbot");
|
||||||
@@ -29,7 +30,7 @@ const verifyContact = async (msgContact, profilePicUrl) => {
|
|||||||
return contact;
|
return contact;
|
||||||
};
|
};
|
||||||
|
|
||||||
const verifyTicket = async contact => {
|
const verifyTicket = async (contact, whatsappId) => {
|
||||||
let ticket = await Ticket.findOne({
|
let ticket = await Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
status: {
|
status: {
|
||||||
@@ -57,6 +58,7 @@ const verifyTicket = async contact => {
|
|||||||
ticket = await Ticket.create({
|
ticket = await Ticket.create({
|
||||||
contactId: contact.id,
|
contactId: contact.id,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
|
whatsappId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,11 +135,12 @@ const handleMessage = async (msg, ticket, contact) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const wbotMessageListener = whatsapp => {
|
const wbotMessageListener = whatsapp => {
|
||||||
const wbot = getWbot(whatsapp.id);
|
const whatsappId = whatsapp.id;
|
||||||
|
const wbot = getWbot(whatsappId);
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|
||||||
wbot.on("message_create", async msg => {
|
wbot.on("message_create", async msg => {
|
||||||
console.log(msg);
|
// console.log(msg);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
msg.from === "status@broadcast" ||
|
msg.from === "status@broadcast" ||
|
||||||
@@ -159,7 +162,7 @@ const wbotMessageListener = whatsapp => {
|
|||||||
|
|
||||||
const profilePicUrl = await msgContact.getProfilePicUrl();
|
const profilePicUrl = await msgContact.getProfilePicUrl();
|
||||||
const contact = await verifyContact(msgContact, profilePicUrl);
|
const contact = await verifyContact(msgContact, profilePicUrl);
|
||||||
const ticket = await verifyTicket(contact);
|
const ticket = await verifyTicket(contact, whatsappId);
|
||||||
|
|
||||||
//return if message was already created by messageController
|
//return if message was already created by messageController
|
||||||
if (msg.fromMe) {
|
if (msg.fromMe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user