Skip to content

Commit

Permalink
Merge pull request #40 from vasani-arpit/development
Browse files Browse the repository at this point in the history
Send file and revision download bug in Mac
  • Loading branch information
vasani-arpit authored Jun 15, 2019
2 parents 6b743ed + 664332a commit 1c0c173
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ An array of objects. Properties of Object are self explanatory.

- **Response** If any of the above conditions becomes true then corresponding response string will be sent as message to the user or group.

- **file** name of the file (from current directory) which you want to send along with response

**Blocked**

Array of numbers with county code to which this bot will not reply to.
Expand Down Expand Up @@ -142,7 +144,11 @@ None. The idea was to get a better understanding of how things work together, Bu
- [Ora](https://www.npmjs.com/package/ora) for spinner
- [cli-progress](https://www.npmjs.com/package/cli-progress) for download progress bar in terminal
- [qrcode-terminal](https://www.npmjs.com/package/qrcode-terminal) to generate QRCode in terminal
- [mime](https://www.npmjs.com/package/mime) detect mime file sent

* **Convert Online File for Base64 Encode**

- https://www.base64-image.de/

* **Apart from development, What else do you do?**

Expand Down
14 changes: 11 additions & 3 deletions bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
{
"contains": [],
"exact": ["hello"],
"response": "hi"
"response": "hi",
"file":"noFile.png"
},
{
"contains": [],
"exact": ["hy"],
"response": "hi"
"response": "hi",
"file":"github.png"
},
{
"contains": [],
Expand Down Expand Up @@ -53,6 +55,12 @@
"contains": ["janmdin","hardik","shubhkaamna"],
"exact": [],
"response": "aabhar 🙏"
},
{
"contains": [],
"exact": ["github"],
"response": "Git Hub Logo",
"file":"github.png"
}
],
"blocked": [],
Expand All @@ -61,4 +69,4 @@
"suggestions":["👍","Ha","aevu m?","Okay","Thanks"],
"clicktosend":true
}
}
}
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"homepage": "https://github.com/vasani-arpit/WBOT#readme",
"dependencies": {
"cli-progress": "^2.1.1",
"mime": "^2.4.4",
"node-fetch": "^2.3.0",
"ora": "^3.0.0",
"puppeteer-core": "^1.16.0",
Expand Down
2 changes: 1 addition & 1 deletion src/detectRev.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ this.getRevNumber = function () {
.then(json => {
//console.log(json);
var betaChannel = json[0].versions.find(x => x.channel == "canary").branch_base_position;
resolve(betaChannel);
resolve("666595");
});
})

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ async function Main() {
page.exposeFunction("log", (message) => {
console.log(message);
})
page.exposeFunction("getFile", utils.getFileInBase64);
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ WAPI.waitNewMessages(false, (data) => {
}
WAPI.sendSeen(message.from._serialized);
WAPI.sendMessage2(message.from._serialized, response);
console.log();
if ((exactMatch || PartialMatch).file != undefined) {
window.getFile((exactMatch || PartialMatch).file).then((base64Data) => {
//console.log(file);
WAPI.sendImage(base64Data, message.from._serialized, (exactMatch || PartialMatch).file);
}).catch((error) => {
window.log("Error in sending file\n" + error);
})
}
}
});
});
Expand All @@ -49,7 +58,7 @@ WAPI.addOptions = function () {
div.innerHTML = suggestions;
div.classList.add("grGJn");
var mainDiv = document.querySelector("#main");
var footer = document.querySelector("footer");
var footer = document.querySelector("footer");
footer.insertBefore(div, footer.firstChild);
var suggestions = document.body.querySelectorAll(".reply-options");
for (let i = 0; i < suggestions.length; i++) {
Expand All @@ -59,5 +68,5 @@ WAPI.addOptions = function () {
window.sendMessage(event.target.textContent).then(text => console.log(text));
});
}
mainDiv.children[mainDiv.children.length - 5].querySelector("div > div div[tabindex]").scrollTop += 100;
mainDiv.children[mainDiv.children.length - 5].querySelector("div > div div[tabindex]").scrollTop += 100;
}
17 changes: 16 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var path = require("path");
const mime = require('mime');
var fs = require("fs");
this.injection = function (filename) {
return new Promise((resolve, reject) => {
var filepath = path.join(__dirname, filename);
//console.log("reading file from" + (filepath));
fs.readFile(filepath, 'utf8', (err, data) => {
if (err) return reject(err);
console.log("1 "+data);
console.log("1 " + data);
resolve(data);
});
});
Expand All @@ -23,6 +24,20 @@ this.externalInjection = function (filename) {
});
}

this.getFileInBase64 = function (filename) {
return new Promise((resolve, reject) => {
try {
filename = path.join(process.cwd(), filename);
// get the mimetype
const fileMime = mime.getType(filename);
var file = fs.readFileSync(filename, { encoding: 'base64' });
resolve(`data:${fileMime};base64,${file}`);
} catch (error) {
reject(error);
}
});
}

this.delay = ms => {
return new Promise(resolve => {
setTimeout(resolve, ms);
Expand Down

0 comments on commit 1c0c173

Please sign in to comment.