Zimbra SkillZ: Capture Zimbra Events Inside a Zimlet

Hello Zimbra Customers, Partners & Friends,

Do you want to capture user events to trigger an action? The zimletEventEmitter can register listeners for these events:

  • LOGOUT: fired when the user clicks the Logout menu item. It can be used to trigger a logout in non Single Log Out aware 3rd party application.
  • ONSEND: fired when the user clicks the Send button when sending an email. It can be used for email error checks, such as a forgotten attachment reminder, or do a check in a 3rd party application for compliance validation.
  • ONSENDINVITEREPLY: fired when a user RSVPs to a calendar invitation. The verb and invitation are passed to the event handler. You can use the verb to determine if the user accepted, declined, proposed a new time or tentatively accepted the invitation. Define your handler like: onSendHandler = (args) => {console.log(args);}.

New events will be added to Zimbra soon. Check back for updates here: https://github.com/Zimbra/zimlet-cli/wiki/Capture-Zimbra-events-inside-a-Zimlet

Example

Here’s an example of how a Zimlet registers a listener for a logout event.

import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';

const onLogoutHandler = () => { /** Do something */ };
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler);

 

Types of Handlers

There’re two types of handlers: synchronous and asynchronous

  1. Synchronous is for tasks like calculating something, displaying toast, or updating view/state. Here’s an example:
import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';

const onLogoutHandler = () => { /** Display toast message */ };
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler);

 

  1. Asynchronous is for tasks like invoking an API call or displaying dialog to confirm the action with the user. Here’s an example:
import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';

const onLogoutHandler = () => new Promise((resolve, reject) => {
    if (window.confirm("Do you really want to logout?")) {
        resolve();
    } else {
        reject();
    }
});
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, 
onLogoutHandler, true); //the 3rd argument makes the handler asynchronous

 

To remove a listener, use zimletEventEmitter.off:

zimletEventEmitter.off(ZIMBRA_ZIMLET_EVENTS.LOGOUT, 
onLogoutHandler);

 

Many thanks,
Your Zimbra Team

, , , , ,

No comments yet.

Leave a Reply