Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages stop being delivered after some time post-authorization, despite sendMessage returning success #3433

Open
2 tasks done
Timiks1 opened this issue Jan 6, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@Timiks1
Copy link

Timiks1 commented Jan 6, 2025

Is there an existing issue for this?

  • I have searched the existing issues.

Is this a problem caused by your code, or is it specifically because of the library?

  • I have double-checked my code carefully.

Describe the bug.

After successfully authorizing with whatsapp-web.js and sending messages, everything works fine for a certain period. However, after some time has passed (e.g., 20-30 minutes), messages stop being delivered. The sendMessage method still returns a response indicating successful delivery, but the messages are not received by the recipient.

Meanwhile, other requests, such as getChats, continue to work without issues. Resetting the session allows messages to be delivered again temporarily, but the problem eventually reoccurs.

Expected Behavior

Messages should continue to be delivered after authorization, regardless of the time elapsed since the session was initialized.

Steps to Reproduce the Bug or Issue

Steps to Reproduce:

Initialize a client with RemoteAuth, saving the session to S3.
Authorize successfully.
Send a message using client.sendMessage.
Wait for some time (approximately 20-30 minutes).
Attempt to send another message.

//Send message
import { initializeClient } from './initializeClient'
import { transformMessage } from './transformMessage'
import { UnreadMessage, WhatsAppPayload, WhatsAppResponse } from '../interfaces'

export async function sendMessage(payload: WhatsAppPayload): Promise<WhatsAppResponse> {
const { number, message, webhook_auth_key } = payload

const { client, connected, disconnect } = await initializeClient(webhook_auth_key)

const chatId = number!.includes('@c.us') ? number : ${number}@c.us
const send = await client.sendMessage(chatId!, message!)
await new Promise((resolve) => {
client.on('message_ack', (msg: any, ack: any) => {
if (msg.id._serialized === send.id._serialized) {
if (ack > 0) {
resolve()
}
}
})
})

const transformedMessage = transformMessage(send)

await disconnect()

return { data: transformedMessage, connected }
}

//initialize Client
import { Client, RemoteAuth } from 'whatsapp-web.js'
import { AwsS3Store } from 'wwebjs-aws-s3'
import {
S3Client,
PutObjectCommand,
HeadObjectCommand,
GetObjectCommand,
DeleteObjectCommand,
} from '@aws-sdk/client-s3'

export async function initializeClient(id: string): Promise<{
client: Client
connected: boolean
disconnect: () => Promise
}> {
const s3 = new S3Client({
region: 'my-region',
credentials: {
accessKeyId: 'my-key-id',
secretAccessKey: 'my-key',
},
})

const putObjectCommand = PutObjectCommand
const headObjectCommand = HeadObjectCommand
const getObjectCommand = GetObjectCommand
const deleteObjectCommand = DeleteObjectCommand
const store = new AwsS3Store({
bucketName: process.env.S3_BUCKET_NAME!,
remoteDataPath: 'path-to-my-sessions/',
s3Client: s3,
putObjectCommand,
headObjectCommand,
getObjectCommand,
deleteObjectCommand,
})

const client = new Client({
puppeteer: {
args: ['--no-sandbox'],
},
authStrategy: new RemoteAuth({
clientId: id,
store: store,
backupSyncIntervalMs: 600000,
}),
})

return new Promise((resolve) => {
client.on('ready', () => {
resolve({
client,
connected: true,
disconnect: async () => {
await client.destroy()
},
})
})

client.initialize()

})
}

WhatsApp Account Type

Standard

Browser Type

Chromium

Operation System Type

Mac

Phone OS Type

iOS 18.1.1

WhatsApp-Web.js Version

1.26.0

WhatsApp Web Version

2.3000.1019158277

Node.js Version

v18.20.5

Authentication Strategy

RemoteAuth

Additional Context

No response

@Timiks1 Timiks1 added the bug Something isn't working label Jan 6, 2025
@rodrigoslayertech
Copy link

rodrigoslayertech commented Jan 7, 2025

I can confirm this bug. Apparently it only affected new connections from my running app. I just don't know exactly when this started for new connections, but I believe it was about 2 months ago.

Possible duplicated: #3427

@eugabrielsilva
Copy link

Is the repo abandoned? 99 open issues and 40 open PRs...

@catalinberta
Copy link

I also encounter this issue, sendMessage() returns no error, yet message is not delivered.

@templargin
Copy link

+1

@Shvan11
Copy link

Shvan11 commented Jan 30, 2025

I also confirm this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants