Announcement

Collapse
No announcement yet.

Calendar Email Invitations - send notification regarding confirmation

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

  • Calendar Email Invitations - send notification regarding confirmation

    Hi there

    When an attendee Accept, Decline, answer "Tentative" to a Meeting event (clicking on the received link), it could be really interesting to send a notifcation to the organizer of the meeting to report the status of the attendee.

    What do you think about it ?
    I can try to implement that and send a PR

    Let me know ?
    Thanks

  • #2
    Hello,
    invitation status is changed directly in database, so you can not catch it. Only if you change the code
    application/Espo/Modules/Crm/EntryPoints/EventConfirmation.php

    Comment


    • #3
      Can i try to send to you a PR to update that part? or let me know if you don't want this feature upstream?

      Comment


      • #4
        This feature has to be configurable. We will think how to do it better.
        Thanks

        Comment


        • #5
          configurable globally ? per user ? per event ?

          Comment


          • #6
            at least catchable for hooks
            https://github.com/espocrm/espocrm/c...b3b49a201ea7e6

            Comment


            • #7
              That's a good design !
              I'm going to write my afterConfirmation method to do my own business :-)

              Thanks ! Awesome team & reactivity.. !

              Comment


              • #8
                https://github.com/espocrm/espocrm/c...mment-27582706

                Comment


                • #9
                  I need the EventID to be able to get the "createdBy" field and send a notification to the organizer to send an acknoledge with the invitee response

                  Comment


                  • #10
                    The first parameter in hook method is event object.
                    $entity->id

                    Comment


                    • #11
                      Yep sorry for that :-)

                      Here is the hook if somebody is interested by or want to review

                      PHP Code:
                      ➜  crm git:(master) ✗ cat www/custom/Espo/Custom/Hooks/Meeting/Base.php
                      <?php
                      namespace Espo\Custom\Hooks\Meeting;

                      use \
                      Espo\ORM\Entity;

                      class 
                      Base extends \Espo\Core\Hooks\Base {

                        protected function 
                      init()
                        {
                          
                      parent::init();
                          
                      $this->addDependencyList([
                              
                      'container',
                              
                      'mailSender',
                              
                      'dateTime',
                              
                      'number',
                              
                      'fileManager',
                              
                      'templateFileManager'
                            
                      ]);
                        }

                        public function 
                      afterConfirmation(Entity $entity, array $options = array(), array $hookData = array()) {
                          
                      $invitee $this->getEntityManager()->getRepository($hookData['inviteeType'])->where(array('id' => $hookData['inviteeId']))->findOne();
                          if (!
                      $invitee) {
                            return;
                          }

                          
                      $emailAddress $entity->get('assignedUser')->get('emailAddress');
                          if (empty(
                      $emailAddress)) {
                            return;
                          }

                          
                      $email $this->getEntityManager()->getEntity('Email');
                          
                      $email->set('to'$emailAddress);
                          
                      $email->set('subject'"Maj RDV - ".$entity->get('name')." - ".$invitee->get('name'));
                          
                      $email->set('isHtml'true);

                          
                      $mailTpl file_get_contents("custom/Espo/Custom/Resources/templates/invitation/fr_FR/afterConfirmation.tpl");

                          
                      $data = array();
                          
                      $data['invitee'] = $invitee->get('name');
                          
                      $data['dateStart'] = $entity->get('dateStart');
                          
                      $data['eventName'] = $entity->get('name');
                          
                      $data['status'] = $hookData['status'];
                          
                      $data['assignedUserName'] = $entity->get('assignedUser')->get('name');

                          
                      $siteUrl rtrim($this->getConfig()->get('siteUrl'), '/');
                          
                      $recordUrl $siteUrl '/#' $entity->getEntityType() . '/view/' $entity->id;
                          
                      $data['recordUrl'] = $recordUrl;

                          
                      $htmlizer = new \Espo\Core\Htmlizer\Htmlizer($this->getInjection('fileManager'), $this->getInjection('dateTime'), $this->getInjection('number'), null);
                          
                      $body $htmlizer->render($entity$mailTpl'invitation-email-body-' $entity->getEntityType(), $datatrue);

                          
                      $email->set('body'$body);
                          
                      $this->getEntityManager()->saveEntity($email);

                          if (
                      $this->getConfig()->get('smtpServer')) {
                              
                      $this->getMailSender()->useGlobal();
                          } else {
                              
                      $this->getMailSender()->useSmtp(array(
                                  
                      'server' => $this->getConfig()->get('internalSmtpServer'),
                                  
                      'port' => $this->getConfig()->get('internalSmtpPort'),
                                  
                      'auth' => $this->getConfig()->get('internalSmtpAuth'),
                                  
                      'username' => $this->getConfig()->get('internalSmtpUsername'),
                                  
                      'password' => $this->getConfig()->get('internalSmtpPassword'),
                                  
                      'security' => $this->getConfig()->get('internalSmtpSecurity'),
                                  
                      'fromAddress' => $this->getConfig()->get('internalOutboundEmailFromAddress'$this->getConfig()->get('outboundEmailFromAddress'))
                              ));
                          }
                          
                      $this->getMailSender()->send($email);
                          
                      $this->getEntityManager()->removeEntity($email);
                        }

                        protected function 
                      getMailSender() {
                              return 
                      $this->getContainer()->get('mailSender');
                        }

                        protected function 
                      getContainer() {
                          return 
                      $this->injections['container'];
                        }
                      }

                      ?>

                      Comment


                      • #12
                        I have a small issue regarding "assignedUser" timezone to display the event dateStart attribut with the right dateTime format
                        i adding many debug log to check how everything goes on.. but don't manage to find a solution

                        PHP Code:
                        .........
                        $user $entity->get('assignedUser');
                        $preferences $this->getEntityManager()->getEntity('Preferences'$user->id);
                        $timezone $preferences->get('timeZone');
                        $tz $timezone $timezone "UTC";
                        $datetime = new \Espo\Core\Utils\DateTime("dd-mm-YYYY""HH:mm"$tz);

                        # my $datetime is correct.. with the good TimeZone for example (Europe/Paris)
                        # Then, in my HTMLizer, i send this $datetime that should be used to display DATETIME field (well recognized for my field dateStart

                        $data = array();
                        $data['invitee'] = $invitee->get('name');
                        $data['dateStart'] = $entity->get('dateStart');
                        $data['eventName'] = $entity->get('name');
                        $data['status'] = $hookData['status'];
                        $data['assignedUserName'] = $entity->get('assignedUser')->get('name');
                        $siteUrl rtrim($this->getConfig()->get('siteUrl'), '/');
                        $recordUrl $siteUrl '/#' $entity->getEntityType() . '/view/' $entity->id;
                        $data['recordUrl'] = $recordUrl;

                        $mailTpl file_get_contents("custom/Espo/Custom/Resources/templates/invitation/fr_FR/afterConfirmation.tpl");
                        $htmlizer = new \Espo\Core\Htmlizer\Htmlizer($this->getInjection('fileManager'), $datetime$this->getInjection('number'), null);
                        $body $htmlizer->render($entity$mailTplnull$datatrue);
                        ...

                        $email $this->getEntityManager()->getEntity('Email');
                        $email->set('to'$emailAddress);
                        $email->set('subject'"Maj RDV - ".$entity->get('name')." - ".$invitee->get('name'));
                        $email->set('body'$body);
                        $email->set('isHtml'true);
                        $this->getEntityManager()->saveEntity($email);
                        ... 
                        $this->getMailSender()->send($email);
                        .. 
                        but when i received my "confirmation", the timezone / dateFormat is not applied
                        Here is the invitation email
                        Click image for larger version

Name:	Capture d’écran 2018-02-16 à 14.39.24.png
Views:	1
Size:	12.3 KB
ID:	34728


                        and my "afterConfirmation" email:


                        Click image for larger version

Name:	Capture d’écran 2018-02-16 à 14.39.42.png
Views:	1
Size:	32.2 KB
ID:	34729

                        I check the "preferences" of Admin user.. and it's Europe/Paris.

                        What am i missing?

                        Thanks for your help !

                        PS: i clear cache/rebuild etc...



                        ..............

                        Comment


                        • #13
                          try to remove $data['dateStart'] row.
                          You need to define only additional variables in $data.
                          Last edited by tanya; 02-16-2018, 01:15 PM.

                          Comment


                          • #14
                            Awesome tanya !!

                            (and i also removed $data['eventName'] to use directly {{name}} coming from $entity

                            Comment

                            Working...
                            X