מצרף את הקוד המלא אם זה יעזור למישהו לעזור לי...
import { YemotRouter } from 'yemot-router2';
import {sendRequest, mainextPath} from '../utils/utils_func.js';
import '../utils/type.js';
import {execFile} from 'child_process';
/** @param {import('yemot-router2').Call} call */
export async function callHandler (call) {
console.log("מכין בקשה");
// מקבל את כל ההעדפות של המאזין
const params = new URLSearchParams({ phone: call.ApiPhone.replace("+972","0") });
const url = `https://stamandsefer.co.il/appart/new/getTzintukSubcrib.php?${params}`;
/** @type {AdResponse} */
let responseSubscribe = await sendRequest(call ,url, "אירעה שגיאה בעת מציאת רישום להתראה");
console.log("responseSubscribe: ", responseSubscribe);
// יוצר פרמטרים לשליחה לקבלת כל המודעות שלא נקראו על פי ההעדפות הנ"ל
let sumAds = 0;
for (let element of makeAdsParams(responseSubscribe, call)) {
//console.log("נכנס ללולאה");
if(element.betShemesh == null) {element.betShemesh = ""};
// מכל שורת פרמטרים מקבל את המודעות
/** @type {AdResponse} */
let responseAds = await sendRequest(call ,`https://stamandsefer.co.il/appart/new/getBuyerAds.php?${new URLSearchParams(element)}`, "אירעה שגיאה בעת מציאת מודעות");
//console.log("responseAds: ", responseAds);
sumAds = sumAds + responseAds.count;
};
// אם אין מודעות בכלל עובר לשלוחה ראשית
if (sumAds==0)
{
call.go_to_folder("/1/1");
}
for (let index = 0; index < 3; index++) {
let toDo = await call.read([{type:"text", data:`יש ${sumAds} התראות חדשות למעבר לשמיעת ההתראות הקש 1 למעבר לשאר השלוחות 2`}],
'tap',
{min_digits: 1, digits_allowed: [1,2, 9, "*0"], typing_playback_mode: 'No'});
if (toDo == 1) {
call.go_to_folder("/1/1/3");
} else if (toDo == 2 || toDo == "*0") {
call.go_to_folder(mainextPath);
}
else if (toDo == 9)
{
let ans = await call.read([{type: 'text', data: "אנא הקלט משהו"}], "record");
console.log(ans);
execFile("python3", ["/home/node.stamandsefer.co.il/public_html/recognize.py",ans], (error, stdout, stderr) => {
console.log(stdout);
if (error) {
console.error(error);
call.id_list_message([{type:'text', data: "Error processing audio" }]);
return;
}
console.log("הבעיה כאן! בפלט");
call.id_list_message([{type:'text', data: ` התוצאה היא ${stdout}`}]);
console.log("הבעיה כאן! בפלט");
});
}
}
call.go_to_folder("/1/1");
}
/***************************************** */
/** @param {AdResponse} res @param {import('yemot-router2').Call} call */
function makeAdsParams(res, call) {
if (!res || !Array.isArray(res.data)) return [];
let ads = [];
/** @type {AdData[]} */
for (const adBase of res.data) {
// עיבוד מודעה
let paramsOfAd = {};
// מוסיף לכל שדה קיים את הערך לאובייקט
const allowedFields = ['buyorrent', 'city', 'betShemesh', 'region', 'room'];
for (const key of allowedFields) {
if (adBase[key] !== undefined && adBase[key] !== null) {
paramsOfAd[key] = adBase[key];
}
}
paramsOfAd.phone = call.ApiPhone.replace("+972", "0");
if (paramsOfAd.room)
{
paramsOfAd.room = paramsOfAd.room.toString().replace(".0","");
}
ads.push(paramsOfAd);
}
return ads;
}
/***************************************** */
/** @param {AdResponse} res*/
function makeAds(res)
{
const adsData = res?.data ?? res?.results;
if (!Array.isArray(adsData)) return [];
let ad = [], tempAd;
for (const adBase of adsData) {
tempAd = `המודעה היא דירה ל${adBase.buyorrent} ב${adBase.city} `;
if (adBase.city === "בית שמש") tempAd += `ה${adBase.betShemesh} `;
tempAd += `${adBase.room} חדרים בשכונה ${adBase.region} ברחוב ${adBase.street} מספר ${adBase.number} קומה ${adBase.floor} במחיר ${adBase.price} טלפון ליצירת קשר ${adBase.phone} `;
if (adBase.phone2) tempAd += ` טלפון נוסף ${adBase.phone2}`;
tempAd = tempAd.replace(".0","").replace(".5"," וחצי").replace("-","מינוס ");
console.log(tempAd);
ad.push({ad: tempAd, adId: adBase.id});
}
return ad;
}