8000 Support StatusCallbackEvent parameter on outbound Calls · damui/twilio-python@95e3d58 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95e3d58

Browse files
committed
Support StatusCallbackEvent parameter on outbound Calls
1 parent f0cfb8d commit 95e3d58

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

tests/test_calls.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,48 @@ def test_create_call(mock):
3232
use_json_extension=True)
3333

3434

35+
@patch("twilio.rest.resources.base.make_twilio_request")
36+
def test_create_call_status_events(mock):
37+
resp = create_mock_json("tests/resources/calls_instance.json")
38+
resp.status_code = 201
39+
mock.return_value = resp
40+
41+
uri = "%s/Calls" % (BASE_URI)
42+
list_resource.create("TO", "FROM", "url",
43+
status_callback="http://example.com",
44+
status_events=['initiated', 'completed'])
45+
exp_params = {
46+
'To': "TO",
47+
'From': "FROM",
48+
'Url': "url",
49+
'StatusCallbackEvent': ['initiated', 'completed'],
50+
'StatusCallback': 'http://example.com',
51+
}
52+
53+
mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH,
54+
use_json_extension=True)
55+
56+
57+
@patch("twilio.rest.resources.base.make_twilio_request")
58+
def test_create_call_status_events_none(mock):
59+
resp = create_mock_json("tests/resources/calls_instance.json")
60+
resp.status_code = 201
61+
mock.return_value = resp
62+
63+
uri = "%s/Calls& 10000 quot; % (BASE_URI)
64+
list_resource.create("TO", "FROM", "url",
65+
status_callback="http://example.com")
66+
exp_params = {
67+
'To': "TO",
68+
'From': "FROM",
69+
'Url': "url",
70+
'StatusCallback': 'http://example.com',
71+
}
72+
73+
mock.assert_called_with("POST", uri, data=exp_params, auth=AUTH,
74+
use_json_extension=True)
75+
76+
3577
@patch("twilio.rest.resources.base.make_twilio_request")
3678
def test_paging(mock):
3779
resp = create_mock_json("tests/resources/calls_list.json")

twilio/rest/resources/calls.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def iter(self, from_=None, ended_after=None,
104104
kwargs["EndTime"] = parse_date(ended)
105105
return super(Calls, self).iter(**kwargs)
106106

107-
def create(self, to, from_, url, status_method=None, **kwargs):
107+
def create(self, to, from_, url, status_method=None, status_events=None,
108+
**kwargs):
108109
"""
109110
Make a phone call to a number.
110111
@@ -123,6 +124,11 @@ def create(self, to, from_, url, status_method=None, **kwargs):
123124
call ends to notify your app.
124125
:param str status_method: The HTTP method Twilio should use when
125126
requesting the above URL.
127+
:param list status_events: A list of call progress events Twilio
128+
should send status callback requests on. One or more of:
129+
'initiated', 'ringing', 'answered', 'completed'. Defaults to
130+
['completed'] if not provided. 'completed' events are sent
131+
free of charge; see twilio.com for current pricing on others.
126132
:param str if_machine: Tell Twilio to try and determine if a machine
127133
(like voicemail) or a human has answered the call.
128134
See more in our `answering machine documentation
@@ -144,6 +150,7 @@ def create(self, to, from_, url, status_method=None, **kwargs):
144150
kwargs["to"] = to
145151
kwargs["url"] = url
146152
kwargs["status_callback_method"] = status_method
153+
kwargs["status_callback_event"] = status_events
147154
return self.create_instance(kwargs)
148155

149156
def update(self, sid, **kwargs):

0 commit comments

Comments
 (0)
0