Calendar Email Invitations - send notification regarding confirmation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wtconseil
    Active Community Member
    • Apr 2015
    • 335

    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
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #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

    • wtconseil
      Active Community Member
      • Apr 2015
      • 335

      #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

      • tanya
        Senior Member
        • Jun 2014
        • 4308

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

        Comment

        • wtconseil
          Active Community Member
          • Apr 2015
          • 335

          #5
          configurable globally ? per user ? per event ?

          Comment

          • tanya
            Senior Member
            • Jun 2014
            • 4308

            #6
            at least catchable for hooks
            EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.

            Comment

            • wtconseil
              Active Community Member
              • Apr 2015
              • 335

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

              Thanks ! Awesome team & reactivity.. !

              Comment

              • wtconseil
                Active Community Member
                • Apr 2015
                • 335

                #8
                EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.

                Comment

                • wtconseil
                  Active Community Member
                  • Apr 2015
                  • 335

                  #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

                  • tanya
                    Senior Member
                    • Jun 2014
                    • 4308

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

                    Comment

                    • wtconseil
                      Active Community Member
                      • Apr 2015
                      • 335

                      #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(), $data, true);
                      
                          $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

                      • wtconseil
                        Active Community Member
                        • Apr 2015
                        • 335

                        #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, $mailTpl, null, $data, true);
                        ...
                        
                        $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:	664
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:	585
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

                        • tanya
                          Senior Member
                          • Jun 2014
                          • 4308

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

                          Comment

                          • wtconseil
                            Active Community Member
                            • Apr 2015
                            • 335

                            #14
                            Awesome tanya !!

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

                            Comment

                            • esforim
                              Active Community Member
                              • Jan 2020
                              • 2204

                              #15
                              Read this section here on the Hook page: https://github.com/espocrm/documenta...pment/hooks.md Meeting / Call

                              • afterConfirmation - when an event attendee clicks on accept/decline/tentative link; details are passed in the 3rd $data argument
                              Did a search and came across this thread, I didn't even know you can send out an "Invitation Email", how do I do that? Is it just Email Template? But Meeting don't have an option to send email.
                              Anyone can help?

                              Comment

                              Working...