Corrreção para abrir links de whatsapp pelo omnihit

adriano 2023-06-13 09:47:57 -03:00
parent 307ceca26e
commit 9f2d574251
10 changed files with 63 additions and 48 deletions

View File

@ -25,6 +25,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
const { ticketId } = req.params; const { ticketId } = req.params;
const { pageNumber } = req.query as IndexQuery; const { pageNumber } = req.query as IndexQuery;
// console.log(':::::::::::::> TICKET ID: ', ticketId)
const { count, messages, ticket, hasMore } = await ListMessagesService({ const { count, messages, ticket, hasMore } = await ListMessagesService({
pageNumber, pageNumber,
ticketId ticketId

View File

@ -128,8 +128,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
export const show = async (req: Request, res: Response): Promise<Response> => { export const show = async (req: Request, res: Response): Promise<Response> => {
const { ticketId } = req.params; const { ticketId } = req.params;
const contact = await ShowTicketService(ticketId); const contact = await ShowTicketService(ticketId);
const { statusChatEnd, count, hasMore } = await ListStatusChatEndService({ searchParam: "", pageNumber: "1" }); const { statusChatEnd, count, hasMore } = await ListStatusChatEndService({ searchParam: "", pageNumber: "1" });

View File

@ -39,7 +39,7 @@ export const initIO = (httpServer: Server): SocketIO => {
io = new SocketIO(httpServer, { io = new SocketIO(httpServer, {
cors: { cors: {
origin: process.env.FRONTEND_URL origin: process.env.FRONTEND_URL
}, },
maxHttpBufferSize: 1e8 maxHttpBufferSize: 1e8
}); });
@ -59,18 +59,18 @@ export const initIO = (httpServer: Server): SocketIO => {
}); });
socket.on("message_from_client", () => { socket.on("message_from_client", () => {
socket.emit('message_from_server', 'Sent an event from the server!'); socket.emit('message_from_server', 'Sent an event from the server!');
}) })
socket.on("message_create", async (data: any) => { socket.on("message_create", async (data: any) => {
handleMessage(data.msg, data); handleMessage(data.msg, data);
}); });
socket.on("media_uploaded", async (data: any) => { socket.on("media_uploaded", async (data: any) => {
handleMessage(data.msg, data); handleMessage(data.msg, data);
@ -220,11 +220,11 @@ export const initIO = (httpServer: Server): SocketIO => {
}); });
socket.on("joinChatBox", (ticketId: string) => { socket.on("joinChatBox", (ticketId: string) => {
logger.info("A client joined a ticket channel"); logger.info("A client joined a ticket channel");
const regex = /^[0-9\b]+$/; // Regular expression to match only numbers const regex = /^[0-9\b]+$/; // Regular expression to match only numbers
if (ticketId && !ticketId.match(regex)) return if (ticketId && !ticketId.match(regex) || !ticketId) return
socket.join(ticketId); socket.join(ticketId);
}); });
@ -247,18 +247,18 @@ export const initIO = (httpServer: Server): SocketIO => {
let rooms = socket.rooms let rooms = socket.rooms
console.log('rooms: ', rooms, ' | rooms.size: ', rooms.size) console.log('rooms: ', rooms, ' | rooms.size: ', rooms.size)
if(rooms && rooms.size==1) return if (rooms && rooms.size == 1) return
if(rooms && rooms.size==2 && !([...rooms][1].startsWith('session_'))) return if (rooms && rooms.size == 2 && !([...rooms][1].startsWith('session_'))) return
let whatsappIds: any = await Whatsapp.findAll({ attributes: ['id'], raw: true }) let whatsappIds: any = await Whatsapp.findAll({ attributes: ['id'], raw: true })
if (whatsappIds && whatsappIds.length > 0) { if (whatsappIds && whatsappIds.length > 0) {
whatsappIds = whatsappIds.map((e: any) => `${e.id}`) whatsappIds = whatsappIds.map((e: any) => `${e.id}`)
console.log('whatsappIds whatsappIds whatsappIds whatsappIds whatsappIds: ',whatsappIds) console.log('whatsappIds whatsappIds whatsappIds whatsappIds whatsappIds: ', whatsappIds)
if (rooms && rooms.size == 2 && if (rooms && rooms.size == 2 &&
[...rooms][1].startsWith('session_') && [...rooms][1].startsWith('session_') &&

View File

@ -18,11 +18,9 @@ interface Response {
const ListMessagesService = async ({ const ListMessagesService = async ({
pageNumber = "1", pageNumber = "1",
ticketId ticketId
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
console.log('>>>>>>>>>>>>>>>>>>>> ticketId: ', ticketId) if ((ticketId && ticketId.length > 9) || !ticketId || (ticketId && ticketId === 'undefined')) {
if (ticketId && ticketId.length > 9) {
return { return {
messages: [], messages: [],
ticket: new Ticket, ticket: new Ticket,

View File

@ -70,13 +70,9 @@ const CreateTicketService = async ({
if (!ticket) { if (!ticket) {
throw new AppError("ERR_CREATING_TICKET"); throw new AppError("ERR_CREATING_TICKET");
} }
// console.log('CONTACT ticket.id: ', ticket.id)
// console.log('>>>>>>>>>>>>>>>>> msg: ', msg)
if (msg.length > 0) { if (msg.length > 0) {
sendWhatsAppMessageSocket(ticket, msg) sendWhatsAppMessageSocket(ticket, msg)
} }

View File

@ -15,8 +15,7 @@ const FindOrCreateTicketService = async (
groupContact?: Contact groupContact?: Contact
): Promise<Ticket> => { ): Promise<Ticket> => {
try { try {
let ticket = await Ticket.findOne({ let ticket = await Ticket.findOne({
where: { where: {
status: { status: {

View File

@ -115,9 +115,9 @@ const Ticket = () => {
}, [ticketId, history]); }, [ticketId, history]);
useEffect(() => { useEffect(() => {
const regex = /^[0-9\b]+$/; // Regular expression to match only numbers const regex = /^[0-9\b]+$/; // Regular expression to match only numbers
if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 ) return if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 || !ticketId) return
const socket = openSocket(process.env.REACT_APP_BACKEND_URL); const socket = openSocket(process.env.REACT_APP_BACKEND_URL);

View File

@ -183,17 +183,14 @@ const TicketsList = (props) => {
const [ticketsList, dispatch] = useReducer(reducer, []); const [ticketsList, dispatch] = useReducer(reducer, []);
const { user } = useContext(AuthContext); const { user } = useContext(AuthContext);
const { searchTicket } = useContext(SearchTicketContext) const { searchTicket } = useContext(SearchTicketContext)
useEffect(() => { useEffect(() => {
dispatch({ type: "RESET" }); dispatch({ type: "RESET" });
setPageNumber(1); setPageNumber(1);
}, [status, searchParam, showAll, selectedQueueIds, searchTicket]); }, [status, searchParam, showAll, selectedQueueIds, searchTicket]);
const { tickets, hasMore, loading } = useTickets({ const { tickets, hasMore, loading } = useTickets({
pageNumber, pageNumber,

View File

@ -94,25 +94,46 @@ const Ticket = () => {
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
const delayDebounceFn = setTimeout(() => { const delayDebounceFn = setTimeout(() => {
const fetchTicket = async () => { const fetchTicket = async () => {
console.log('+++++++++++ ticketId: ', ticketId)
try { try {
let number let number
let msg let msg = ''
let contactId let contactId
let link
console.log('ticketId: ', ticketId) link = window.location.href
console.log('window.location.href): ', window.location.href)
const link = window.location.href.split('/https://wa.me/') if (link.includes('/https://wa.me/')) {
number = link[1].split('?text=')[0] link = window.location.href.split('/https://wa.me/')
msg = link[1].split('?text=')[1] || ''
msg = decodeURIComponent(msg); number = link[1].split('?text=')[0]
msg = link[1].split('?text=')[1] || ''
}
else if (link.includes('https://web.whatsapp.com/send/?phone')) {
let aux = link.split('?phone=')
number = aux[1].split('&text')[0]
if (link.includes('&text=')) {
msg = aux[1].split('&text=')[1]
msg = msg.replaceAll("+", " ");
msg = msg.split('&type=')[0]
}
}
if (msg && msg.trim().length > 0) {
msg = decodeURIComponent(msg);
}
console.log('NUMBER: ', number, ' | MESSAGE: ', msg)
const { data: data0 } = await api.get("/contacts/", { params: { searchParam: number, pageNumber: "1" }, }); const { data: data0 } = await api.get("/contacts/", { params: { searchParam: number, pageNumber: "1" }, });
@ -120,14 +141,14 @@ const Ticket = () => {
console.log('-----> data: ', data0.contacts[0].id) console.log('-----> data: ', data0.contacts[0].id)
contactId = data0.contacts[0].id contactId = data0.contacts[0].id
} }
else { else {
const values = { const values = {
name: number, name: number,
number: number, number: number,
}; };
const { data: data1 } = await api.post("/contacts", values); const { data: data1 } = await api.post("/contacts", values);
contactId = data1.id contactId = data1.id
@ -159,10 +180,10 @@ const Ticket = () => {
return () => clearTimeout(delayDebounceFn); return () => clearTimeout(delayDebounceFn);
}, [ticketId, history, user.id]); }, [ticketId, history, user.id]);
useEffect(() => { useEffect(() => {
const regex = /^[0-9\b]+$/; // Regular expression to match only numbers const regex = /^[0-9\b]+$/; // Regular expression to match only numbers
if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 ) return if (ticketId && !ticketId.match(regex) || ticketId && ticketId.length > 9 || !ticketId) return
const socket = openSocket(process.env.REACT_APP_BACKEND_URL); const socket = openSocket(process.env.REACT_APP_BACKEND_URL);

View File

@ -37,6 +37,8 @@ const Routes = () => {
<Route exact path="/tickets/:ticketId?" component={Tickets} isPrivate /> <Route exact path="/tickets/:ticketId?" component={Tickets} isPrivate />
<Route exact path="/tickets/https://wa.me/:ticketId?" component={WhatsLink} isPrivate /> <Route exact path="/tickets/https://wa.me/:ticketId?" component={WhatsLink} isPrivate />
<Route exact path="/tickets/https://web.whatsapp.com/send/:ticketId?" component={WhatsLink} isPrivate />
<Route exact path="/connections" component={Connections} isPrivate /> <Route exact path="/connections" component={Connections} isPrivate />