fix: bug id and body undefined from webhook
							parent
							
								
									ec6e84f567
								
							
						
					
					
						commit
						c5c5ddb5a4
					
				| 
						 | 
				
			
			@ -265,6 +265,10 @@ export const weebhook = async (
 | 
			
		|||
      });
 | 
			
		||||
 | 
			
		||||
      if (type == "text") {
 | 
			
		||||
        if (!message?.text?.body) {
 | 
			
		||||
          return res.status(400).json({ error: "body not found" });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        type = "chat";
 | 
			
		||||
        msg = {
 | 
			
		||||
          ...msg,
 | 
			
		||||
| 
						 | 
				
			
			@ -272,6 +276,10 @@ export const weebhook = async (
 | 
			
		|||
          type
 | 
			
		||||
        };
 | 
			
		||||
      } else {
 | 
			
		||||
        if (!message[message?.type]?.id) {
 | 
			
		||||
          return res.status(400).json({ error: "id not found" });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const mediaId = message[message.type].id;
 | 
			
		||||
        const mimetype = message[message.type].mime_type;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,7 +98,7 @@ import FindOrCreateTicketServiceBot from "../TicketServices/FindOrCreateTicketSe
 | 
			
		|||
import ShowTicketService from "../TicketServices/ShowTicketService";
 | 
			
		||||
import ShowQueuesByUser from "../UserServices/ShowQueuesByUser";
 | 
			
		||||
import ListWhatsappQueuesByUserQueue from "../UserServices/ListWhatsappQueuesByUserQueue";
 | 
			
		||||
import CreateContactService from "../ContactServices/CreateContactService"
 | 
			
		||||
import CreateContactService from "../ContactServices/CreateContactService";
 | 
			
		||||
 | 
			
		||||
var lst: any[] = getWhatsappIds();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -318,13 +318,14 @@ const verifyQueue = async (
 | 
			
		|||
    selectedOption = 1;
 | 
			
		||||
    choosenQueue = queues[+selectedOption - 1];
 | 
			
		||||
  } else {
 | 
			
		||||
    selectedOption = msg.body;
 | 
			
		||||
    selectedOption = msg?.body;
 | 
			
		||||
 | 
			
		||||
    //////////////// EXTRAIR APENAS O NÚMERO ///////////////////
 | 
			
		||||
    selectedOption = selectedOption.replace(/[^1-9]/g, "");
 | 
			
		||||
    ///////////////////////////////////
 | 
			
		||||
 | 
			
		||||
    choosenQueue = queues[+selectedOption - 1];
 | 
			
		||||
    if (selectedOption && selectedOption.trim().length > 0) {
 | 
			
		||||
      //////////////// EXTRAIR APENAS O NÚMERO ///////////////////
 | 
			
		||||
      selectedOption = selectedOption.replace(/[^1-9]/g, "");
 | 
			
		||||
      ///////////////////////////////////
 | 
			
		||||
      choosenQueue = queues[+selectedOption - 1];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (choosenQueue) {
 | 
			
		||||
| 
						 | 
				
			
			@ -610,7 +611,7 @@ const handleMessage = async (
 | 
			
		|||
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
  } 
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!isValidMsg(msg)) {
 | 
			
		||||
    return;
 | 
			
		||||
| 
						 | 
				
			
			@ -780,33 +781,33 @@ const handleMessage = async (
 | 
			
		|||
      await verifyQueue(wbot, msg, ticket, contact);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      if (msg.type === "vcard") {
 | 
			
		||||
        try {
 | 
			
		||||
          const array = msg.body.split("\n");
 | 
			
		||||
          const obj = [];
 | 
			
		||||
          let contact = "";
 | 
			
		||||
          for (let index = 0; index < array.length; index++) {
 | 
			
		||||
            const v = array[index];
 | 
			
		||||
            const values = v.split(":");
 | 
			
		||||
            for (let ind = 0; ind < values.length; ind++) {
 | 
			
		||||
              if (values[ind].indexOf("+") !== -1) {
 | 
			
		||||
                obj.push({ number: values[ind] });
 | 
			
		||||
              }
 | 
			
		||||
              if (values[ind].indexOf("FN") !== -1) {
 | 
			
		||||
                contact = values[ind + 1];
 | 
			
		||||
              }
 | 
			
		||||
    if (msg.type === "vcard") {
 | 
			
		||||
      try {
 | 
			
		||||
        const array = msg.body.split("\n");
 | 
			
		||||
        const obj = [];
 | 
			
		||||
        let contact = "";
 | 
			
		||||
        for (let index = 0; index < array.length; index++) {
 | 
			
		||||
          const v = array[index];
 | 
			
		||||
          const values = v.split(":");
 | 
			
		||||
          for (let ind = 0; ind < values.length; ind++) {
 | 
			
		||||
            if (values[ind].indexOf("+") !== -1) {
 | 
			
		||||
              obj.push({ number: values[ind] });
 | 
			
		||||
            }
 | 
			
		||||
            if (values[ind].indexOf("FN") !== -1) {
 | 
			
		||||
              contact = values[ind + 1];
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          for await (const ob of obj) {
 | 
			
		||||
            const cont = await CreateContactService({
 | 
			
		||||
              name: contact,
 | 
			
		||||
              number: ob.number.replace(/\D/g, "")
 | 
			
		||||
            });
 | 
			
		||||
          }
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
          console.log(error);
 | 
			
		||||
        }
 | 
			
		||||
        for await (const ob of obj) {
 | 
			
		||||
          const cont = await CreateContactService({
 | 
			
		||||
            name: contact,
 | 
			
		||||
            number: ob.number.replace(/\D/g, "")
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.log(error);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const botInfo = await BotIsOnQueue("botqueue");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -820,7 +821,7 @@ const handleMessage = async (
 | 
			
		|||
        ticket.status == "pending" ||
 | 
			
		||||
        ticket.status == "queueChoice")
 | 
			
		||||
    ) {
 | 
			
		||||
      const filteredUsers = await findByContain("user:*", "name", msg?.body); 
 | 
			
		||||
      const filteredUsers = await findByContain("user:*", "name", msg?.body);
 | 
			
		||||
 | 
			
		||||
      if (filteredUsers && filteredUsers.length > 0) {
 | 
			
		||||
        if (botInfo.isOnQueue) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue