Skip to content

Commit

Permalink
Merge branch 'feature/dialplan-starts-notification-SH-332'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmendes86 committed Mar 29, 2019
2 parents aada68e + ec9ba6c commit 4bb8f5a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cacofonisk/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, event):
self.fwd_dials = []
self.bridge = None
self.is_originated = False
self.is_calling = False
self.is_calling = self.uniqueid == self.linkedid

# The Custom dict can be used to store custom data.
self.custom = {}
Expand Down
3 changes: 2 additions & 1 deletion cacofonisk/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def on_bridge_enter(self, channel, bridge):
# The rest are will be marked as targets.
for non_caller in sorted_callers:
targets.add(non_caller)
non_caller.is_calling = False
elif len(callers) < 1:
# A call should always have a caller.
self._logger.warning('Call {} has too few callers: {}'.format(
Expand Down Expand Up @@ -832,7 +833,7 @@ def on_user_event(self, event):
Args:
event (dict): Dict-like object with all attributes of the event.
"""
self._reporter.on_user_event(event)
self._reporter.on_user_event(self._channels[event['Uniqueid']].as_namedtuple(), event)

def on_hangup(self, channel, event):
"""
Expand Down
10 changes: 5 additions & 5 deletions cacofonisk/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def on_blind_transfer(self, caller, transferer, targets):
"""
pass

def on_user_event(self, event):
def on_user_event(self, caller, event):
"""
Handle custom UserEvent messages from Asterisk.
Expand Down Expand Up @@ -233,7 +233,7 @@ def on_blind_transfer(self, caller, transferer, targets):
self._logger.info('{} bld xfer: {} <--> {} (through {})'.format(
caller.linkedid, caller, targets, transferer))

def on_user_event(self, event):
def on_user_event(self, caller, event):
"""
Handle custom UserEvent messages from Asterisk.
Expand Down Expand Up @@ -287,11 +287,11 @@ def on_event(self, event):
for reporter in self.reporters:
reporter.on_event(event)

def on_user_event(self, event):
super(MultiReporter, self).on_user_event(event)
def on_user_event(self, caller, event):
super(MultiReporter, self).on_user_event(caller, event)

for reporter in self.reporters:
reporter.on_user_event(event)
reporter.on_user_event(caller, event)

def on_b_dial(self, caller, targets):
super(MultiReporter, self).on_b_dial(caller, targets)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

version = '0.6.0'
version = '0.7.0'

setup(
name='cacofonisk',
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/simple/a_created_no_answer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{"AccountCode": "", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "0", "ChannelStateDesc": "Down", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "voipgrid_in", "Event": "Newchannel", "Exten": "+31150010004", "Language": "en", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "1", "Privilege": "call,all", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "content": ""},
{"AccountCode": "", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "4", "ChannelStateDesc": "Ring", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "voipgrid_in", "Event": "Newstate", "Exten": "+31150010004", "Language": "vg_en_UK_F", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "1", "Privilege": "call,all", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "content": ""},
{"AccountCode": "15001", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "4", "ChannelStateDesc": "Ring", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "osvpi_world", "Event": "NewAccountCode", "Exten": "+31150010004", "Language": "vg_en_UK_F", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "11", "Privilege": "call,all", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "content": ""},
{"AccountCode": "15001", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "4", "ChannelStateDesc": "Ring", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "osvpi_world", "Direction": "inbound", "Event": "UserEvent", "Exten": "+31150010004", "Language": "vg_en_UK_F", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "16", "Privilege": "user,all", "Provider": "webhook", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "UserEvent": "NotifyCallstate", "WebhookUrls": "http://notifications.example.com/data", "content": ""},
{"AccountCode": "15001", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "6", "ChannelStateDesc": "Up", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "osvpi_proc_lazyanswer", "Event": "Newstate", "Exten": "+31150010004", "Language": "vg_en_UK_F", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "2", "Privilege": "call,all", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "content": ""},
{"BridgeCreator": "<unknown>", "BridgeName": "<unknown>", "BridgeNumChannels": "0", "BridgeTechnology": "simple_bridge", "BridgeType": "basic", "BridgeUniqueid": "42ef5a4b-dfa1-4a83-a29d-bd5ffc3c6ef4", "BridgeVideoSourceMode": "none", "Event": "BridgeCreate", "Privilege": "call,all", "SystemName": "e25ad522d444", "content": ""},
{"BridgeCreator": "<unknown>", "BridgeName": "<unknown>", "BridgeNumChannels": "0", "BridgeTechnology": "simple_bridge", "BridgeType": "basic", "BridgeUniqueid": "597a84a3-2db7-4344-b6c4-899360e00ea0", "BridgeVideoSourceMode": "none", "Event": "BridgeCreate", "Privilege": "call,all", "SystemName": "e25ad522d444", "content": ""},
{"BridgeCreator": "<unknown>", "BridgeName": "<unknown>", "BridgeNumChannels": "0", "BridgeTechnology": "simple_bridge", "BridgeType": "basic", "BridgeUniqueid": "597a84a3-2db7-4344-b6c4-899360e00ea0", "BridgeVideoSourceMode": "none", "Event": "BridgeDestroy", "Privilege": "call,all", "SystemName": "e25ad522d444", "content": ""},
{"BridgeCreator": "<unknown>", "BridgeName": "<unknown>", "BridgeNumChannels": "0", "BridgeTechnology": "simple_bridge", "BridgeType": "basic", "BridgeUniqueid": "42ef5a4b-dfa1-4a83-a29d-bd5ffc3c6ef4", "BridgeVideoSourceMode": "none", "Event": "BridgeDestroy", "Privilege": "call,all", "SystemName": "e25ad522d444", "content": ""},
{"AccountCode": "15001", "CallerIDName": "<unknown>", "CallerIDNum": "+31150010001", "Cause": "0", "Cause-txt": "Unknown", "Channel": "SIP/voipgrid-siproute-docker-00000009", "ChannelState": "6", "ChannelStateDesc": "Up", "ConnectedLineName": "<unknown>", "ConnectedLineNum": "<unknown>", "Context": "handlers", "Event": "Hangup", "Exten": "onhangup", "Language": "vg_en_UK_F", "Linkedid": "e25ad522d444-1553503669.94", "Priority": "4", "Privilege": "call,all", "SystemName": "e25ad522d444", "Uniqueid": "e25ad522d444-1553503669.94", "content": ""}
]
4 changes: 2 additions & 2 deletions tests/test_reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_on_event(self):

def test_on_user_event(self):
event_dict = {'Linkedid': '195176c06ab8-1529936170.42'}
self.multi_reporter.on_user_event(event_dict)
self.mock_reporter.on_user_event.assert_called_once_with(event_dict)
self.multi_reporter.on_user_event(self.a_party, event_dict)
self.mock_reporter.on_user_event.assert_called_once_with(self.a_party, event_dict)

def test_on_b_dial(self):
targets = [self.b_party, self.c_party]
Expand Down
28 changes: 28 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,31 @@ def test_ab_out_of_order_dial(self):
]

self.assertEqual(expected_events, events)

def test_a_created_no_answer(self):
"""
Test a simple AB call where the state is changed before the dial.
"""
fixture_file = 'fixtures/simple/a_created_no_answer.json'
events = self.run_and_get_events(fixture_file)

calling_chan = SimpleChannel(
name='SIP/voipgrid-siproute-docker-00000009',
uniqueid='e25ad522d444-1553503669.94',
linkedid='e25ad522d444-1553503669.94',
account_code='15001',
caller_id=CallerId(name='', num='+31150010001'),
cid_calling_pres=None,
connected_line=CallerId(),
exten='+31150010004',
state=6,
)

expected_events = [
('on_hangup', {
'caller': calling_chan,
'reason': 'completed',
}),
]

self.assertEqual(expected_events, events)
2 changes: 1 addition & 1 deletion tests/test_var_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
super(UserEventReporter, self).__init__()
self.events = []

def on_user_event(self, event):
def on_user_event(self, caller, event):
desired = ('UserEvent', 'Provider', 'AccountCode',
'WebhookUrls', 'Direction', 'ClientId',
'AccountInternalNumber', 'UserInternalNumbers')
Expand Down

0 comments on commit 4bb8f5a

Please sign in to comment.