https://katari.readthedocs.io/en/latest/
pip install Katari
pip install git+https://github.com/hyperioxx/Katari.git
to create a katari project run the following command in your terminal
katari --build-app <project name>
import settings
from Katari import KatariApplication
from Katari.sip.response import ResponseFactory
app = KatariApplication(settings=settings)
@app.invite()
def do_invite(request, client):
# add INVITE logic here
response = ResponseFactory.build(200) # 200 OK
app.send(request.create_response(response), client)
@app.register()
def do_register(request, client):
# add REGISTER logic here
response = ResponseFactory.build(401) # 401 unauthorized
app.send(request.create_response(OK200()), client)
@app.options()
def do_options(request, client):
# add OPTIONS logic here
response = ResponseFactory.build(200) # 200 OK
app.send(request.create_response(response), client)
@app.info()
def do_info(request, client):
# add INFO logic here
response = ResponseFactory.build(200) # 200 OK
app.send(request.create_response(response), client)
if __name__ == "__main__":
app.run()
create a directory called middleware within your project
myproject -
- app.py
- settings.py
- middleware << LIKE THIS
- __init__.py
- test.py
your middleware can modify the sip message before it reaches your main logic using the process_request method and also modify the response before it gets sent back to the client using process response method.
test.py
from Katari.interfaces import MiddlewareInterface
class Test(MiddlewareInterface):
def process_request(self, message):
print(str(message))
return message
def process_response(self, message):
print(str(message))
return message
settings.py
"""
## ## ### ######## ### ######## ####
## ## ## ## ## ## ## ## ## ##
## ## ## ## ## #