~singpolyma/sgx-jmp

sgx-jmp/web.rb -rw-r--r-- 8.7 KiB
Merge branch 'sip-concurrency'

* sip-concurrency:
  Limit call concurrency for outbound SIP
Limit call concurrency for outbound SIP
Shunt call to voicemail on exception
Set Sentry user from CustomerRepo

We don't always use this to get the current user, so make it optional.
Import some hotfixes from prod
Do not log error when hangup/voicemail a call that is already gone
Add customer_id to Sentry where relevant
Pass customer_id through to leg2

The to in leg2 is not the phone number, but the fwd, which is not useful for
looking up customer.
Make sure from and to are in correct direction

Doesn't affect any current code paths, but should be correct in case we ever
start using it in the inbound case.

Also from does not have to be a formatted phone number, can be a string like
Anonymous, etc.
JSON route for outbound calls

For use from Asterisk
Try auto top up / low balance notify when not enough balance for a call

There is an edge case where a customer might not have auto-topped up yet but
they don't have enough balance for this call, so try to charge their card first
before telling them the call is a no go.
Also supports limits on inbound calls
Outbound call logic for overages

If cannot find an acceptable rate for the number, cannot call.
If balance is too low, cannot call.
If too close to limit, warn.
Else, call.
Add customer_id to outgoing call JSON
Support JSON route pre-limits

This will allow us to switch asterisk to the new logic before rolling out the
limits.  Asterisk will then support the limits once sgx-jmp begins instructing
it about them.
CustomerRepo::QueryKey and CustomerRepo#find_by_format

Introduce objects representing the different kind of query keys that can be used
to look up a customer.  These keys know how to use themselves to get
the (customer_id, jid) pair that is needed for an actual repo lookup.  All
find_by_* methods are now just trivial wrappers over these objects that pass on
to find_inner.

This enables the easy creation of a new helper: QueryKey.for, used as
find_by_format which allows passing an xmpp: URI, or a properly formatted tel,
or a customer id, and will find by the correct one.  This could cause a problem
if a customer id were to be a valid xmpp: URI or a formatted tel, so this method
does assume not using these formats for any customer id (which would be
ill-advised in any case).
End call on hangup
Initial tests for web routes
Allow injecting a customer repo into Web
Fallback should actually happen

This is certainly an accidental holdover from the original code, and was making
voicemail from anon not work at all.
Next