When i use $this->hyperlink()$ while sending notification - by email it's look normal, but in messenger it's look like this:
-span class="object-ref " title="Incident::9039" https://cmdb.domain.com/pages/UI.php?operation=details&class=Incident&id=9039">I-009042< span>
how can i send direct link of incident? ( i deleted some symbols to represent view, cause here HTML works fine..
Last edit: Alexander 2024-08-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From which itop version it's worked?
i have 3.0.1-9191 (cause some addons is worked only on this version)
In current version $this->url()$ just showing in chat $this->url()$, not the link
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and incident have only ref atribute.. it will be easy if ref and id was the same but they are different
Incident&id=$this->ref$ probably worked , but id and ref are not the same =(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I'm not mistaken, there was also the ability to specify "ref" instead as well in the URL. Could be wrong though, or it may need a small tweak somehow.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i made an intermediate bot that accepts and processes POST requests, cuts the link from HTML and sends it to the desired chat in the form I need (i send from itop as json with markdown format, bot cut the link and paste it to the place where it was and not touching other text)
Install node.js from https://nodejs.org/
mkdir html-extractor-bot
cd html-extractor-bot
npm init -y
npm install express cheerio body-parser axios
touch server.js -> then open this file, paste and modify code for your needs
and start server -> node server.js , or use something like pm2 to run it at background
And then just make in iTop connection for webhook http://your_server_ip_or_FQDN:3001/extract-link
i send group_chat_id from iTop and my chat is accepting messages by group chat id and auth token, so modify this code for your chat needs
constexpress=require('express');constcheerio=require('cheerio');constbodyParser=require('body-parser');constaxios=require('axios');constapp=express();constPORT=3001;//Serverportapp.use(bodyParser.json());app.post('/extract-link',async(req,res)=>{console.log('Received request body:',req.body);const{group_chat_id,notification}=req.body;if(!notification||!notification.body){console.error('Field "body" is missing in the notification object.');returnres.status(400).json({success:false,message:'Field "body" is required.'});}consthtmlString=notification.body;console.log('HTML String:',htmlString);//parsingHTMLconst$=cheerio.load(htmlString);//extractURLfromHTMLconstlink=$('a.object-ref-link').attr('href');console.log('Extracted Link:',link);if(!link){console.error('Link not found in the provided HTML.');returnres.status(404).json({success:false,message:'Link not found in the provided HTML.'});}//replacingHTMLwithpureURLconstcleanedMessage=htmlString.replace(/<span[^>]*>.*?<a[^>]*href="([^"]*)"[^>]*>.*?<\/a>.*?<\/span>/g, '$1');console.log('Cleaned Message:',cleanedMessage);try{constbotResponse=awaitaxios.post('https://link_to_your_chat_api',{group_chat_id:group_chat_id,notification:{body:cleanedMessage//Sendingcleanedmessage}},{headers:{'Authorization':'Bearer your_token',//replace"your_token"foryourauthtokenforchatifyouhaveit'Content-Type':'application/json'}});console.log('Bot response:',botResponse.data);res.json({success:true,link:link,botResponse:botResponse.data});}catch(error){console.error('Error sending message to bot:',error);res.status(500).json({success:false,message:'Failed to send message to bot',error:error.message});}});app.listen(PORT,()=>{console.log(```HTMLextractorandbotnotifierisrunningonport${PORT}```);});
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When i use $this->hyperlink()$ while sending notification - by email it's look normal, but in messenger it's look like this:
-span class="object-ref " title="Incident::9039" https://cmdb.domain.com/pages/UI.php?operation=details&class=Incident&id=9039">I-009042< span>
how can i send direct link of incident? ( i deleted some symbols to represent view, cause here HTML works fine..
Last edit: Alexander 2024-08-08
$this->url()$
The url to access the current object in iTop console
From which itop version it's worked?
i have 3.0.1-9191 (cause some addons is worked only on this version)
In current version $this->url()$ just showing in chat $this->url()$, not the link
As i can understand it's worked for fresh releases. is there a way to implement it in my version of the application?
What version are you on? Any reason not to upgrade?
and incident have only ref atribute.. it will be easy if ref and id was the same but they are different
Incident&id=$this->ref$ probably worked , but id and ref are not the same =(
If I'm not mistaken, there was also the ability to specify "ref" instead as well in the URL. Could be wrong though, or it may need a small tweak somehow.
I have the same problem, were you able to solve it?
i made an intermediate bot that accepts and processes POST requests, cuts the link from HTML and sends it to the desired chat in the form I need (i send from itop as json with markdown format, bot cut the link and paste it to the place where it was and not touching other text)
Install node.js from https://nodejs.org/
mkdir html-extractor-bot
cd html-extractor-bot
npm init -y
npm install express cheerio body-parser axios
touch server.js -> then open this file, paste and modify code for your needs
and start server -> node server.js , or use something like pm2 to run it at background
And then just make in iTop connection for webhook http://your_server_ip_or_FQDN:3001/extract-link
i send group_chat_id from iTop and my chat is accepting messages by group chat id and auth token, so modify this code for your chat needs