Wa-automate-nodejs: Best way to send files from URL directly

Created on 14 Apr 2020  Â·  8Comments  Â·  Source: open-wa/wa-automate-nodejs

Hi, thanks for the great work again.
I was working on bad methods to send a media message (an image as example) directly from a remote link, grapping the file and converting to base64 then sending .... etc, i couldn't achieve a reliable function.

Can you please advice me?

enhancement

Most helpful comment

@tinyCoder32 @blackchineykh @m7mdcc @apnerve You can now use sendFileFromUrl like so:

//simple get

client.sendFileFromUrl(
'[email protected]',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'dummy.pdf',
'Here is your dummy pdf')

//OR
//custom request using: https://github.com/axios/axios#request-config

client.sendFileFromUrl(
'[email protected]',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'dummy.pdf',
'Here is your dummy pdf',{
    method: "post",
    proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  },
})

Please report back if it worked for you. Thanks

All 8 comments

You should download your file from the url as base64 first. You can use fetch-base64. Then look at the params for sendImage or sendFile in the whatsapp client library

There are a million different ways to download a file. I agree with @blackchineykh 's suggestion. Might start using that one myself actually. Thanks

You should download your file from the url as base64 first. You can use fetch-base64. Then look at the params for sendImage or sendFile in the whatsapp client library

I have tryout this package , but Iam facing this issue : https://github.com/gamell/fetch-base64/issues/11

but i did that in another way .

@github-actions run


âš¡ Release! âš¡

(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`);
exec(`npm run release-ci`);

//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`);
  })();

Changelog

🚀 Release 1.8.66 (2020-04-19)

@tinyCoder32 @blackchineykh @m7mdcc @apnerve You can now use sendFileFromUrl like so:

//simple get

client.sendFileFromUrl(
'[email protected]',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'dummy.pdf',
'Here is your dummy pdf')

//OR
//custom request using: https://github.com/axios/axios#request-config

client.sendFileFromUrl(
'[email protected]',
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'dummy.pdf',
'Here is your dummy pdf',{
    method: "post",
    proxy: {
    host: '127.0.0.1',
    port: 9000,
    auth: {
      username: 'mikeymike',
      password: 'rapunz3l'
    }
  },
})

Please report back if it worked for you. Thanks

@smashah , requestConfig is just freaking good option , Thanks !

Np. Tested and confirmed to be working. Closing. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alishahlakhani picture alishahlakhani  Â·  7Comments

arisros picture arisros  Â·  4Comments

jazZcarabazZ picture jazZcarabazZ  Â·  5Comments

phantom-limb picture phantom-limb  Â·  5Comments

DeLuca92 picture DeLuca92  Â·  5Comments