Skip to content

Commit

Permalink
Fixed Issue vasani-arpit#308
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashvigandhi committed Oct 19, 2023
1 parent 7b873ef commit 0caa952
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
1 change: 1 addition & 0 deletions bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
}
],
"blocked": [],
"allowed":[],
"noMatch":"{🤔|🤷‍♂️}",
"smartreply":{
"suggestions":["Hello", "Welcome to my store !!", "Thanks for reaching out 🙏"],
Expand Down
51 changes: 22 additions & 29 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,14 @@ async function sendReply({ msg, client, data, noMatch }) {

// files = await spintax.unspin(data.file);
files = data.file
if(Array.isArray(files))
{
if (Array.isArray(files)) {
files.forEach(file => {
sendFile(file)
})
}
else{
}
else {
sendFile(files)
}
}
// if responseAsCaption is true, send image with response as a caption
// else send image and response seperately
await client.sendMessage(msg.from, response);
Expand All @@ -275,12 +274,12 @@ async function sendReply({ msg, client, data, noMatch }) {
await msg.reply(response);
}
}
function sendFile(file){
function sendFile(file) {
if (captionStatus == true) {
utils
.getFileData(file)
.then(async ({ fileMime, base64 }) => {

// console.log(fileMime);
// send response in place of caption as a last argument in below function call
var media = await new MessageMedia(
Expand Down Expand Up @@ -308,7 +307,7 @@ async function sendReply({ msg, client, data, noMatch }) {
console.log(
"Either the responseAsCaption is undefined or false, Make it true to allow caption to a file"
);

utils
.getFileData(file)
.then(async ({ fileMime, base64 }) => {
Expand All @@ -329,8 +328,9 @@ async function sendReply({ msg, client, data, noMatch }) {
.catch((error) => {
console.log("Error in sending file\n" + error);
})
}}

}
}

}

async function processWebhook({ msg, client }) {
Expand Down Expand Up @@ -373,9 +373,9 @@ async function processWebhook({ msg, client }) {

const mimeTypeMatch = itemFile.file.match(/^data:(.*?);/);

const base64Data = mimeTypeMatch ? itemFile.file.split(',')[1] : itemFile.file ;
const mimeType = mimeTypeMatch ? itemFile.file.split(':')[1].split(';')[0] : "image/jpg" ;
const base64Data = mimeTypeMatch ? itemFile.file.split(',')[1] : itemFile.file;

const mimeType = mimeTypeMatch ? itemFile.file.split(':')[1].split(';')[0] : "image/jpg";

var media = await new MessageMedia(
mimeType,
Expand Down Expand Up @@ -404,23 +404,16 @@ async function smartReply({ msg, client }) {
//Don't reply is sender is blocked
const senderNumber = msg.from.split("@")[0]
var blockedNumbers = appconfig.blocked
var count = 0;
if(blockedNumbers)
{
blockedNumbers.forEach(num => {
num.replace(/\s+/g, '')
num.replace('+','')

if(num == senderNumber)
{
console.log("Message received but sender is blocked so will not reply.")
count++
return;
}
})
var allowedNumbers = appconfig.allowed
// check if blocked numnbers are there or not.
// if current number is init then return
if (Array.isArray(blockedNumbers) && blockedNumbers.includes(senderNumber)) {
console.log("Message received but sender is blocked so will not reply.")
return;
}
if(count != 0)
{

if (Array.isArray(allowedNumbers) && allowedNumbers.length > 0 && !allowedNumbers.includes(senderNumber)) {
console.log("Message received but user is not in allowed list so will not reply.")
return;
}

Expand Down

0 comments on commit 0caa952

Please sign in to comment.