-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working program example #61
Comments
I should start by saying this framework is stateless (to be able to scale in a docker environment). this is an example of a SIP Router/Redirection Service where by we route based of a redis datastore of phone numbers so we can then route to another regions SIP application server (Broadworks). import settings
from Katari import KatariApplication
from Katari.sip.response import ResponseFactory
from utils.redis import RegionStore, NumberStore
app = KatariApplication(settings=settings)
Numbers = NumberStore()
Region = RegionStore()
@app.invite()
def do_invite(request, client):
response = ResponseFactory.build(302) # SIPResponseFactory returns a response instance based from sip code e.g. 302 Moved Temporarily
response = request.create_response(response) # creates response from request
to_number = request.get_to().get_user() #gets user/phonenumber from to field
response.clean_contact() # removes pre existing contact from request (this is because we use the request to generate a response)
route = Numbers.get_number(to_number)
if not route:
route = Region.get_route(settings.REGION)
else:
app.logger.info("Found route on {}".format(to_number))
response.append_contact("{}@{}".format(to_number, route), "0.5") # adds new contact to contacts header with a weight "0.5"
response.set_content_length("0") # sets content length 0 as there is no payload
app.send(response, client) # returns the response
@app.options()
def do_options(request, client):
response = ResponseFactory.build(200)
response = request.create_response(response)
response.set_content_length("0")
app.send(response, client)
if __name__ == "__main__":
app.run() Any other questions let me know |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you happen to have an example program you could share that may help me better understand how to get started? I am not sure how to use the framework to execute a sip dialog.
add INVITE logic here
add REGISTER logic here
What would be some common examples of how you envision this framework being used?
Thanks!
The text was updated successfully, but these errors were encountered: