Skip to main content

What is the Events Manager

The Events Manager is a class designed to facilitate asynchronous handling of events in the application. It allows for non-blocking actions on events, such as processing transcripts, managing phone calls, and other tasks. The main components of the Events Manager are the EventsManager class and several Event subclasses representing various event types.

EventsManager Class

The EventsManager class is responsible for managing the event queue and handling events asynchronously. The class provides methods for publishing events, starting the event loop, handling events, and ending the event loop.

Initialization

The EventsManager constructor accepts an optional list of EventType subscriptions. By default, it initializes an empty set of subscriptions, an asynchronous queue, and sets the active attribute to False.

Publishing Events

The publish_event method takes an Event object as input and adds it to the queue if its type is in the set of subscribed event types.

Starting the Event Loop

Current Event Types

The current event types include:
  1. TRANSCRIPT: Indicates a partial transcript for the conversation has been received.
  2. TRANSCRIPT_COMPLETE: Indicates the transcript is complete (ie conversation has ended).
  3. PHONE_CALL_CONNECTED: Indicates a phone call has been connected.
  4. PHONE_CALL_ENDED: Indicates a phone call has ended.
  5. RECORDING: (Vonage Only) Indicates a secure URL containing a recording of the call is available. Requires recording=true in VonageConfig.

Example Usage

The following example demonstrates how the EventsManager class can be used to consume the TRANSCRIPT_COMPLETE event and save the transcript to a file using the add_transcript method:
In this example, a custom EventsManager subclass is created with a subscription to the TRANSCRIPT_COMPLETE event. The handle_event method is overridden to save the transcript to a file using the add_transcript method when the TRANSCRIPT_COMPLETE event is received.