EvoluxBR / greenswitch

Battle proven FreeSWITCH Event Socket Protocol client implementation with Gevent
Other
126 stars 50 forks source link

How to subscribe to events? #88

Closed dima23113 closed 7 months ago

dima23113 commented 7 months ago

Hello! Please tell me how to do something similar, but using your library? Unfortunately, due to lack of documentation, I was not able to implement this.


def event_listener(fs):
    while True:
        con = create_connection(fs)
        if con.connected():
            print(f"{fs} connected")
            con.events('plain', 'all')
            #con.filter("Event-Name", "DTMF")
            while con.connected():
                e = con.recvEvent()
                if e:
                    if not event_counts.get(e.getHeader("Event-Name")):
                        event_counts[e.getHeader("Event-Name")] = 1
                    else:
                        event_counts[e.getHeader("Event-Name")] += 1
iuridiniz commented 7 months ago

Pseudocode (unable to write a correct one right now)

import greenswitch

fs = greenswitch.InboundESL(host='127.0.0.1', port=8021, password='ClueCon')

def callback(event):
    print(event)
    fs.stop()

fs.register_handler("Event", callback)
fs.connect()
fs.process_events()