mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
fix: remove vcard support, waiting for better implementation
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
import { QueryInterface, DataTypes } from "sequelize";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface: QueryInterface) => {
|
||||||
|
return queryInterface.removeColumn("Messages", "vcardContactId");
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface: QueryInterface) => {
|
||||||
|
return queryInterface.addColumn("Messages", "vcardContactId", {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
references: { model: "Contacts", key: "id" },
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
interface JCard {
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Meta {
|
|
||||||
[key: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ParseVcardToJson = (input: string): JCard => {
|
|
||||||
const Re1 = /^(version|fn|title|org):(.+)$/i;
|
|
||||||
const Re2 = /^([^:;]+);([^:]+):(.+)$/;
|
|
||||||
const ReKey = /item\d{1,2}\./;
|
|
||||||
const fields = {} as JCard;
|
|
||||||
|
|
||||||
input.split(/\r\n|\r|\n/).forEach(line => {
|
|
||||||
let results;
|
|
||||||
let key;
|
|
||||||
|
|
||||||
if (Re1.test(line)) {
|
|
||||||
results = line.match(Re1);
|
|
||||||
if (results) {
|
|
||||||
key = results[1].toLowerCase();
|
|
||||||
const [, , res] = results;
|
|
||||||
fields[key] = res;
|
|
||||||
}
|
|
||||||
} else if (Re2.test(line)) {
|
|
||||||
results = line.match(Re2);
|
|
||||||
if (results) {
|
|
||||||
key = results[1].replace(ReKey, "").toLowerCase();
|
|
||||||
|
|
||||||
const meta = {} as Meta;
|
|
||||||
results[2]
|
|
||||||
.split(";")
|
|
||||||
.map((p, i) => {
|
|
||||||
const match = p.match(/([a-z]+)=(.*)/i);
|
|
||||||
if (match) {
|
|
||||||
return [match[1], match[2]];
|
|
||||||
}
|
|
||||||
return [`TYPE${i === 0 ? "" : i}`, p];
|
|
||||||
})
|
|
||||||
.forEach(p => {
|
|
||||||
const [, m] = p;
|
|
||||||
meta[p[0]] = m;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!fields[key]) fields[key] = [];
|
|
||||||
|
|
||||||
fields[key].push({
|
|
||||||
meta,
|
|
||||||
value: results[3].split(";")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return fields;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ParseVcardToJson;
|
|
||||||
@@ -72,13 +72,6 @@ class Message extends Model<Message> {
|
|||||||
|
|
||||||
@BelongsTo(() => Contact, "contactId")
|
@BelongsTo(() => Contact, "contactId")
|
||||||
contact: Contact;
|
contact: Contact;
|
||||||
|
|
||||||
@ForeignKey(() => Contact)
|
|
||||||
@Column
|
|
||||||
vcardContactId: number;
|
|
||||||
|
|
||||||
@BelongsTo(() => Contact, "vcardContactId")
|
|
||||||
vcardContact: Contact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Message;
|
export default Message;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ interface MessageData {
|
|||||||
ticketId: number;
|
ticketId: number;
|
||||||
body: string;
|
body: string;
|
||||||
contactId?: number;
|
contactId?: number;
|
||||||
vcardContactId?: number;
|
|
||||||
fromMe?: boolean;
|
fromMe?: boolean;
|
||||||
read?: boolean;
|
read?: boolean;
|
||||||
mediaType?: string;
|
mediaType?: string;
|
||||||
@@ -29,7 +28,7 @@ const CreateMessageService = async ({
|
|||||||
await Message.upsert(messageData);
|
await Message.upsert(messageData);
|
||||||
|
|
||||||
const message = await Message.findByPk(messageData.id, {
|
const message = await Message.findByPk(messageData.id, {
|
||||||
include: ["contact", "vcardContact"]
|
include: ["contact"]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const ListMessagesService = async ({
|
|||||||
const { count, rows: messages } = await Message.findAndCountAll({
|
const { count, rows: messages } = await Message.findAndCountAll({
|
||||||
where: whereCondition,
|
where: whereCondition,
|
||||||
limit,
|
limit,
|
||||||
include: ["contact", "vcardContact"],
|
include: ["contact"],
|
||||||
offset,
|
offset,
|
||||||
order: [["createdAt", "DESC"]]
|
order: [["createdAt", "DESC"]]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { getIO } from "../../libs/socket";
|
|||||||
import { getWbot } from "../../libs/wbot";
|
import { getWbot } from "../../libs/wbot";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||||
import ParseVcardToJson from "../../helpers/ParseVcardToJson";
|
|
||||||
import CreateMessageService from "../MessageServices/CreateMessageService";
|
import CreateMessageService from "../MessageServices/CreateMessageService";
|
||||||
|
|
||||||
const writeFileAsync = promisify(writeFile);
|
const writeFileAsync = promisify(writeFile);
|
||||||
@@ -181,8 +180,7 @@ const handlMedia = async (
|
|||||||
const handleMessage = async (
|
const handleMessage = async (
|
||||||
msg: WbotMessage,
|
msg: WbotMessage,
|
||||||
ticket: Ticket,
|
ticket: Ticket,
|
||||||
contact: Contact,
|
contact: Contact
|
||||||
vcardContact?: Contact
|
|
||||||
) => {
|
) => {
|
||||||
let newMessage: Message | null;
|
let newMessage: Message | null;
|
||||||
|
|
||||||
@@ -193,7 +191,6 @@ const handleMessage = async (
|
|||||||
id: msg.id.id,
|
id: msg.id.id,
|
||||||
ticketId: ticket.id,
|
ticketId: ticket.id,
|
||||||
contactId: msg.fromMe ? undefined : contact.id,
|
contactId: msg.fromMe ? undefined : contact.id,
|
||||||
vcardContactId: vcardContact ? vcardContact.id : undefined,
|
|
||||||
body: msg.body,
|
body: msg.body,
|
||||||
fromMe: msg.fromMe,
|
fromMe: msg.fromMe,
|
||||||
mediaType: msg.type,
|
mediaType: msg.type,
|
||||||
@@ -246,7 +243,6 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
|||||||
try {
|
try {
|
||||||
let msgContact: WbotContact;
|
let msgContact: WbotContact;
|
||||||
let groupContact: Contact | undefined;
|
let groupContact: Contact | undefined;
|
||||||
let vcardContact: Contact | undefined;
|
|
||||||
|
|
||||||
if (msg.fromMe) {
|
if (msg.fromMe) {
|
||||||
msgContact = await wbot.getContactById(msg.to);
|
msgContact = await wbot.getContactById(msg.to);
|
||||||
@@ -259,27 +255,25 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
|||||||
msgContact = await msg.getContact();
|
msgContact = await msg.getContact();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if message has an author, its a gruop message.
|
const chat = await msg.getChat();
|
||||||
|
|
||||||
if (msg.author) {
|
if (chat.isGroup) {
|
||||||
const msgGroupContact = await wbot.getContactById(msg.from);
|
let msgGroupContact;
|
||||||
groupContact = await verifyGroup(msgGroupContact);
|
|
||||||
|
if (msg.fromMe) {
|
||||||
|
msgGroupContact = await wbot.getContactById(msg.to);
|
||||||
|
} else {
|
||||||
|
msgGroupContact = await wbot.getContactById(msg.from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.type === "vcard") {
|
groupContact = await verifyGroup(msgGroupContact);
|
||||||
const { tel } = ParseVcardToJson(msg.body);
|
|
||||||
const vcardWaid = tel[0]?.meta?.waid;
|
|
||||||
const vcardMsgContact = await wbot.getContactById(`${vcardWaid}@c.us`);
|
|
||||||
const profilePicUrl = await vcardMsgContact.getProfilePicUrl();
|
|
||||||
|
|
||||||
vcardContact = await verifyContact(vcardMsgContact, profilePicUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, whatsappId, groupContact);
|
const ticket = await verifyTicket(contact, whatsappId, groupContact);
|
||||||
|
|
||||||
await handleMessage(msg, ticket, contact, vcardContact);
|
await handleMessage(msg, ticket, contact);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -311,7 +305,7 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const messageToUpdate = await Message.findByPk(msg.id.id, {
|
const messageToUpdate = await Message.findByPk(msg.id.id, {
|
||||||
include: ["contact", "vcardContact"]
|
include: ["contact"]
|
||||||
});
|
});
|
||||||
if (!messageToUpdate) {
|
if (!messageToUpdate) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,13 +14,7 @@ import DoneIcon from "@material-ui/icons/Done";
|
|||||||
import DoneAllIcon from "@material-ui/icons/DoneAll";
|
import DoneAllIcon from "@material-ui/icons/DoneAll";
|
||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
|
||||||
import {
|
import { IconButton } from "@material-ui/core";
|
||||||
Avatar,
|
|
||||||
Card,
|
|
||||||
CardActions,
|
|
||||||
CardHeader,
|
|
||||||
IconButton,
|
|
||||||
} from "@material-ui/core";
|
|
||||||
import { Block, ExpandMore } from "@material-ui/icons";
|
import { Block, ExpandMore } from "@material-ui/icons";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
@@ -449,27 +443,6 @@ const Ticket = () => {
|
|||||||
controls
|
controls
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
if (message.mediaType === "vcard") {
|
|
||||||
return (
|
|
||||||
<Card className={classes.vcard} variant="outlined">
|
|
||||||
<CardHeader
|
|
||||||
avatar={
|
|
||||||
<Avatar
|
|
||||||
aria-label="contact-avatar"
|
|
||||||
src={message.vcardContact?.profilePicUrl}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title={message.vcardContact?.name}
|
|
||||||
subheader={message.vcardContact?.number}
|
|
||||||
/>
|
|
||||||
<CardActions>
|
|
||||||
{/* <Button size="small" variant="contained">
|
|
||||||
Send Message
|
|
||||||
</Button> */}
|
|
||||||
</CardActions>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<a href={message.mediaUrl} target="_blank" rel="noopener noreferrer">
|
<a href={message.mediaUrl} target="_blank" rel="noopener noreferrer">
|
||||||
@@ -559,15 +532,14 @@ const Ticket = () => {
|
|||||||
{renderDailyTimestamps(message, index)}
|
{renderDailyTimestamps(message, index)}
|
||||||
{renderMessageDivider(message, index)}
|
{renderMessageDivider(message, index)}
|
||||||
<div className={classes.messageLeft}>
|
<div className={classes.messageLeft}>
|
||||||
{(message.mediaUrl || message.mediaType === "vcard") &&
|
{message.mediaUrl && checkMessageMedia(message)}
|
||||||
checkMessageMedia(message)}
|
|
||||||
{ticket.isGroup && (
|
{ticket.isGroup && (
|
||||||
<span className={classes.messageContactName}>
|
<span className={classes.messageContactName}>
|
||||||
{message.contact?.name}
|
{message.contact?.name}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<div className={classes.textContentItem}>
|
<div className={classes.textContentItem}>
|
||||||
{message.mediaType !== "vcard" && message.body}
|
{message.body}
|
||||||
<span className={classes.timestamp}>
|
<span className={classes.timestamp}>
|
||||||
{format(parseISO(message.createdAt), "HH:mm")}
|
{format(parseISO(message.createdAt), "HH:mm")}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user