mirror of
https://github.com/stjornleysi/telegram_glpi.git
synced 2025-11-30 00:53:08 +00:00
bugfix
This commit is contained in:
42
lib/utils.js
42
lib/utils.js
@@ -17,6 +17,7 @@ exports.htmlToText = async (text) => {
|
||||
delete textArray[i];
|
||||
}
|
||||
}
|
||||
// text.replace(/(\.\s)+/g, '. ');
|
||||
let messageText = '';
|
||||
for(let k in textArray){
|
||||
if(textArray[k][0] != '>' && textArray[k].trim() && textArray[k].indexOf('ts@krtech.ru писал') == -1 && textArray[k].indexOf('cellpadding="0"') == -1){
|
||||
@@ -25,24 +26,33 @@ exports.htmlToText = async (text) => {
|
||||
}
|
||||
return messageText.replace(/\[.*?\]/g, '');
|
||||
}catch(e){
|
||||
fs.appendFileSync(dir + "/../logs/logs.json", JSON.stringify("*** htmlToText:\n" + e, null, 3));
|
||||
fs.appendFileSync(dir + "/../logs/logs.txt", e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
exports.parseMessageText = async (message, messageData, ticketId) => {
|
||||
try{
|
||||
let color = await this.getTicketColor(messageData.data[ticketId].status);
|
||||
text = message.text.split('\n');
|
||||
messageText = `${color} <b>ЗАЯВКА <a href="${glpiUrl}front/ticket.form.php?id=${ticketId}">№${ticketId}</a></b>\n\n`;
|
||||
for(let i = 2; i < text.length; i++){
|
||||
if(text[i].indexOf(':') >= 0) messageText += `<b>${text[i].replace(':', ':</b>')}\n`;
|
||||
}
|
||||
if(text[text.length - 1].indexOf("Читать дальше") >= 0){
|
||||
messageText = `${messageText.replace('Читать дальше', '')}\n<b><a href="${glpiUrl}front/ticket.form.php?id=${ticketId}">Читать дальше</a></b>`;
|
||||
}
|
||||
exports.parseMessageText = async (ticket, ticketAuthor, color) => {
|
||||
try{
|
||||
let messageText = `${color} <b>ЗАЯВКА <a href="${glpiUrl}front/ticket.form.php?id=${ticket.id}">№${ticket.id}</a></b>\n\n`;
|
||||
if(ticket.users_id_recipient == conf.glpiConfig.user_id){
|
||||
let text = html.convert(he.decode(ticket.content), {preserveNewlines: true});
|
||||
let halfText = text.split("\nОписание: ");
|
||||
let headers = halfText[0].split("\n");
|
||||
for(let i = 0; i < headers.length; i++){
|
||||
messageText += `<b>${headers[i].split(": ")[0]}: </b>${headers[i].split(": ")[1]}\n`;
|
||||
}
|
||||
messageText += `<b>Описание: </b>${halfText[1]}`;
|
||||
}else{
|
||||
let text = await this.htmlToText(ticket.content);
|
||||
messageText += `<b>Автор заявки: </b>${ticketAuthor}\n`;
|
||||
messageText += `<b>Проблема: </b>${ticket.name}\n<b>Описание: </b>`;
|
||||
messageText += text;
|
||||
if(messageText.length > 600){
|
||||
messageText = `${messageText.substring(0, 500)} + '\n\n<b><a href="${glpiUrl}front/ticket.form.php?id=${ticket.id}">Читать дальше</a></b>`;
|
||||
}
|
||||
}
|
||||
return messageText;
|
||||
}catch(e){
|
||||
fs.appendFileSync(dir + "/../logs/logs.json", JSON.stringify("*** parseMessageText:\n" + e, null, 3));
|
||||
fs.appendFileSync(dir + "/../logs/logs.txt", e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +76,7 @@ exports.createThread = async (bot, messageData, ticketId, title) => {
|
||||
messageData.data[ticketId].pinMessageId = msg.message_id;
|
||||
fs.writeFileSync(dir + "/../data/messageData.json", JSON.stringify(messageData, null, 3));
|
||||
}catch(e){
|
||||
fs.appendFileSync(dir + "/../logs/logs.json", JSON.stringify("*** createThread:\n" + e, null, 3));
|
||||
fs.appendFileSync(dir + "/../logs/logs.txt", e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +115,7 @@ exports.editMessageText = async (bot, messageId, messageText, keyboard) => {
|
||||
reply_markup: {inline_keyboard: keyboard}
|
||||
});
|
||||
}catch(e){
|
||||
//fs.appendFileSync(dir + "/../logs/logs.json", JSON.stringify(e, null, 3));
|
||||
//fs.appendFileSync(dir + "/../logs/logs.txt", e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +123,7 @@ exports.editMessageMarkup = async (bot, messageId, keyboard) => {
|
||||
try{
|
||||
await bot.telegram.editMessageReplyMarkup(conf.supportChatId, messageId, undefined, {inline_keyboard: keyboard});
|
||||
}catch(e){
|
||||
//fs.appendFileSync(dir + "/../logs/logs.json", JSON.stringify(e, null, 3));
|
||||
//fs.appendFileSync(dir + "/../logs/logs.txt", e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user