Skip to content

Commit

Permalink
send pic
Browse files Browse the repository at this point in the history
  • Loading branch information
MiRo1310 committed Sep 23, 2023
1 parent b4c4f63 commit 31ebd03
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,61 +331,57 @@ class TelegramMenu extends utils.Adapter {
);
return true;
} else if (part.sendPic) {
try {
_this.log.debug("Send Picture");
_this.log.debug("Send Picture");

part.sendPic.forEach((element) => {
token = token.trim();
// if (element.id != "-") {
const url = element.id;
const newUrl = url.replace(/&/g, "&");
exec(
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`,
(error, stdout, stderr) => {
if (stdout) {
_this.log.debug("Stdout: " + JSON.stringify(stdout));
}
if (stderr) {
_this.log.debug("Stderr: " + JSON.stringify(stderr));
}
if (error) {
_this.log.error("Ein Fehler ist aufgetreten: " + JSON.stringify(error));
return;
}
},
);
_this.log.debug(
"url: " +
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`,
);
// }
part.sendPic.forEach((element) => {
token = token.trim();
// if (element.id != "-") {
const url = element.id;
const newUrl = url.replace(/&/g, "&");
exec(
`curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`,
(error, stdout, stderr) => {
if (stdout) {
_this.log.debug("Stdout: " + JSON.stringify(stdout));
}
if (stderr) {
_this.log.debug("Stderr: " + JSON.stringify(stderr));
}
if (error) {
_this.log.error("Ein Fehler ist aufgetreten: " + JSON.stringify(error));
return;
}
},
);
// _this.log.debug(
// "url: " +
// `curl -H "Authorisation: Bearer ${token}" "${newUrl}" > ${directoryPicture}${element.fileName}`,
// );
// }

timeoutKey += 1;
const path = `${directoryPicture}${element.fileName}`;
const timeout = _this.setTimeout(async () => {
_this.log.debug("Send Pic to Telegram");
sendToTelegram(
_this,
userToSend,
path,
undefined,
instanceTelegram,
resize_keyboard,
one_time_keyboard,
userListWithChatID,
);
timeoutKey += 1;
const path = `${directoryPicture}${element.fileName}`;
const timeout = _this.setTimeout(async () => {
_this.log.debug("Send Pic to Telegram");
sendToTelegram(
_this,
userToSend,
path,
undefined,
instanceTelegram,
resize_keyboard,
one_time_keyboard,
userListWithChatID,
);

let timeoutToClear = {};
timeoutToClear = timeouts.filter((item) => item.key == timeoutKey);
clearTimeout(timeoutToClear.timeout);
timeouts = timeouts.filter((item) => item.key !== timeoutKey);
}, element.delay);
timeouts.push({ key: timeoutKey, timeout: timeout });
});
_this.log.debug("Picture sended");
} catch (e) {
_this.log.error("Error :" + JSON.stringify(e));
}
let timeoutToClear = {};
timeoutToClear = timeouts.filter((item) => item.key == timeoutKey);
clearTimeout(timeoutToClear.timeout);
timeouts = timeouts.filter((item) => item.key !== timeoutKey);
}, element.delay);
timeouts.push({ key: timeoutKey, timeout: timeout });
});
_this.log.debug("Picture sended");
return true;
}
} else if (calledValue.startsWith("menu") || calledValue.startsWith("submenu")) {
Expand Down

0 comments on commit 31ebd03

Please sign in to comment.