Corrreção para abrir links de whatsapp pelo omnihit
parent
307ceca26e
commit
9f2d574251
|
@ -25,6 +25,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
const { ticketId } = req.params;
|
||||
const { pageNumber } = req.query as IndexQuery;
|
||||
|
||||
// console.log(':::::::::::::> TICKET ID: ', ticketId)
|
||||
|
||||
const { count, messages, ticket, hasMore } = await ListMessagesService({
|
||||
pageNumber,
|
||||
ticketId
|
||||
|
|
|
@ -128,8 +128,8 @@ export const store = 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 { statusChatEnd, count, hasMore } = await ListStatusChatEndService({ searchParam: "", pageNumber: "1" });
|
||||
|
|
|
@ -39,7 +39,7 @@ export const initIO = (httpServer: Server): SocketIO => {
|
|||
io = new SocketIO(httpServer, {
|
||||
cors: {
|
||||
origin: process.env.FRONTEND_URL
|
||||
},
|
||||
},
|
||||
maxHttpBufferSize: 1e8
|
||||
});
|
||||
|
||||
|
@ -59,18 +59,18 @@ export const initIO = (httpServer: Server): SocketIO => {
|
|||
});
|
||||
|
||||
socket.on("message_from_client", () => {
|
||||
|
||||
|
||||
socket.emit('message_from_server', 'Sent an event from the server!');
|
||||
})
|
||||
|
||||
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);
|
||||
|
||||
|
@ -220,11 +220,11 @@ export const initIO = (httpServer: Server): SocketIO => {
|
|||
});
|
||||
|
||||
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
|
||||
if (ticketId && !ticketId.match(regex)) return
|
||||
|
||||
if (ticketId && !ticketId.match(regex) || !ticketId) return
|
||||
|
||||
socket.join(ticketId);
|
||||
});
|
||||
|
||||
|
@ -247,18 +247,18 @@ export const initIO = (httpServer: Server): SocketIO => {
|
|||
|
||||
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==2 && !([...rooms][1].startsWith('session_'))) return
|
||||
if (rooms && rooms.size == 1) 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) {
|
||||
|
||||
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 &&
|
||||
[...rooms][1].startsWith('session_') &&
|
||||
|
|
|
@ -18,11 +18,9 @@ interface Response {
|
|||
const ListMessagesService = async ({
|
||||
pageNumber = "1",
|
||||
ticketId
|
||||
}: Request): Promise<Response> => {
|
||||
|
||||
console.log('>>>>>>>>>>>>>>>>>>>> ticketId: ', ticketId)
|
||||
|
||||
if (ticketId && ticketId.length > 9) {
|
||||
}: Request): Promise<Response> => {
|
||||
|
||||
if ((ticketId && ticketId.length > 9) || !ticketId || (ticketId && ticketId === 'undefined')) {
|
||||
return {
|
||||
messages: [],
|
||||
ticket: new Ticket,
|
||||
|
|
|
@ -70,13 +70,9 @@ const CreateTicketService = async ({
|
|||
|
||||
if (!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)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ const FindOrCreateTicketService = async (
|
|||
groupContact?: Contact
|
||||
): Promise<Ticket> => {
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
let ticket = await Ticket.findOne({
|
||||
where: {
|
||||
status: {
|
||||
|
|
|
@ -115,9 +115,9 @@ const Ticket = () => {
|
|||
}, [ticketId, history]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -183,17 +183,14 @@ const TicketsList = (props) => {
|
|||
const [ticketsList, dispatch] = useReducer(reducer, []);
|
||||
const { user } = useContext(AuthContext);
|
||||
|
||||
const { searchTicket } = useContext(SearchTicketContext)
|
||||
|
||||
const { searchTicket } = useContext(SearchTicketContext)
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
dispatch({ type: "RESET" });
|
||||
setPageNumber(1);
|
||||
|
||||
}, [status, searchParam, showAll, selectedQueueIds, searchTicket]);
|
||||
|
||||
|
||||
}, [status, searchParam, showAll, selectedQueueIds, searchTicket]);
|
||||
|
||||
const { tickets, hasMore, loading } = useTickets({
|
||||
pageNumber,
|
||||
|
|
|
@ -94,25 +94,46 @@ const Ticket = () => {
|
|||
useEffect(() => {
|
||||
setLoading(true);
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
const fetchTicket = async () => {
|
||||
|
||||
console.log('+++++++++++ ticketId: ', ticketId)
|
||||
const fetchTicket = async () => {
|
||||
|
||||
try {
|
||||
|
||||
let number
|
||||
let msg
|
||||
let msg = ''
|
||||
let contactId
|
||||
let link
|
||||
|
||||
console.log('ticketId: ', ticketId)
|
||||
console.log('window.location.href): ', window.location.href)
|
||||
link = window.location.href
|
||||
|
||||
const link = window.location.href.split('/https://wa.me/')
|
||||
if (link.includes('/https://wa.me/')) {
|
||||
|
||||
number = link[1].split('?text=')[0]
|
||||
msg = link[1].split('?text=')[1] || ''
|
||||
link = window.location.href.split('/https://wa.me/')
|
||||
|
||||
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" }, });
|
||||
|
||||
|
@ -120,14 +141,14 @@ const Ticket = () => {
|
|||
console.log('-----> data: ', data0.contacts[0].id)
|
||||
contactId = data0.contacts[0].id
|
||||
}
|
||||
else {
|
||||
else {
|
||||
|
||||
const values = {
|
||||
name: number,
|
||||
number: number,
|
||||
};
|
||||
|
||||
const { data: data1 } = await api.post("/contacts", values);
|
||||
const { data: data1 } = await api.post("/contacts", values);
|
||||
|
||||
contactId = data1.id
|
||||
|
||||
|
@ -159,10 +180,10 @@ const Ticket = () => {
|
|||
return () => clearTimeout(delayDebounceFn);
|
||||
}, [ticketId, history, user.id]);
|
||||
|
||||
useEffect(() => {
|
||||
useEffect(() => {
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ const Routes = () => {
|
|||
<Route exact path="/tickets/:ticketId?" component={Tickets} 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 />
|
||||
|
||||
|
|
Loading…
Reference in New Issue