Skip to content

Custom event handler

You can create a custom event handler to listen to events from Lime CRM, both the built in core events, and events that you define and publish yourself from a custom endpoint or a custom limeobject.

To add a custom event handler to your package, run the following from the root of your package directory:

lime-project generate event-handler

This adds a custom event handler that listens for changes to companies and posts information to a URL if it sees that the name of the company has changed:

import logging
import requests

logger = logging.getLogger(__name__)

def company_renamed(worker, body, message):
    """Summarize your event handlers's functionality here"""'Received message: {}'.format(body))

    if 'name' in body['original_values']:'Company renamed, calling external API')
        data = dict(
            new_name=body['values']['name'])'https://some.api/company_renamed', json=data)


def register_event_handlers(worker, config):

The register_event_handlers function starts listening to core events that are sent whenever a company is updated, and will call our handler function whenever it receives one.

The comapny_renamed function checks to see if the body of the event received indicates that the name of the company has changed. If so, it extracts the old and new name of the company and post that information to a URL.