Announcement

Collapse
No announcement yet.

Text summarization in EspoCRM

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #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


    • #3
      I'd recommend utilizing Symfony\Component\Process\Process. It's included in Espo.

      Comment

      Working...
      X