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.14k stars 601 forks source link

SocketClient should have the same API as Client #1778

Closed smashah closed 3 years ago

smashah commented 3 years ago

I want:

await client.sendText(....

//and 

client.onAnyMessage

not

await client.ask("sendText",....

//and

await client.listner("onAnyMessage,....
smashah commented 3 years ago

@github-actions run

⚑ Release! ⚑ ```js (async () => { function exec(cmd) { console.log(execSync(cmd).toString()); } // Config const gitUserEmail = "github-actions[bot]@users.noreply.github.com"; const gitUserName = "github-actions[bot]"; exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`); exec(`git config --global user.email "${gitUserEmail}"`); exec(`git config --global user.name "${gitUserName}"`); exec(`npm i -D`); exec(`npm run release-ci minor`); //comment on the issue var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString(); await postComment(result); //create changelog image exec(`npm run release-image`); exec(`git commit -a -m 'updated release-image'`); exec(`git push --force`); })(); ```
smashah commented 3 years ago

Changelog

πŸš€ Release 4.5.0 (2021-06-13)

smashah commented 3 years ago
  1. Run the EASY API
> npx @open-wa/wa-automate --socket -p 8002 -k api_key

Note: --socket flag is required!!

  1. Typescript code:
import {
  Client,
  SocketClient,
} from "@open-wa/wa-automate";

const NUMBER = 'TEST_PHONE_NUMBER@c.us'

const start = async () => {
  const client = new SocketClient(
    "http://localhost:8002",
    "api_key"
  ) as SocketClient & Client;

  client.socket.on("connect", async () => {
    client.onAnyMessage((message) => {
      console.log("onAnyMessage", message.id, message.body);
    });

    const socketId = client.socket.id;
    console.log("πŸš€ ~ file: client.ts ~ line 144 ~ start ~ socketId", socketId);

    console.log(
      "Connected!",
      await client.sendText(NUMBER, "this is a text")
    );
    client
      .sendAudio(
        NUMBER,
        "https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3"
      )
      .then((audoMessageId) => console.log(audoMessageId));

    console.log(
      await client.sendFile(
        NUMBER,
        "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4",
        "test.mp4",
        "hellow"
      )
    );

  });
};

start();
smashah commented 2 years ago

Completed in v2.1.0 of the socket client project