Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/instagram/src/handlers/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const fs = require('fs');
const crypto = require("crypto");
const axios = require('axios').default;
const account_info = require('../dcore/account_info.js');
const { Product } = require("../models/Products");
const product_info = require('../dcore/products.js');
const private_message=require('../dcore/private_message.js');
const {INSTAGRAM_URI} =process.env;
// const Queue = require('bull');
// const messageQueue = new Queue('messageQueue',{
// redis: {
// username: process.env.REDIS_USER_NAME,
// host: process.env.REDIS_HOST,
// password: process.env.REDIS_PASSWORD,
// port: process.env.REDIS_PORT,
// }
// });
const invalid_words=["fuck","damn", "cunt","faggot", "Shit","Nigga", "Slut"];
function decryptText (encryptedText) {
return crypto.privateDecrypt(
{
key: fs.readFileSync('fb_private_key.pem', 'utf8'),
oaepHash: 'sha256'
},
encryptedText
)
}
async function getLastInteractionTimestamp(senderId,ACCESS_TOKEN) {
try {
var ACCESS_TOKEN= await decryptText (Buffer.from(ACCESS_TOKEN, "base64"));
var response= await axios.get(`${INSTAGRAM_URI}/me/conversations?limit=10&fields=messages{from,created_time}&user_id=${senderId}&access_token=${ACCESS_TOKEN.toString()}`);
if (response.status=== 200) {
var conversationsData = response.data;
var lastInteraction=null;
if ( conversationsData && conversationsData.data[0].messages.data.length>0) {
for (const message of conversationsData.data[0].messages.data) {
// console.log(message.from.id);
if (message.from.id == senderId) { // Check if the message is from the user
lastInteraction = message.created_time;
break; // Stop at the most recent message from the user
}
}
if (lastInteraction) {
const now = new Date();
if ((now - new Date(lastInteraction)) <= 24 * 60 * 60 * 1000) {
// console.log("within 24");
return 1;
} else {
return 2;
}
}else{
return 2;
}
} else {
return 2;
}
}else{
return 2;
}
} catch (error) {
console.log("error ==" + error);
return 2;
}
}
async function commentReply(ACCESS_TOKEN,comment_id,message) {
var ACCESS_TOKEN= await decryptText (Buffer.from(ACCESS_TOKEN, "base64"));
var response= await axios.post(`${INSTAGRAM_URI}/${comment_id}/replies`,{
"message": message
},
{
params: { access_token: ACCESS_TOKEN }
}).then((res) => {
// console.log(res.data);
}).catch((error) => {
console.log(error);
});
return "done";
}
// Handles messages events
const liveComment = async function (user_id,senderId, commentData) {
let data;
let response;
var res;
let live_id=commentData.media.id;
// const jsonData = JSON.stringify(commentData);
// // Write the JSON string to a file
// fs.appendFile("./Live_Comment/"+live_id+'.json', jsonData+",\r\n", 'utf8', (err) => {
// if (err) throw err;
// // console.log('The file has been saved!');
// });
data=await account_info.get_accessToken(user_id);
if (data) {
var ACCESS_TOKEN=data.token;
var vendor_id=data.vendor_id;
var shop_id=data.shop_id;
var text_cm=commentData.text;
var comment_id=commentData.id;
var text_m=text_cm.toLowerCase();
var vulgar = invalid_words.find(substring => text_m.includes(substring.toLowerCase()));
if (vulgar) {
return "done";
// delete is not available for live comment, so we will reply with a warning message and ask them to delete the comment by themselves.
// var ACCESS_TOKEN= await decryptText (Buffer.from(ACCESS_TOKEN, "base64"));
// response= await axios.delete(`${process.env.FACEBOOK_URI}/${commentData.comment_id}?access_token=${ACCESS_TOKEN.toString()}`);
}else{
const numberPattern = /\b[1-9]\d{3}\b/;
var pr_code = text_cm.match(numberPattern);
if (pr_code) {
pr_code=parseInt(pr_code[0]);
// product code
const product_code = vendor_id + "_" + pr_code;
var pr=await Product.findOne({$and:[{product_code: product_code},{visibility: 1},{shop_id: shop_id}]});
if (pr) {
var message_type =await getLastInteractionTimestamp(senderId,ACCESS_TOKEN);
if (message_type==1) {
var res = await product_info.get_product(user_id,pr_code,vendor_id,ACCESS_TOKEN,senderId,shop_id);
var message="Thank you for contacting us. We have replied you back to you on messenger. Please check your messenger.";
await commentReply(ACCESS_TOKEN,comment_id,message);
}else if(message_type==2){
if (pr) {
response={
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text":`Are you interested on product ${ pr.title} (${pr_code}) ? Click the Yes button below to know more details.`,
"buttons":[
{
"type":"postback",
"title":"Yes",
"payload":`product_${pr_code}`
}
]
}
}
}
var res=await private_message.callSendAPI (ACCESS_TOKEN,comment_id, response);
var message="Thank you for contacting us. We have replied you back to you on messenger. Please check your messenger.";
await commentReply(ACCESS_TOKEN,comment_id,message);
return res;
}
}
}else{
var message="Thank you for contacting us. Our team will get back to you soon. However, you can always send us a message on messenger to get replies faster.";
await commentReply(ACCESS_TOKEN,comment_id,message);
}
}else{
var message="Thank you for contacting us. Our team will get back to you soon. However, you can always send us a message on messenger to get replies faster.";
await commentReply(ACCESS_TOKEN,comment_id,message);
}
// console.log(pr_code);
// if (pr_code) {
// }else{
// var message="Thank you for contacting us. Our team will get back to you soon. However, you can always send us a message on messenger to get replies faster.";
// await commentReply(ACCESS_TOKEN,comment_id,message);
// }
return "done";
}
}else{
console.log("Page data not found.......");
return "done";
}
}
module.exports={ liveComment }; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0148 ]-- |