Text summarization in EspoCRM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prathyush Shetty
    Junior Member
    • Oct 2023
    • 22

    Text summarization in EspoCRM

    I have a Python script that summarizes any chunk of text. I want to call the script in the AfterSave hook of some entity let's say "leadhook.php". Is it possible? If yes, how can I do it?
  • jellis
    Junior Member
    • Feb 2024
    • 3

    #2
    I haven't tried this code but it's cobbled together from something similar we have. This assumes your script is under espocrm/custom/scripts. Also this is sloppy because you're passing something unsafe on the command line, but you get the idea.

    PHP Code:
    <?php
    namespace Espo\Custom\Hooks\Lead;
    
    use Espo\ORM\Entity;
    use Espo\Core\ORM\EntityManager;
    
    class LeadHook
    {
        private EntityManager $entityManager;
    
        public function __construct(private EntityManager $em)
        {
            $this->entityManager = $em;
        }
    
        public function afterSave(Entity $entity, $options): void
        {
    
            // use tempnam(), fopen(), fwrite() if you need
            // to process a temporary file, otherwise pass in field
            $params = $entity->get('fieldToSummarize') ?? "";
            $output = null;
            $workdir = dirname($_SERVER['CONTEXT_DOCUMENT_ROOT']);
            $command = "$workdir/scripts/myScript.py '$params' 2>&1";
            $output = shell_exec($command);
    
            $entity->set('summaryField', $output);
            $this->entityManager->saveEntity($entity);
        }
    
    }
    

    Comment

    • yuri
      Member
      • Mar 2014
      • 8453

      #3
      I'd recommend utilizing Symfony\Component\Process\Process. It's included in Espo.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      Working...