What is the Events Manager

The Events Manager consumes realtime events during conversations - it provides a framework to consume and take action on these events asychronously.

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. ACTION: Indicates that a Vocode action has begun or completed.
  4. PHONE_CALL_CONNECTED: Indicates a phone call has been connected (only gets sent during PhoneConversations)
  5. PHONE_CALL_ENDED: Indicates a phone call has ended.

Usage

Using the events manager to take particular action when events fire requires that you subclass vocode.streaming.utils.EventsManager and override the handle_event method.

You can also configure which events your EventsManager is subscribed to by using the subscriptions property (see example).

Example

from vocode.streaming.models.events import Event, EventType

from vocode.streaming.models.events import Event, EventType
from vocode.streaming.models.transcript import TranscriptCompleteEvent
from vocode.streaming.utils.events_manager import EventsManager


class CustomEventsManager(EventsManager):
    def __init__(self):
        super().__init__([EventType.TRANSCRIPT_COMPLETE])

    async def handle_event(self, event: Event):
        if isinstance(event, TranscriptCompleteEvent):
            print("The call has finished, the transcript was", event.transcript.to_string())

In this example, we create a custom EventsManager subclass is created with a subscription to the TRANSCRIPT_COMPLETE event and then print the transcript when we receive the event.

To use CustomEventsManager, you can pass it into any Conversation, e.g.

...
conversation = StreamingConversation(
    ...,
    events_manager=CustomEventsManager()
)

You can also pass it into a TelephonyServer, like:

server = TelephonyServer(
    ...,
    events_manager=CustomEventsManager()
)