25 באפר׳ 2022, 9:34

הצלחתי לשמור ולהפעיל פרויקט אבל משום מה זה לא מצנתק ולא משמיע הודעות מה יכול להיות הבעיה
Untitled.png ![כיתוב בבעיות טעינה](כתובת תמונה)

|-function mailToPhone() {
const url = ('https://private.call2all.co.il/ym/api/');
const token = ('0700000006:60000005');
const path = ('ivr2:2/');
const listTzintuk = ('tzl:1');
const label = GmailApp.getUserLabelByName('לטלפון');
let didUpload = false
chechForGmails()
 
function chechForGmails() {
  const threads = GmailApp.search('label:לטלפון');
  for (const thread of threads) {
    const messages = thread.getMessages();
    const minuteAgo = new Date(Date.now() - 60000);
   
    if (thread.getLastMessageDate() > minuteAgo) {
      for (const message of messages) {
        if (message.getDate() > minuteAgo) {
        const result = sendToYemot(message);
        didUpload = result || didUpload;
        }
      }
      thread.removeLabel(label);
    } else {
      const result = sendToYemot(messages[messages.length - 1]);
      didUpload = result || didUpload;
      thread.removeLabel(label);
    }
  }
 
  if(didUpload === true){
  const tzintuk = UrlFetchApp.fetch(`${url}RunTzintuk?token=${token}&phones=${listTzintuk}`);
  Logger.log(tzintuk)
  }
}
function sendToYemot (message) {
  const ttsString = `הודעה מאת. ${message.getFrom()}. ,נושא,. ${message.getSubject()}. גוף ההודעה. ${message.getPlainBody()}`;
  Logger.log({ ttsString });
  const directoryListing = JSON.parse(UrlFetchApp.fetch(`${url}GetIVR2Dir?token=${token}&path=${path}`));
  Logger.log(directoryListing)
  if (directoryListing.responseStatus === 'OK') {
    const lastFileName = directoryListing.files
      .filter(file => file.fileType === 'AUDIO' || file.fileType === 'TTS')
      .map(file => file.name.split('.')[0])
      .find(fileName => !isNaN(fileName));
    const newFileNumber = Number(lastFileName || -1) + 1;
    const newFileName = newFileNumber.toString().padStart(3, '0');
    const newFilePath = `${path}${newFileName}.tts`;
 
    const payload = {
      token,
      what: newFilePath,
      contents: ttsString
    };
    const uploadResult = JSON.parse(UrlFetchApp.fetch(url + 'UploadTextFile?', { payload }));
    return uploadResult.responseStatus === 'OK';
  }
 }
}