Menu

Is there a way to send direct hyperlink in notification , not in html format?

Alexander
2024-08-08
2024-08-13
  • Alexander

    Alexander - 2024-08-08

    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
  • Vincent @ Combodo

    $this->url()$
    The url to access the current object in iTop console

     
    • Alexander

      Alexander - 2024-08-09

      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

       
  • Alexander

    Alexander - 2024-08-09

    As i can understand it's worked for fresh releases. is there a way to implement it in my version of the application?

     
    • Jeffrey Bostoen

      Jeffrey Bostoen - 2024-08-13

      What version are you on? Any reason not to upgrade?

       
  • Alexander

    Alexander - 2024-08-09

    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 =(

     
    • Jeffrey Bostoen

      Jeffrey Bostoen - 2024-08-13

      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.

       
  • vladimyr andres gonzalez ruiz

    I have the same problem, were you able to solve it?

     
    • Alexander

      Alexander - 2024-08-13

      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

      const express = require('express');
      const cheerio = require('cheerio');
      const bodyParser = require('body-parser');
      const axios = require('axios');
      
      const app = express();
      const PORT = 3001; // Server port
      
      app.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.');
              return res.status(400).json({
                  success: false,
                  message: 'Field "body" is required.'
              });
          }
      
          const htmlString = notification.body;
          console.log('HTML String:', htmlString);
      
          // parsing  HTML
          const $ = cheerio.load(htmlString);
      
          // extract  URL from HTML
          const link = $('a.object-ref-link').attr('href');
          console.log('Extracted Link:', link);
      
          if (!link) {
              console.error('Link not found in the provided HTML.');
              return res.status(404).json({
                  success: false,
                  message: 'Link not found in the provided HTML.'
              });
          }
      
          // replacing  HTML with pure URL
          const cleanedMessage = htmlString.replace(/<span[^>]*>.*?<a[^>]*href="([^"]*)"[^>]*>.*?<\/a>.*?<\/span>/g, '$1');
      
          console.log('Cleaned Message:', cleanedMessage);
      
          try {
              const botResponse = await axios.post('https://link_to_your_chat_api', {
                  group_chat_id: group_chat_id,
                  notification: {
                      body: cleanedMessage // Sending cleaned message
                  }
              }, {
                  headers: {
                      'Authorization': 'Bearer your_token', // replace "your_token" for your auth token for chat if you have it
                      '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(```HTML extractor and bot notifier is running on port ${PORT}```);
      });
      
       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.