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.1k stars 589 forks source link

Error sendFileFromUrl: Object prototype may only be an Object or null: undefined #796

Closed YogaSakti closed 3 years ago

YogaSakti commented 3 years ago

Describe the bug I got an error like this when using sendFileFromUrl()

image

Steps to Reproduce Steps to reproduce the behavior:

downloader.tiktok(url)
                .then((videoMeta) => {
                    const filename = videoMeta.authorMeta.name + '.mp4'
                    const caps = `*Metadata:*\nUsername: ${videoMeta.authorMeta.name} \nMusic: ${videoMeta.musicMeta.musicName} \nView: ${videoMeta.playCount.toLocaleString()} \nLike: ${videoMeta.diggCount.toLocaleString()} \nComment: ${videoMeta.commentCount.toLocaleString()} \nShare: ${videoMeta.shareCount.toLocaleString()} \nCaption: ${videoMeta.text.trim() ? videoMeta.text : '-'}\n\nProcessed for ${processTime(moment())} _Second_`
                    client.sendFileFromUrl(from, videoMeta.url, filename,  caps, null, { headers: { 'User-Agent': 'okhttp/4.5.0' } }, true)
                        .catch(err => console.log(`sendFileFromUrl has error ${err}\n`))
                }).catch(() => {
                    client.reply(from, 'Gagal mengambil metadata, link yang kamu kirim tidak valid. [Invalid Link]', id)
                })

create() code This is the code you use to create the client. e.g


create('Imperial', {
    headless: true,
    executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
    qrRefreshS: 10,
    qrTimeout: 10,
    autoRefresh: true,
    killProcessOnBrowserClose: true,
    cacheEnabled: false,
    chromiumArgs: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--aggressive-cache-discard',
        '--disable-cache',
        '--disable-application-cache',
        '--disable-offline-load-stale-cache',
        '--disk-cache-size=0'
    ]
})
    .then((client) => {
        console.log('[DEV]', color('Red Emperor', 'yellow'))
        console.log('[CLIENT] CLIENT Started!')

        // Force it to keep the current session
        client.onStateChanged((state) => {
            console.log('[Client State]', state)
            if (state === 'CONFLICT') client.forceRefocus()
        })

        // listening on message
        client.onMessage((message) => {
            client.getAmountOfLoadedMessages() // Cut message Cache if cache more than 3K
                .then((msg) => {
                    if (msg >= 3000) {
                        console.log('[CLIENT]', color(`Loaded Message Reach ${msg}, cuting message cache...`, 'yellow'))
                        client.cutMsgCache()
                    }
                })
                // Message Handler
            msgHandler(client, message)
        })
    })
    .catch((err) => new Error(err))

Expected behavior it should send the video to the user.

DEBUG INFO This is the info printed to the console when you start your app. It should look like this

Debug Info {
  WA_VERSION: 2.2035.14
  PAGE_UA: WhatsApp/2.2029.4 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
  WA_AUTOMATE_VERSION: 2.0.16
  BROWSER_VERSION: HeadlessChrome/84.0.4147.135
}

Screenshots If applicable, add screenshots to help explain your problem. Use headless: false to get screenshots

Host (please complete the following information):

YogaSakti commented 3 years ago

I don't know what happened but no more errors after I rerun the script,

I closed this issue

smashah commented 3 years ago

@YogaSakti ok good.

The error in the screenshot is actually the error from when you use client.reply. I suggest you log the actual error from the main code:

.catch((error) => {
                    console.log(error)
                    client.reply(from, 'Gagal mengambil metadata, link yang kamu kirim tidak valid. [Invalid Link]', id)
                })
YogaSakti commented 3 years ago

okay, thank you πŸ‘