salman0ansari / whatsapp-api-nodejs Goto Github PK
View Code? Open in Web Editor NEWRESTful WhatsApp API with Multiple Device Support
License: GNU General Public License v3.0
RESTful WhatsApp API with Multiple Device Support
License: GNU General Public License v3.0
automatic disconnected phone 📱 after few hours instance automatic expired
please sir give me a solution it is very urgent!!!!!!!!!!!!
I want to send read receipt to sender. In another word blue tick on message. Please help
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 :)
http://localhost:3344/message/image?key=4b4c3f84-0509-4220-bgfhghghghxxxxx
it is working with post man . when i am useing php then showing this error
{
"error": true,
"code": 500,
"message": "TypeError: Cannot read property 'includes' of undefined"
}
node v14.19.0
npm 6.14.16
Hi sorry for asking this
But is there a prediction of when the WebHook function will be available for the MD version?
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();
Hi,
Is tested on shared hosting ?
add button sending with image
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)
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)
(Usenode --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.
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?
Can we read webhook url from env file instead of config file, it helps user to specify the webhook at runtime.
(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 }
}
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'''
i needed image with template button
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.
This is a response what i got
{
"error": true,
"code": 500,
"message": "TypeError: Cannot read properties of undefined (reading 'map')"
}
It will be better if we write tests for this project.
it will help in future maintainability and help find bugs easily
Can you please add API to fetch all groups meta data?
Like group Id, group name, profile picture, list of members in the group, admin information etc.
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.
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
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
`
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 }
}
Why i can't scan QR Code from WA non beta?
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":{}}}
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".
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?
how to send image with url
like i have image on server https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg
how i can send
Will there be a modification for WhatsApp-MD? (https://github.com/adiwajshing/Baileys/tree/multi-device)
After official whatsapp update, when reading QRCode does not work
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?
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 "-".
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
Im new with this,
anyone have full documentation for install on my vps ubuntu
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"}
Is there any way to set up webhook for like when new message arrive?
If You Have any idea, to add new feature on this API. Leave a comment below.
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.
Is there any way to send buttons using the MD version?
I looked in the codes, but I didn't find anything about
Hello Salman,
I did the test using a whatsapp MD Normal and whatsapp MD Business both after reading the QRCode and authenticating the connection with whatsapp is closed and disappears from the list of connected devices.
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"}
Following item need to remove from .dockerignore file, else it won't copy and throw error
.env
/Instances/
correct me if I am wrong
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.