Implementing this library with express shouldn't be so complicated and verbose. A simple middleware should be able to manage the vast majority of functionality from the client. This feature needs to be implemented with minimal increased library footprint.
@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`);
})();
How to use the middleware:
import { create } from '@open-wa/wa-automate';
const express = require('express')
const app = express()
app.use(express.json())
const PORT = 8082;
function start(client){
app.use(client.middleware);
app.listen(PORT, function () {
console.log(`\n• Listening on port ${PORT}!`);
});
...
}
create({
sessionId:'session1'
}).then(start)
All requests need to be POST requests. You use the API the same way you would with client. The method can be the path or the method param in the post body. The arguments for the method should be properly ordered in the args array in the JSON post body.
Example:
await client.sendText('[email protected]','test')
//returns "[email protected]_3EB0645E623D91006252"
as a request with a path:
const axios = require('axios').default;
axios.post('localhost:8082/sendText', {
args: [
"[email protected]",
"test"
]
})
or as a request without a path:
const axios = require('axios').default;
axios.post('localhost:8082', {
method:'sendText',
args: [
"[email protected]",
"test"
]
})
Thanks for your incredible work and superb documentation. I got this to work very easily with your help.
I will continue to explore it.
Thanks
Hello,
I cant seem to send an image. I am wsing the latest version of the library and was able to get most things to work except sending of files.
it usually returns b64Data.split is not a function among other errors. My simple axios request is as follows
const file = 'iVBORw...cx';
const axios = require('axios').default;
axios.post('http://localhost:8082/sendFile', {
args: [
"[email protected]",
[file],
'ing.png',
'ntesho!'
]
}).then((res) => console.log(res.data))
.catch(err => console.log(err))
Thanks once again for your incredible work.
afaik you need to send the base64 data directly. Here is how i send it (not with the REST api, mind you)
client.sendImage(
to,
`data:${mime.lookup(FILE)};base64,${fs.readFileSync(FILE).toString('base64')}`,
FILE.substring(FILE.lastIndexOf('/') + 1).trim(),
caption
);
Here i am using the libs mime and fs in node.
mime to lookup the mimetype and then fs to open and read the FILE.
Note that FILE is a filepath
Oh. Thanks. I will try that in a minute
Most helpful comment
How to use the middleware:
All requests need to be
POSTrequests. You use the API the same way you would withclient. The method can be the path or the method param in the post body. The arguments for the method should be properly ordered in the args array in the JSON post body.Example:
as a request with a path:
or as a request without a path: