open-wa / wa-automate-nodejs

πŸ’¬ πŸ€– The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.15k stars 600 forks source link

Incorrect typings for client.getUnreadMessages() #2417

Closed bauti-defi closed 2 years ago

bauti-defi commented 2 years ago

Are you using the latest version of the library?

What type of session are you experiencing this issue on?

Legacy (Normal)

What type of host account are you experiencing this issue on?

Business account

Mode

My own code

Current Behavior

client.getUnreadMessages() returns a Message[] but it actually doesn't. It actually seems to return a Chat[] and each chat has a Message[] called messages. messages are all "unread"

Expected Behavior

client.getUnreadMessages() should return a Chat[] type.

Steps To Reproduce

const handleUnreadMessages = async (bot_id: string, client: Client) => {
  const unReadChats: Message[] = await client.getUnreadMessages(false, false, true);

  for (var chat of unReadChats) {
    //@ts-ignore
    const markAsSeen  = await client.sendSeen(chat.id);

    if (!chat["isGroup"]) {
      //@ts-ignore
      await client.sendText(chat.id, "Hola, volvi! πŸ€–");

      for (var message of chat["messages"]) {
        await MessageRelayer(bot_id, client)(message);
      }
    }
  }
};

create() code

wa.create({
  sessionId: "beto-wapp-server-v4",
  disableSpins: true,
  headless: true,
  useStealth: true,
  sessionDataPath: "./data/tokens",
  authTimeout: 0,
  multiDevice: false, // process.env.DEV_MODE ? false : true
  licenseKey: process.env.DEV_MODE ? undefined : process.env.OPEN_WA_KEY,
  cachedPatch: true,
  restartOnCrash: start,
})
  .then(start)
  .catch((error) => {
    if (!error.silent) {
      console.log("Error:", error.message);
    }
  });

DEBUG INFO

- Starting
- Version: 4.28.13
- Initializing WA
- Launching Browser
Subscribed to ALL channels
- Setting Up Page
- Loading session data
- Found session data file: /home/bautista/Desktop/Beto/Beto-WAPP/data/tokens/beto-wapp-server-v4.data.json
- Existing session data detected. Injecting...
- Existing session data injected
- Navigating to WA
- Page loaded in 737ms: 200
- Browser Launched
- Debug info: {
  "WA_VERSION": "2.2149.4",
  "PAGE_UA": "WhatsApp/2.2147.16 Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
  "WA_AUTOMATE_VERSION": "4.28.13",
  "BROWSER_VERSION": "HeadlessChrome/93.0.4577.0",
  "OS": "Linux 5.11",
  "START_TS": 1642087626979
}
- Use this easy pre-filled link to report an issue: https://github.com/open-wa/wa-automate-nodejs/issues/new?template=bug_report.yaml&d_info=%7B%0A%20%20%22WA_VERSION%22:%20%222.2149.4%22,%0A%20%20%22WA_AUTOMATE_VERSION%22:%20%224.28.13%22,%0A%20%20%22BROWSER_VERSION%22:%20%22HeadlessChrome/93.0.4577.0%22,%0A%20%20%22START_TS%22:%201642087626979,%0A%20%20%22LATEST_VERSION%22:%20true,%0A%20%20%22CLI%22:%20false%0A%7D&enviro=-%20OS:%20Linux%205.11%0A-%20Node:%2017.3.1%0A-%20npm:%208.3.0&labels=Legacy
- Injecting api
- WAPI injected
- Authenticating
- Authenticated
- Reinjecting api
- WAPI Reinjected
- Checking if session is valid
- Searching for cached patch
- Found cached patch
- Cached patch loaded
- Downloading cached patches from https://cdn.openwa.dev/patches.json
- Client is ready
- Installing patches
- Patches Installed: CACHED-46c7b
- Client loaded for normal account with 944 contacts, 845 chats & 878 messages in 5.628s
- Finalizing web session...
- Finalizing client...
- Downloaded patches in 0.457s
- Saving patches to current working directory
- Saved patches to current working directory
- πŸš€ @OPEN-WA ready for account: 3298

Environment

- OS: ubuntu 20.04
- Node: 8.3.0
- npm: 17.3.1

Screenshots/Logs

No response

Anything else?

No response

bauti-defi commented 2 years ago

Any news on this?

smashah commented 2 years ago

fixed in https://github.com/open-wa/wa-automate-nodejs/releases/tag/4.31.1 thanks