How to use a class to handle eventsΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from jaspion.abc import AbstractBaseHandler
from jaspion import Jaspion


# Freeswitch data to connection
freeswitch = {"host": "127.0.0.1", "password": "ClueCon", "port": 8021}


# Create a subclass of *AbstractBaseHandler*
class SimpleHandler(AbstractBaseHandler):
    def setup(self):
        print("Hello, I am a setup.")

    def handle(self):
        print("event:")
        print(self.event)

    def finish(self):
        print("Finishing the processing.")


# Create a Jaspion App
app = Jaspion(**freeswitch)


# Add Classhandler to event.
app["HEARTBEAT"] = SimpleHandler


# Run Jaspion App
if __name__ == "__main__":
    app.run()