@צדיק-תמים קודם כל תודה על העזרה!
handlerReceive זה מגיע אחרי הבאג, וזה עובד מצויין, שבמקרה שלא נמצאו אסימונים בקריאה לgetAir או שהמשתמש בחר 2 להמשיך כרגיל זה יוצר את תסריט השיחה הרגיל,
getAir קורא נתונים מקובץ בשרת, כעת שמתי בו 2 שורות בגוף הקוד, ובודק האם העמודה השניה תואמת למס' הזיהוי של המשתמש במערכת, ובאם הוא מוצא הוא מחזיר את השורות כמערך של אובייקטים כל שורה באובייקט נפרד עם העמודות שלה.
אני מקווה שכעת זה מספיק,כי אני לא באמת יודע מה להביא כי כבר getAir עצמה נראית בסדר במחשב, ורק בטלפון זה לא מושמע
async function callHandler(call) {
const isAir = await getAir(call);
console.log('isAir', isAir.join('\n'));
if (isAir != false) {
var message = '';
if (isAir.length > 1) {
const messages = isAir.map(row => `אסימון מסוג ${row.type} בשווי ${row.value}`).join(' וכן את ');
message = `יש לכם ${isAir.length} אסימונים פעילים ${messages}`;
} else if (isAir.length === 1) {
const row = isAir[0];
message = `יש לכם אסימון אחד פעיל מסוג ${row.type} בשווי ${row.value}`;
} else {
console.log('No matching rows found');
}
console.log('message', message);
const choiceAction = await call.read([{
type: 'text',
data: message + `למימוש הקישו 1 להמשך הפעילות הקישו 2`
}], 'tap', {
max_digits: 1,
digits_allowed: [1, 2],
allow_empty: false,
sec_wait: 12
});
console.log('choiceAction', choiceAction);
if (choiceAction == 1) {
call.id_list_message([{
type: 'text',
data: `אפשרות זו עדיין לא פעילה`
}]);
} else if (choiceAction == 2) {
handlerReceive(call);
}
} else {
handlerReceive(call);
}
}
async function getAir(call) {
const user = "079555555";
//let apiEnterID = call?.ApiEnterID || "";
//let [apiEnterIDType, apiEnterIDValue] = apiEnterID !== "" ? apiEnterID.split('-') : ["ללא", call.ApiPhone];
let apiEnterIDValue = '0559777777';
try {
//const filePath = `${user}/air.ini`;
//const fileContent = await fs.readFileSync(filePath, 'utf-8');
const fileContent = `afhnrcl4b4r24k9,0559777777,0559777777,יוסי,12,זהב,1,רגיל,1
7bun3eqdznlpk86,0559777777,0559777777,יוסי,12,זהב,1,רגיל,1`;
const dataArray = fileContent.split('\n').filter(Boolean);
const matchingRows = dataArray.filter(row => {
const columns = row.split(',');
return columns[2] === apiEnterIDValue;
});
if (matchingRows.length === 0) {
console.log('No matching rows found');
return false;
}
console.log('matching rows');
const resultArray = matchingRows.map(row => {
const columns = row.split(',');
return {
IdAction: columns[0],
phone: columns[1],
idphone: columns[2],
name: columns[3],
typeIndex: columns[4],
type: columns[5],
valueIndex: columns[6],
value: columns[7],
sum: columns[8]
};
});
return resultArray;
} catch (error) {
console.error('Error:', error.message);
return false;
}
}