GithubHelp home page GithubHelp logo

salman0ansari / whatsapp-api-nodejs Goto Github PK

View Code? Open in Web Editor NEW
1.2K 52.0 587.0 1.07 MB

RESTful WhatsApp API with Multiple Device Support

License: GNU General Public License v3.0

JavaScript 98.73% EJS 0.85% Procfile 0.03% Shell 0.12% Dockerfile 0.27%
baileys-rest baileys whatsapp whatsapp-web whatsapp-api whatsapp-bot whatsapp-rest nodejs nodejs-wrapper nodejs-bot

whatsapp-api-nodejs's Introduction

whatsapp-api-nodejs's People

Contributors

adarsh-chakraborty avatar ak4zh avatar arnal1 avatar dependabot[bot] avatar devalexanderdaza avatar dv336699 avatar italodea avatar luispimenta avatar luizeof avatar patrickcmartins avatar pauloanalista avatar raphaelvserafim avatar robsonwr avatar ryanachdiadsyah avatar salman0ansari avatar shiro2477 avatar susmitbhamare avatar torvalds avatar useems avatar vinibgoulart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whatsapp-api-nodejs's Issues

When should I use the "restore" endpoint?

Exactly when should I use the "restore" endpoint?

My question is if I should make a call to it varies times a day or just when I'm going to restart the API?

The API is "active" on the cell phone and when an internet outage occurs, the connection returns automatically, the same thing that doesn't happen when you don't call "restore" all the time.

I'm afraid of overloading WhatsApp if I keep making multiple calls a day, for example.

How to update authentication keys after sending and receiving messages?

Hey!
I did some analysis and noticed that the session authentication keys, which are saved in JSON in the "Instances" folder, are updated when the qr-code is read.

However, the official Baileys documentation says: "When a message is received/sent from Session Authentication, the authentication keys will be included. Whenever this happens you should save as Not doing this will prevent your messages from reaching the recipient and other key differences".

Saving & Restoring Sessions

I identified that WhatsApp is "stuck" after sending a message with the cell phone offline, and after that I can no longer connect to the API, I believe it is due to this problem with authentication keys.

Can this be implemented in the API or how can I make this modification?

automatic disconnected phone

automatic disconnected phone 📱 after few hours instance automatic expired
please sir give me a solution it is very urgent!!!!!!!!!!!!

button send error

C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:190
onErr = ({ reason, status }) => reject(new Constants_1.BaileysError(reason, { status }));
^

BaileysError: Not expecting a response
at onErr (C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:190:56)
at C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:185:82
at Timeout. (C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:272:21)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
status: 422,
context: { status: 422 }
}

[MD] getWhatsAppId() condition need to change

In getWhatsAppId(), I think it is not necessary that group id contain "-" always because when I create a new group today for testing, it has this id without "-".

[email protected]

in such case the following method will not work

 getWhatsAppId(id) {
        return id?.includes('-') ? `${id}@g.us` : `${id}@s.whatsapp.net`
    }

instead we can replace it with the following code

 getWhatsAppId(id) {
        return id?.includes('@g.us') ? `${id}` : `${id}@s.whatsapp.net`;
    }

Correct me, If I am wrong

Instance end point throw Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

First time when instance end point gets call, it work as expected but when I call instance end point again to check user's login status, it throw following error

(node:18) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

at ServerResponse.setHeader (_http_outgoing.js:561:11)

at ServerResponse.header (/app/node_modules/express/lib/response.js:771:10)

at ServerResponse.send (/app/node_modules/express/lib/response.js:170:12)

at ServerResponse.json (/app/node_modules/express/lib/response.js:267:15)

at /app/Routes/Instance.js:63:9

at processTicksAndRejections (internal/process/task_queues.js:95:5)

(node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 10)

I think this error throw because loginverify.js file return response if phone isn't connected and instance end point also return response.

we need to specify the return keyword like this in loginverify.js file to fix the issue

return res.status(401).send(({ error: true, message: "phone isn't connected" }))
return res.status(403).send(({ error: true, message: 'no key query was present' }))

Please correct me, if I am wrong.

Close after scan QR

Hi @salman0ansari thank you for the code, I got error after scan the QR code.

0.Base.js:126 encKey: this.authInfo.encKey.toString('base64'), TypeError: Cannot read property 'toString' of undefined

What I do currently comment out

// client.on('qr',async () => {
// const authInfo = await client.base64EncodedAuthInfo()
// fs.writeFileSync('./auth_info.json', JSON.stringify(authInfo, null, '\t'))
// })

and it works. Do you know what causing this?

Error on delete endpoint

When delete endpoint called, it throw following error when

/app/node_modules/@adiwajshing/baileys/lib/WAConnection/3.Connect.js:79
const rejectAllOnWSClose = ({ reason }) => rejectAll(new Error(reason));
Error: intentional
at WAConnection.rejectAllOnWSClose (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/3.Connect.js:79:62)
at WAConnection.emit (node:events:402:35)
at WAConnection.emit (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/4.Events.js:664:41)
at WAConnection.endConnection (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/0.Base.js:417:14)
at WAConnection.closeInternal (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/0.Base.js:400:14)
at WAConnection.close (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/0.Base.js:392:14)
at WAConnection.logout (/app/node_modules/@adiwajshing/baileys/lib/WAConnection/0.Base.js:388:14)
at WhatsAppInstance.logout (/app/Objects/instanceClass.js:286:35)
at /app/Routes/Instance.js:105:20
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
Node.js v17.2.0

Delete endpoint try to logout even whatsapp instance is not logged in

we can fix this issue by following code in delete end point, similar fix need to add in logout endpoint

await instance.conn?.logout();

Cannot Create a Group

This is a response what i got

{
    "error": true,
    "code": 500,
    "message": "TypeError: Cannot read properties of undefined (reading 'map')"
}

error when running npm install.

error when running npm install.

Note: I use Windows

`λ npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/sharp
npm ERR! sharp@"^0.30.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer sharp@"^0.29.3" from @adiwajshing/[email protected]
npm ERR! node_modules/@adiwajshing/baileys
npm ERR! @adiwajshing/baileys@"^4.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Robinho\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Robinho\AppData\Local\npm-cache_logs\2022-03-19T23_13_43_591Z-debug-0.log
`

stop in Docker

container stops after some time there is an error too many requests
Jepretan Layar 2022-02-27 pukul 15 11 11

Webhook receive contact card

Hi,

  1. I did the tests and the webhook cannot capture the return when a contact card is sent.
  2. I did a payment request test by whatsapp also did not receive it on the webhook.
  3. Does Baileys allow checking as seen whenever he uploads to the webhook?
    Thanks!

Media Filename Problem

File name is not on the file that is being sent. 'fileName': 'file'

    files= {
    'file': ('fileName.PDF', open(document, 'rb'), 'application/pdf')
    }

155335771-03b8b1bd-4192-4f25-95ab-ede32c1ea541

Write tests

It will be better if we write tests for this project.
it will help in future maintainability and help find bugs easily

getting error when send images

(node:7660) [DEP0128] DeprecationWarning: Invalid 'main' field in 'C:\Users\sbra
n\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-main\node_module
s\swagger-ui-express\package.json' of './lib/index.js'. Please either fix that o
r report it to the module author
(Use node --trace-deprecation ... to show where the warning was created)
�: Listening on PORT => http://localhost:3333
C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nodejs-mai
n\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:190
onErr = ({ reason, status }) => reject(new Constants_1.BaileysEr
ror(reason, { status }));
^

BaileysError: Not expecting a response
at onErr (C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-
api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:190
:56)
at C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-main\whatsapp-api-nod
ejs-main\node_modules@adiwajshing\baileys\lib\WAConnection\0.Base.js:185:82
at Timeout. (C:\Users\sbran\OneDrive\Desktop\whatsapp-api-nodejs-
main\whatsapp-api-nodejs-main\node_modules@adiwajshing\baileys\lib\WAConnection
\0.Base.js:272:21)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
status: 422,
context: { status: 422 }
}

npm run start error

hi i have already jnstalled evrrything but it shows me this error aftr running npm run start

''0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'start' ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 3ms
4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 4ms
5 timing config:load:builtin Completed in 4ms
6 timing config:load:cli Completed in 3ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/home/vaccarieli/whatsapp-api-nodejs/.npmrc Completed in 1ms
9 timing config:load:project Completed in 2ms
10 timing config:load:file:/home/vaccarieli/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 2ms
18 timing config:load Completed in 17ms
19 verbose npm-session 6e65e15b4cb34ab5
20 timing npm:load Completed in 35ms
21 timing command:run-script Completed in 383ms
22 verbose stack Error: command failed
22 verbose stack at ChildProcess. (/usr/share/nodejs/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack at ChildProcess.emit (events.js:314:20)
22 verbose stack at maybeClose (internal/child_process.js:1022:16)
22 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
23 verbose pkgid [email protected]
24 verbose cwd /home/vaccarieli/whatsapp-api-nodejs
25 verbose Linux 5.13.0-35-generic
26 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "start"
27 verbose node v12.22.5
28 verbose npm v7.5.2
29 error code 1
30 error path /home/vaccarieli/whatsapp-api-nodejs
31 error command failed
32 error command sh -c node src/server.js
33 verbose exit 1'''

Postman or Insomnia Documentation

is anyone here interested to get some api doc from postman or insomnia ?
if you interested, i'll make a full of documentation from this repo.
Please replay if anyone interested :)

Error kills server after reading qr code.

Hello, I'm getting this error right after reading the qr-code, the server stops after the error. Can you help me?

{"level":30,"time":1647628378460,"pid":500079,"hostname":"vmi625985.contaboserver.net","pid":500079, "hostname":"vmi625985.contaboserver.net","class":"baileys","histNotification":{"fileSha256":"fPGw0o4 U6nDbCiyeLkOpmLkgvmMe/2nZ6F+7B3uUSRk=","fileLength":"64115","mediaKey":"YCSpqn+Zo+V4mS1kKreaJfZhblXX Nw+CBYIdbqBXPiA=","fileEncSha256":"OX9rLhvKJQYkXOksk1zqHjN9h3zFGxw4GJ322XzNuz0=","directPath":"/v/t6 2.31111-24/11751996_287822846763677_5514845287318593325_n.enc?ccb=11-4&oh=01_AVw52QFL9MxOpYn5hN6wThY OqQv4FZo1PL0UVKGUAlATTQ&oe=6259BB33","syncType":"INITIAL_STATUS_V3"},"id":"B67406A3DADE68777528E1A52 DD409AA","msg":"got history notification"} {"level":50,"time":1647628378538,"pid":500079,"hostname":"vmi625985.contaboserver.net","err":{"type" :"Error","message":"Connection Closed","stack":"Error: Connection Closed\n at sendRawMessage (/ho me/cp9379ba026/web/public/md_baileys/teste/novo/baileys_api_md/node_modules/@adiwajshing/baileys/lib /Socket/socket.js:63:19)\n at sendNode (/home/cp9379ba026/web/public/md_baileys/teste/novo/bailey s_api_md/node_modules/@adiwajshing/baileys/lib/Socket/socket.js:71:16)\n at processMessage (/home /cp9379ba026/web/public/md_baileys/teste/novo/baileys_api_md/node_modules/@adiwajshing/baileys/lib/S ocket/messages-recv.js:123:27)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async EventEmitter.<anonymous> (/home/cp9379ba026/ web/public/md_baileys/teste/novo/baileys_api_md/node_modules/@adiwajshing/baileys/lib/Socket/message s-recv.js:452:17)","data":null,"isBoom":true,"isServer":false,"output":{"statusCode":428,"payload":{ "statusCode":428,"error":"Precondition Required","message":"Connection Closed"},"headers":{}}},"msg" :"Connection Closed"} {"level":30,"time":1647628378541,"pid":500079,"hostname":"vmi625985.contaboserver.net","pid":500079, "hostname":"vmi625985.contaboserver.net","class":"baileys","msg":"connected to WA Web"} {"level":30,"time":1647628378639,"pid":500079,"hostname":"vmi625985.contaboserver.net","pid":500079, "hostname":"vmi625985.contaboserver.net","class":"baileys","msg":"handshake complete"} {"level":30,"time":1647628378639,"pid":500079,"hostname":"vmi625985.contaboserver.net","pid":500079, "hostname":"vmi625985.contaboserver.net","class":"baileys","msg":"logging in..."} {"level":30,"time":1647628378644,"pid":500079,"hostname":"vmi625985.contaboserver.net","msg":"Server closed"}

[MD] Link Preview not generating

In SendMessage endpoint, if the message parameter contains a link, it is not generating link preview in the older version it was generating automatically. I think there are some changes in Baily v4.0

[MD] Send Buttons

Is there any way to send buttons using the MD version?
I looked in the codes, but I didn't find anything about

Please Fix You Postman collection

What i found and you should fix:
Please Change key (ID) to Body RAW JSON not in PARAMS. it cause an errors if i use it on PARAMS

Form This :
image

To This :
image

Route Affected is :
image

this.isZero()

If I am using WhatsApp business on iPhone its gives an error from the second message the first message works fine but the second message gives an error like this.isZero() is not a function.

Its works fine with WhatsApp business android but not with iPhone (tried on iPhone 6s and iPhone 12)

UnhandledPromiseRejectionWarning: Error on Init API

When I invoke init api, getting following error message on console screen

(node:5880) UnhandledPromiseRejectionWarning: Error
at new RequestError (C:\Users\whatsapp-api-nodejs-main\node_modules\pusher\lib\errors.js:13:16)
at C:\Users\whatsapp-api-nodejs-main\node_modules\pusher\lib\requests.js:61:17
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:5880) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5880) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

"TypeError: Cannot use 'in' operator to search for 'stream' in undefined"

Hey @salman0ansari thanks for your support, I have this issue now, with sending docs/audio, I am already able to send messages, images, videos, and everything else, except for this 2 types.

`curl --location --request POST 'localhost:3333/message/audio?key=myKey --form 'file=@"audio.ogg"' --form 'id=9748745287'`

`curl --location --request POST 'localhost:3333/message/audio?key=myKey --form 'file=@"audio.mp3"' --form 'id=9748745287'`

`curl --location --request POST 'localhost:3333/message/doc?key=myKey --form 'file=@"words.docx"' --form 'id=9748745287'`

{"error":true,"code":500,"message":"TypeError: Cannot use 'in' operator to search for 'stream' in undefined"}

[MD] Bug Buttons

There is a bug when sending buttons
The buttons are sent normally, but in the Client, it shows that the buttons were sent to the client itself, that is, as if I were sending a message to myself.
However, the recipient receives the buttons normally.

how to handle Too Many Requests(429) error?

User gets QR code by following API

http://localhost:3333/qrcode?key=f7ecc0cf-38e1-4138-a90c-d5ee2d97d809

But when user does not scan qr code for 2 minutes somewhere, it throw following error

Error: Unexpected status in 'admin': Too Many Requests(429)

WARN [2022-02-08 15:03:06.239 +0000] (51536): error in QR gen
    class: "Baileys"
    error: {
      "name": "BaileysError",
      "status": 429,
      "context": {
        "query": [
          "admin",
          "Conn",
          "reref"
        ],
        "message": "Too Many Requests",
        "status": 429
      }
    }

is it possible to handle this error?

[MD] WebHook

Hi sorry for asking this
But is there a prediction of when the WebHook function will be available for the MD version?

Phone is not connected after linking device

Hi @salman0ansari I am getting this response when I try to send a message, {"error":true,"message":"phone isn\'t connected"}'

I already linked it to my WS, does the server saves the session by itself? after linking IF so and i have multiple devices linked to the server how can I select which one is the one that i am going to be sending messages with? anyways this is the url I am using:

with country code
http://192.168.1.189:3333/message/text?key=790235bd-dc68-4fbe-9605-a9acd674af5c&id=+50760157876&message=Hello World

without country code
http://192.168.1.189:3333/message/text?key=790235bd-dc68-4fbe-9605-a9acd674af5c&id=60157876&message=Hello World

Tetste out the instance and shows no user = {}

{"error":false,"message":"Instance fetched successfully","instance_data":{"instance_key":"8755e41f-01b3-4910-a45c-d7e39af49a98","user":{}}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.