1# coding=utf-8 2r""" 3This code was generated by 4\ / _ _ _| _ _ 5 | (_)\/(_)(_|\/| |(/_ v1.0.0 6 / / 7""" 8 9from twilio.base import deserialize 10from twilio.base import serialize 11from twilio.base import values 12from twilio.base.instance_context import InstanceContext 13from twilio.base.instance_resource import InstanceResource 14from twilio.base.list_resource import ListResource 15from twilio.base.page import Page 16from twilio.rest.api.v2010.account.call.event import EventList 17from twilio.rest.api.v2010.account.call.feedback import FeedbackList 18from twilio.rest.api.v2010.account.call.feedback_summary import FeedbackSummaryList 19from twilio.rest.api.v2010.account.call.notification import NotificationList 20from twilio.rest.api.v2010.account.call.payment import PaymentList 21from twilio.rest.api.v2010.account.call.recording import RecordingList 22from twilio.rest.api.v2010.account.call.siprec import SiprecList 23 24 25class CallList(ListResource): 26 27 def __init__(self, version, account_sid): 28 """ 29 Initialize the CallList 30 31 :param Version version: Version that contains the resource 32 :param account_sid: The SID of the Account that created this resource 33 34 :returns: twilio.rest.api.v2010.account.call.CallList 35 :rtype: twilio.rest.api.v2010.account.call.CallList 36 """ 37 super(CallList, self).__init__(version) 38 39 # Path Solution 40 self._solution = {'account_sid': account_sid, } 41 self._uri = '/Accounts/{account_sid}/Calls.json'.format(**self._solution) 42 43 # Components 44 self._feedback_summaries = None 45 46 def create(self, to, from_, method=values.unset, fallback_url=values.unset, 47 fallback_method=values.unset, status_callback=values.unset, 48 status_callback_event=values.unset, 49 status_callback_method=values.unset, send_digits=values.unset, 50 timeout=values.unset, record=values.unset, 51 recording_channels=values.unset, 52 recording_status_callback=values.unset, 53 recording_status_callback_method=values.unset, 54 sip_auth_username=values.unset, sip_auth_password=values.unset, 55 machine_detection=values.unset, 56 machine_detection_timeout=values.unset, 57 recording_status_callback_event=values.unset, trim=values.unset, 58 caller_id=values.unset, 59 machine_detection_speech_threshold=values.unset, 60 machine_detection_speech_end_threshold=values.unset, 61 machine_detection_silence_timeout=values.unset, 62 async_amd=values.unset, async_amd_status_callback=values.unset, 63 async_amd_status_callback_method=values.unset, byoc=values.unset, 64 call_reason=values.unset, call_token=values.unset, 65 recording_track=values.unset, time_limit=values.unset, 66 url=values.unset, twiml=values.unset, application_sid=values.unset): 67 """ 68 Create the CallInstance 69 70 :param unicode to: Phone number, SIP address, or client identifier to call 71 :param unicode from_: Twilio number from which to originate the call 72 :param unicode method: HTTP method to use to fetch TwiML 73 :param unicode fallback_url: Fallback URL in case of error 74 :param unicode fallback_method: HTTP Method to use with fallback_url 75 :param unicode status_callback: The URL we should call to send status information to your application 76 :param list[unicode] status_callback_event: The call progress events that we send to the `status_callback` URL. 77 :param unicode status_callback_method: HTTP Method to use with status_callback 78 :param unicode send_digits: The digits to dial after connecting to the number 79 :param unicode timeout: Number of seconds to wait for an answer 80 :param bool record: Whether to record the call 81 :param unicode recording_channels: The number of channels in the final recording 82 :param unicode recording_status_callback: The URL that we call when the recording is available to be accessed 83 :param unicode recording_status_callback_method: The HTTP method we should use when calling the `recording_status_callback` URL 84 :param unicode sip_auth_username: The username used to authenticate the caller making a SIP call 85 :param unicode sip_auth_password: The password required to authenticate the user account specified in `sip_auth_username`. 86 :param unicode machine_detection: Enable machine detection or end of greeting detection 87 :param unicode machine_detection_timeout: Number of seconds to wait for machine detection 88 :param list[unicode] recording_status_callback_event: The recording status events that will trigger calls to the URL specified in `recording_status_callback` 89 :param unicode trim: Set this parameter to control trimming of silence on the recording. 90 :param unicode caller_id: The phone number, SIP address, or Client identifier that made this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. 91 :param unicode machine_detection_speech_threshold: Number of milliseconds for measuring stick for the length of the speech activity 92 :param unicode machine_detection_speech_end_threshold: Number of milliseconds of silence after speech activity 93 :param unicode machine_detection_silence_timeout: Number of milliseconds of initial silence 94 :param unicode async_amd: Enable asynchronous AMD 95 :param unicode async_amd_status_callback: The URL we should call to send amd status information to your application 96 :param unicode async_amd_status_callback_method: HTTP Method to use with async_amd_status_callback 97 :param unicode byoc: BYOC trunk SID (Beta) 98 :param unicode call_reason: Reason for the call (Branded Calls Beta) 99 :param unicode call_token: A token string needed to invoke a forwarded call with a CallerId recieved on a previous incoming call 100 :param unicode recording_track: Which track(s) to record 101 :param unicode time_limit: The maximum duration of the call in seconds. 102 :param unicode url: The absolute URL that returns TwiML for this call 103 :param unicode twiml: TwiML instructions for the call 104 :param unicode application_sid: The SID of the Application resource that will handle the call 105 106 :returns: The created CallInstance 107 :rtype: twilio.rest.api.v2010.account.call.CallInstance 108 """ 109 data = values.of({ 110 'To': to, 111 'From': from_, 112 'Url': url, 113 'Twiml': twiml, 114 'ApplicationSid': application_sid, 115 'Method': method, 116 'FallbackUrl': fallback_url, 117 'FallbackMethod': fallback_method, 118 'StatusCallback': status_callback, 119 'StatusCallbackEvent': serialize.map(status_callback_event, lambda e: e), 120 'StatusCallbackMethod': status_callback_method, 121 'SendDigits': send_digits, 122 'Timeout': timeout, 123 'Record': record, 124 'RecordingChannels': recording_channels, 125 'RecordingStatusCallback': recording_status_callback, 126 'RecordingStatusCallbackMethod': recording_status_callback_method, 127 'SipAuthUsername': sip_auth_username, 128 'SipAuthPassword': sip_auth_password, 129 'MachineDetection': machine_detection, 130 'MachineDetectionTimeout': machine_detection_timeout, 131 'RecordingStatusCallbackEvent': serialize.map(recording_status_callback_event, lambda e: e), 132 'Trim': trim, 133 'CallerId': caller_id, 134 'MachineDetectionSpeechThreshold': machine_detection_speech_threshold, 135 'MachineDetectionSpeechEndThreshold': machine_detection_speech_end_threshold, 136 'MachineDetectionSilenceTimeout': machine_detection_silence_timeout, 137 'AsyncAmd': async_amd, 138 'AsyncAmdStatusCallback': async_amd_status_callback, 139 'AsyncAmdStatusCallbackMethod': async_amd_status_callback_method, 140 'Byoc': byoc, 141 'CallReason': call_reason, 142 'CallToken': call_token, 143 'RecordingTrack': recording_track, 144 'TimeLimit': time_limit, 145 }) 146 147 payload = self._version.create(method='POST', uri=self._uri, data=data, ) 148 149 return CallInstance(self._version, payload, account_sid=self._solution['account_sid'], ) 150 151 def stream(self, to=values.unset, from_=values.unset, 152 parent_call_sid=values.unset, status=values.unset, 153 start_time_before=values.unset, start_time=values.unset, 154 start_time_after=values.unset, end_time_before=values.unset, 155 end_time=values.unset, end_time_after=values.unset, limit=None, 156 page_size=None): 157 """ 158 Streams CallInstance records from the API as a generator stream. 159 This operation lazily loads records as efficiently as possible until the limit 160 is reached. 161 The results are returned as a generator, so this operation is memory efficient. 162 163 :param unicode to: Phone number or Client identifier of calls to include 164 :param unicode from_: Phone number or Client identifier to filter `from` on 165 :param unicode parent_call_sid: Parent call SID to filter on 166 :param CallInstance.Status status: The status of the resources to read 167 :param datetime start_time_before: Only include calls that started on this date 168 :param datetime start_time: Only include calls that started on this date 169 :param datetime start_time_after: Only include calls that started on this date 170 :param datetime end_time_before: Only include calls that ended on this date 171 :param datetime end_time: Only include calls that ended on this date 172 :param datetime end_time_after: Only include calls that ended on this date 173 :param int limit: Upper limit for the number of records to return. stream() 174 guarantees to never return more than limit. Default is no limit 175 :param int page_size: Number of records to fetch per request, when not set will use 176 the default value of 50 records. If no page_size is defined 177 but a limit is defined, stream() will attempt to read the 178 limit with the most efficient page size, i.e. min(limit, 1000) 179 180 :returns: Generator that will yield up to limit results 181 :rtype: list[twilio.rest.api.v2010.account.call.CallInstance] 182 """ 183 limits = self._version.read_limits(limit, page_size) 184 185 page = self.page( 186 to=to, 187 from_=from_, 188 parent_call_sid=parent_call_sid, 189 status=status, 190 start_time_before=start_time_before, 191 start_time=start_time, 192 start_time_after=start_time_after, 193 end_time_before=end_time_before, 194 end_time=end_time, 195 end_time_after=end_time_after, 196 page_size=limits['page_size'], 197 ) 198 199 return self._version.stream(page, limits['limit']) 200 201 def list(self, to=values.unset, from_=values.unset, 202 parent_call_sid=values.unset, status=values.unset, 203 start_time_before=values.unset, start_time=values.unset, 204 start_time_after=values.unset, end_time_before=values.unset, 205 end_time=values.unset, end_time_after=values.unset, limit=None, 206 page_size=None): 207 """ 208 Lists CallInstance records from the API as a list. 209 Unlike stream(), this operation is eager and will load `limit` records into 210 memory before returning. 211 212 :param unicode to: Phone number or Client identifier of calls to include 213 :param unicode from_: Phone number or Client identifier to filter `from` on 214 :param unicode parent_call_sid: Parent call SID to filter on 215 :param CallInstance.Status status: The status of the resources to read 216 :param datetime start_time_before: Only include calls that started on this date 217 :param datetime start_time: Only include calls that started on this date 218 :param datetime start_time_after: Only include calls that started on this date 219 :param datetime end_time_before: Only include calls that ended on this date 220 :param datetime end_time: Only include calls that ended on this date 221 :param datetime end_time_after: Only include calls that ended on this date 222 :param int limit: Upper limit for the number of records to return. list() guarantees 223 never to return more than limit. Default is no limit 224 :param int page_size: Number of records to fetch per request, when not set will use 225 the default value of 50 records. If no page_size is defined 226 but a limit is defined, list() will attempt to read the limit 227 with the most efficient page size, i.e. min(limit, 1000) 228 229 :returns: Generator that will yield up to limit results 230 :rtype: list[twilio.rest.api.v2010.account.call.CallInstance] 231 """ 232 return list(self.stream( 233 to=to, 234 from_=from_, 235 parent_call_sid=parent_call_sid, 236 status=status, 237 start_time_before=start_time_before, 238 start_time=start_time, 239 start_time_after=start_time_after, 240 end_time_before=end_time_before, 241 end_time=end_time, 242 end_time_after=end_time_after, 243 limit=limit, 244 page_size=page_size, 245 )) 246 247 def page(self, to=values.unset, from_=values.unset, 248 parent_call_sid=values.unset, status=values.unset, 249 start_time_before=values.unset, start_time=values.unset, 250 start_time_after=values.unset, end_time_before=values.unset, 251 end_time=values.unset, end_time_after=values.unset, 252 page_token=values.unset, page_number=values.unset, 253 page_size=values.unset): 254 """ 255 Retrieve a single page of CallInstance records from the API. 256 Request is executed immediately 257 258 :param unicode to: Phone number or Client identifier of calls to include 259 :param unicode from_: Phone number or Client identifier to filter `from` on 260 :param unicode parent_call_sid: Parent call SID to filter on 261 :param CallInstance.Status status: The status of the resources to read 262 :param datetime start_time_before: Only include calls that started on this date 263 :param datetime start_time: Only include calls that started on this date 264 :param datetime start_time_after: Only include calls that started on this date 265 :param datetime end_time_before: Only include calls that ended on this date 266 :param datetime end_time: Only include calls that ended on this date 267 :param datetime end_time_after: Only include calls that ended on this date 268 :param str page_token: PageToken provided by the API 269 :param int page_number: Page Number, this value is simply for client state 270 :param int page_size: Number of records to return, defaults to 50 271 272 :returns: Page of CallInstance 273 :rtype: twilio.rest.api.v2010.account.call.CallPage 274 """ 275 data = values.of({ 276 'To': to, 277 'From': from_, 278 'ParentCallSid': parent_call_sid, 279 'Status': status, 280 'StartTime<': serialize.iso8601_datetime(start_time_before), 281 'StartTime': serialize.iso8601_datetime(start_time), 282 'StartTime>': serialize.iso8601_datetime(start_time_after), 283 'EndTime<': serialize.iso8601_datetime(end_time_before), 284 'EndTime': serialize.iso8601_datetime(end_time), 285 'EndTime>': serialize.iso8601_datetime(end_time_after), 286 'PageToken': page_token, 287 'Page': page_number, 288 'PageSize': page_size, 289 }) 290 291 response = self._version.page(method='GET', uri=self._uri, params=data, ) 292 293 return CallPage(self._version, response, self._solution) 294 295 def get_page(self, target_url): 296 """ 297 Retrieve a specific page of CallInstance records from the API. 298 Request is executed immediately 299 300 :param str target_url: API-generated URL for the requested results page 301 302 :returns: Page of CallInstance 303 :rtype: twilio.rest.api.v2010.account.call.CallPage 304 """ 305 response = self._version.domain.twilio.request( 306 'GET', 307 target_url, 308 ) 309 310 return CallPage(self._version, response, self._solution) 311 312 @property 313 def feedback_summaries(self): 314 """ 315 Access the feedback_summaries 316 317 :returns: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryList 318 :rtype: twilio.rest.api.v2010.account.call.feedback_summary.FeedbackSummaryList 319 """ 320 if self._feedback_summaries is None: 321 self._feedback_summaries = FeedbackSummaryList( 322 self._version, 323 account_sid=self._solution['account_sid'], 324 ) 325 return self._feedback_summaries 326 327 def get(self, sid): 328 """ 329 Constructs a CallContext 330 331 :param sid: The SID of the Call resource to fetch 332 333 :returns: twilio.rest.api.v2010.account.call.CallContext 334 :rtype: twilio.rest.api.v2010.account.call.CallContext 335 """ 336 return CallContext(self._version, account_sid=self._solution['account_sid'], sid=sid, ) 337 338 def __call__(self, sid): 339 """ 340 Constructs a CallContext 341 342 :param sid: The SID of the Call resource to fetch 343 344 :returns: twilio.rest.api.v2010.account.call.CallContext 345 :rtype: twilio.rest.api.v2010.account.call.CallContext 346 """ 347 return CallContext(self._version, account_sid=self._solution['account_sid'], sid=sid, ) 348 349 def __repr__(self): 350 """ 351 Provide a friendly representation 352 353 :returns: Machine friendly representation 354 :rtype: str 355 """ 356 return '<Twilio.Api.V2010.CallList>' 357 358 359class CallPage(Page): 360 361 def __init__(self, version, response, solution): 362 """ 363 Initialize the CallPage 364 365 :param Version version: Version that contains the resource 366 :param Response response: Response from the API 367 :param account_sid: The SID of the Account that created this resource 368 369 :returns: twilio.rest.api.v2010.account.call.CallPage 370 :rtype: twilio.rest.api.v2010.account.call.CallPage 371 """ 372 super(CallPage, self).__init__(version, response) 373 374 # Path Solution 375 self._solution = solution 376 377 def get_instance(self, payload): 378 """ 379 Build an instance of CallInstance 380 381 :param dict payload: Payload response from the API 382 383 :returns: twilio.rest.api.v2010.account.call.CallInstance 384 :rtype: twilio.rest.api.v2010.account.call.CallInstance 385 """ 386 return CallInstance(self._version, payload, account_sid=self._solution['account_sid'], ) 387 388 def __repr__(self): 389 """ 390 Provide a friendly representation 391 392 :returns: Machine friendly representation 393 :rtype: str 394 """ 395 return '<Twilio.Api.V2010.CallPage>' 396 397 398class CallContext(InstanceContext): 399 400 def __init__(self, version, account_sid, sid): 401 """ 402 Initialize the CallContext 403 404 :param Version version: Version that contains the resource 405 :param account_sid: The SID of the Account that created the resource(s) to fetch 406 :param sid: The SID of the Call resource to fetch 407 408 :returns: twilio.rest.api.v2010.account.call.CallContext 409 :rtype: twilio.rest.api.v2010.account.call.CallContext 410 """ 411 super(CallContext, self).__init__(version) 412 413 # Path Solution 414 self._solution = {'account_sid': account_sid, 'sid': sid, } 415 self._uri = '/Accounts/{account_sid}/Calls/{sid}.json'.format(**self._solution) 416 417 # Dependents 418 self._recordings = None 419 self._notifications = None 420 self._feedback = None 421 self._events = None 422 self._payments = None 423 self._siprec = None 424 425 def delete(self): 426 """ 427 Deletes the CallInstance 428 429 :returns: True if delete succeeds, False otherwise 430 :rtype: bool 431 """ 432 return self._version.delete(method='DELETE', uri=self._uri, ) 433 434 def fetch(self): 435 """ 436 Fetch the CallInstance 437 438 :returns: The fetched CallInstance 439 :rtype: twilio.rest.api.v2010.account.call.CallInstance 440 """ 441 payload = self._version.fetch(method='GET', uri=self._uri, ) 442 443 return CallInstance( 444 self._version, 445 payload, 446 account_sid=self._solution['account_sid'], 447 sid=self._solution['sid'], 448 ) 449 450 def update(self, url=values.unset, method=values.unset, status=values.unset, 451 fallback_url=values.unset, fallback_method=values.unset, 452 status_callback=values.unset, status_callback_method=values.unset, 453 twiml=values.unset, time_limit=values.unset): 454 """ 455 Update the CallInstance 456 457 :param unicode url: The absolute URL that returns TwiML for this call 458 :param unicode method: HTTP method to use to fetch TwiML 459 :param CallInstance.UpdateStatus status: The new status to update the call with. 460 :param unicode fallback_url: Fallback URL in case of error 461 :param unicode fallback_method: HTTP Method to use with fallback_url 462 :param unicode status_callback: The URL we should call to send status information to your application 463 :param unicode status_callback_method: HTTP Method to use to call status_callback 464 :param unicode twiml: TwiML instructions for the call 465 :param unicode time_limit: The maximum duration of the call in seconds. 466 467 :returns: The updated CallInstance 468 :rtype: twilio.rest.api.v2010.account.call.CallInstance 469 """ 470 data = values.of({ 471 'Url': url, 472 'Method': method, 473 'Status': status, 474 'FallbackUrl': fallback_url, 475 'FallbackMethod': fallback_method, 476 'StatusCallback': status_callback, 477 'StatusCallbackMethod': status_callback_method, 478 'Twiml': twiml, 479 'TimeLimit': time_limit, 480 }) 481 482 payload = self._version.update(method='POST', uri=self._uri, data=data, ) 483 484 return CallInstance( 485 self._version, 486 payload, 487 account_sid=self._solution['account_sid'], 488 sid=self._solution['sid'], 489 ) 490 491 @property 492 def recordings(self): 493 """ 494 Access the recordings 495 496 :returns: twilio.rest.api.v2010.account.call.recording.RecordingList 497 :rtype: twilio.rest.api.v2010.account.call.recording.RecordingList 498 """ 499 if self._recordings is None: 500 self._recordings = RecordingList( 501 self._version, 502 account_sid=self._solution['account_sid'], 503 call_sid=self._solution['sid'], 504 ) 505 return self._recordings 506 507 @property 508 def notifications(self): 509 """ 510 Access the notifications 511 512 :returns: twilio.rest.api.v2010.account.call.notification.NotificationList 513 :rtype: twilio.rest.api.v2010.account.call.notification.NotificationList 514 """ 515 if self._notifications is None: 516 self._notifications = NotificationList( 517 self._version, 518 account_sid=self._solution['account_sid'], 519 call_sid=self._solution['sid'], 520 ) 521 return self._notifications 522 523 @property 524 def feedback(self): 525 """ 526 Access the feedback 527 528 :returns: twilio.rest.api.v2010.account.call.feedback.FeedbackList 529 :rtype: twilio.rest.api.v2010.account.call.feedback.FeedbackList 530 """ 531 if self._feedback is None: 532 self._feedback = FeedbackList( 533 self._version, 534 account_sid=self._solution['account_sid'], 535 call_sid=self._solution['sid'], 536 ) 537 return self._feedback 538 539 @property 540 def events(self): 541 """ 542 Access the events 543 544 :returns: twilio.rest.api.v2010.account.call.event.EventList 545 :rtype: twilio.rest.api.v2010.account.call.event.EventList 546 """ 547 if self._events is None: 548 self._events = EventList( 549 self._version, 550 account_sid=self._solution['account_sid'], 551 call_sid=self._solution['sid'], 552 ) 553 return self._events 554 555 @property 556 def payments(self): 557 """ 558 Access the payments 559 560 :returns: twilio.rest.api.v2010.account.call.payment.PaymentList 561 :rtype: twilio.rest.api.v2010.account.call.payment.PaymentList 562 """ 563 if self._payments is None: 564 self._payments = PaymentList( 565 self._version, 566 account_sid=self._solution['account_sid'], 567 call_sid=self._solution['sid'], 568 ) 569 return self._payments 570 571 @property 572 def siprec(self): 573 """ 574 Access the siprec 575 576 :returns: twilio.rest.api.v2010.account.call.siprec.SiprecList 577 :rtype: twilio.rest.api.v2010.account.call.siprec.SiprecList 578 """ 579 if self._siprec is None: 580 self._siprec = SiprecList( 581 self._version, 582 account_sid=self._solution['account_sid'], 583 call_sid=self._solution['sid'], 584 ) 585 return self._siprec 586 587 def __repr__(self): 588 """ 589 Provide a friendly representation 590 591 :returns: Machine friendly representation 592 :rtype: str 593 """ 594 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 595 return '<Twilio.Api.V2010.CallContext {}>'.format(context) 596 597 598class CallInstance(InstanceResource): 599 600 class Event(object): 601 INITIATED = "initiated" 602 RINGING = "ringing" 603 ANSWERED = "answered" 604 COMPLETED = "completed" 605 606 class Status(object): 607 QUEUED = "queued" 608 RINGING = "ringing" 609 IN_PROGRESS = "in-progress" 610 COMPLETED = "completed" 611 BUSY = "busy" 612 FAILED = "failed" 613 NO_ANSWER = "no-answer" 614 CANCELED = "canceled" 615 616 class UpdateStatus(object): 617 CANCELED = "canceled" 618 COMPLETED = "completed" 619 620 def __init__(self, version, payload, account_sid, sid=None): 621 """ 622 Initialize the CallInstance 623 624 :returns: twilio.rest.api.v2010.account.call.CallInstance 625 :rtype: twilio.rest.api.v2010.account.call.CallInstance 626 """ 627 super(CallInstance, self).__init__(version) 628 629 # Marshaled Properties 630 self._properties = { 631 'sid': payload.get('sid'), 632 'date_created': deserialize.rfc2822_datetime(payload.get('date_created')), 633 'date_updated': deserialize.rfc2822_datetime(payload.get('date_updated')), 634 'parent_call_sid': payload.get('parent_call_sid'), 635 'account_sid': payload.get('account_sid'), 636 'to': payload.get('to'), 637 'to_formatted': payload.get('to_formatted'), 638 'from_': payload.get('from'), 639 'from_formatted': payload.get('from_formatted'), 640 'phone_number_sid': payload.get('phone_number_sid'), 641 'status': payload.get('status'), 642 'start_time': deserialize.rfc2822_datetime(payload.get('start_time')), 643 'end_time': deserialize.rfc2822_datetime(payload.get('end_time')), 644 'duration': payload.get('duration'), 645 'price': payload.get('price'), 646 'price_unit': payload.get('price_unit'), 647 'direction': payload.get('direction'), 648 'answered_by': payload.get('answered_by'), 649 'annotation': payload.get('annotation'), 650 'api_version': payload.get('api_version'), 651 'forwarded_from': payload.get('forwarded_from'), 652 'group_sid': payload.get('group_sid'), 653 'caller_name': payload.get('caller_name'), 654 'queue_time': payload.get('queue_time'), 655 'trunk_sid': payload.get('trunk_sid'), 656 'uri': payload.get('uri'), 657 'subresource_uris': payload.get('subresource_uris'), 658 } 659 660 # Context 661 self._context = None 662 self._solution = {'account_sid': account_sid, 'sid': sid or self._properties['sid'], } 663 664 @property 665 def _proxy(self): 666 """ 667 Generate an instance context for the instance, the context is capable of 668 performing various actions. All instance actions are proxied to the context 669 670 :returns: CallContext for this CallInstance 671 :rtype: twilio.rest.api.v2010.account.call.CallContext 672 """ 673 if self._context is None: 674 self._context = CallContext( 675 self._version, 676 account_sid=self._solution['account_sid'], 677 sid=self._solution['sid'], 678 ) 679 return self._context 680 681 @property 682 def sid(self): 683 """ 684 :returns: The unique string that identifies this resource 685 :rtype: unicode 686 """ 687 return self._properties['sid'] 688 689 @property 690 def date_created(self): 691 """ 692 :returns: The RFC 2822 date and time in GMT that this resource was created 693 :rtype: datetime 694 """ 695 return self._properties['date_created'] 696 697 @property 698 def date_updated(self): 699 """ 700 :returns: The RFC 2822 date and time in GMT that this resource was last updated 701 :rtype: datetime 702 """ 703 return self._properties['date_updated'] 704 705 @property 706 def parent_call_sid(self): 707 """ 708 :returns: The SID that identifies the call that created this leg. 709 :rtype: unicode 710 """ 711 return self._properties['parent_call_sid'] 712 713 @property 714 def account_sid(self): 715 """ 716 :returns: The SID of the Account that created this resource 717 :rtype: unicode 718 """ 719 return self._properties['account_sid'] 720 721 @property 722 def to(self): 723 """ 724 :returns: The phone number, SIP address or Client identifier that received this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. Client identifiers are formatted `client:name`. 725 :rtype: unicode 726 """ 727 return self._properties['to'] 728 729 @property 730 def to_formatted(self): 731 """ 732 :returns: The phone number, SIP address or Client identifier that received this call. Formatted for display. 733 :rtype: unicode 734 """ 735 return self._properties['to_formatted'] 736 737 @property 738 def from_(self): 739 """ 740 :returns: The phone number, SIP address or Client identifier that made this call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. Client identifiers are formatted `client:name`. 741 :rtype: unicode 742 """ 743 return self._properties['from_'] 744 745 @property 746 def from_formatted(self): 747 """ 748 :returns: The calling phone number, SIP address, or Client identifier formatted for display. 749 :rtype: unicode 750 """ 751 return self._properties['from_formatted'] 752 753 @property 754 def phone_number_sid(self): 755 """ 756 :returns: If the call was inbound, this is the SID of the IncomingPhoneNumber resource that received the call. If the call was outbound, it is the SID of the OutgoingCallerId resource from which the call was placed. 757 :rtype: unicode 758 """ 759 return self._properties['phone_number_sid'] 760 761 @property 762 def status(self): 763 """ 764 :returns: The status of this call. 765 :rtype: CallInstance.Status 766 """ 767 return self._properties['status'] 768 769 @property 770 def start_time(self): 771 """ 772 :returns: The start time of the call. Null if the call has not yet been dialed. 773 :rtype: datetime 774 """ 775 return self._properties['start_time'] 776 777 @property 778 def end_time(self): 779 """ 780 :returns: The end time of the call. Null if the call did not complete successfully. 781 :rtype: datetime 782 """ 783 return self._properties['end_time'] 784 785 @property 786 def duration(self): 787 """ 788 :returns: The length of the call in seconds. 789 :rtype: unicode 790 """ 791 return self._properties['duration'] 792 793 @property 794 def price(self): 795 """ 796 :returns: The charge for this call, in the currency associated with the account. Populated after the call is completed. May not be immediately available. 797 :rtype: unicode 798 """ 799 return self._properties['price'] 800 801 @property 802 def price_unit(self): 803 """ 804 :returns: The currency in which `Price` is measured. 805 :rtype: unicode 806 """ 807 return self._properties['price_unit'] 808 809 @property 810 def direction(self): 811 """ 812 :returns: A string describing the direction of the call. `inbound` for inbound calls, `outbound-api` for calls initiated via the REST API or `outbound-dial` for calls initiated by a `Dial` verb. 813 :rtype: unicode 814 """ 815 return self._properties['direction'] 816 817 @property 818 def answered_by(self): 819 """ 820 :returns: Either `human` or `machine` if this call was initiated with answering machine detection. Empty otherwise. 821 :rtype: unicode 822 """ 823 return self._properties['answered_by'] 824 825 @property 826 def annotation(self): 827 """ 828 :returns: The annotation provided for the call 829 :rtype: unicode 830 """ 831 return self._properties['annotation'] 832 833 @property 834 def api_version(self): 835 """ 836 :returns: The API Version used to create the call 837 :rtype: unicode 838 """ 839 return self._properties['api_version'] 840 841 @property 842 def forwarded_from(self): 843 """ 844 :returns: The forwarding phone number if this call was an incoming call forwarded from another number (depends on carrier supporting forwarding). Otherwise, empty. 845 :rtype: unicode 846 """ 847 return self._properties['forwarded_from'] 848 849 @property 850 def group_sid(self): 851 """ 852 :returns: The Group SID associated with this call. If no Group is associated with the call, the field is empty. 853 :rtype: unicode 854 """ 855 return self._properties['group_sid'] 856 857 @property 858 def caller_name(self): 859 """ 860 :returns: The caller's name if this call was an incoming call to a phone number with caller ID Lookup enabled. Otherwise, empty. 861 :rtype: unicode 862 """ 863 return self._properties['caller_name'] 864 865 @property 866 def queue_time(self): 867 """ 868 :returns: The wait time in milliseconds before the call is placed. 869 :rtype: unicode 870 """ 871 return self._properties['queue_time'] 872 873 @property 874 def trunk_sid(self): 875 """ 876 :returns: The (optional) unique identifier of the trunk resource that was used for this call. 877 :rtype: unicode 878 """ 879 return self._properties['trunk_sid'] 880 881 @property 882 def uri(self): 883 """ 884 :returns: The URI of this resource, relative to `https://api.twilio.com` 885 :rtype: unicode 886 """ 887 return self._properties['uri'] 888 889 @property 890 def subresource_uris(self): 891 """ 892 :returns: A list of related subresources identified by their relative URIs 893 :rtype: unicode 894 """ 895 return self._properties['subresource_uris'] 896 897 def delete(self): 898 """ 899 Deletes the CallInstance 900 901 :returns: True if delete succeeds, False otherwise 902 :rtype: bool 903 """ 904 return self._proxy.delete() 905 906 def fetch(self): 907 """ 908 Fetch the CallInstance 909 910 :returns: The fetched CallInstance 911 :rtype: twilio.rest.api.v2010.account.call.CallInstance 912 """ 913 return self._proxy.fetch() 914 915 def update(self, url=values.unset, method=values.unset, status=values.unset, 916 fallback_url=values.unset, fallback_method=values.unset, 917 status_callback=values.unset, status_callback_method=values.unset, 918 twiml=values.unset, time_limit=values.unset): 919 """ 920 Update the CallInstance 921 922 :param unicode url: The absolute URL that returns TwiML for this call 923 :param unicode method: HTTP method to use to fetch TwiML 924 :param CallInstance.UpdateStatus status: The new status to update the call with. 925 :param unicode fallback_url: Fallback URL in case of error 926 :param unicode fallback_method: HTTP Method to use with fallback_url 927 :param unicode status_callback: The URL we should call to send status information to your application 928 :param unicode status_callback_method: HTTP Method to use to call status_callback 929 :param unicode twiml: TwiML instructions for the call 930 :param unicode time_limit: The maximum duration of the call in seconds. 931 932 :returns: The updated CallInstance 933 :rtype: twilio.rest.api.v2010.account.call.CallInstance 934 """ 935 return self._proxy.update( 936 url=url, 937 method=method, 938 status=status, 939 fallback_url=fallback_url, 940 fallback_method=fallback_method, 941 status_callback=status_callback, 942 status_callback_method=status_callback_method, 943 twiml=twiml, 944 time_limit=time_limit, 945 ) 946 947 @property 948 def recordings(self): 949 """ 950 Access the recordings 951 952 :returns: twilio.rest.api.v2010.account.call.recording.RecordingList 953 :rtype: twilio.rest.api.v2010.account.call.recording.RecordingList 954 """ 955 return self._proxy.recordings 956 957 @property 958 def notifications(self): 959 """ 960 Access the notifications 961 962 :returns: twilio.rest.api.v2010.account.call.notification.NotificationList 963 :rtype: twilio.rest.api.v2010.account.call.notification.NotificationList 964 """ 965 return self._proxy.notifications 966 967 @property 968 def feedback(self): 969 """ 970 Access the feedback 971 972 :returns: twilio.rest.api.v2010.account.call.feedback.FeedbackList 973 :rtype: twilio.rest.api.v2010.account.call.feedback.FeedbackList 974 """ 975 return self._proxy.feedback 976 977 @property 978 def events(self): 979 """ 980 Access the events 981 982 :returns: twilio.rest.api.v2010.account.call.event.EventList 983 :rtype: twilio.rest.api.v2010.account.call.event.EventList 984 """ 985 return self._proxy.events 986 987 @property 988 def payments(self): 989 """ 990 Access the payments 991 992 :returns: twilio.rest.api.v2010.account.call.payment.PaymentList 993 :rtype: twilio.rest.api.v2010.account.call.payment.PaymentList 994 """ 995 return self._proxy.payments 996 997 @property 998 def siprec(self): 999 """ 1000 Access the siprec 1001 1002 :returns: twilio.rest.api.v2010.account.call.siprec.SiprecList 1003 :rtype: twilio.rest.api.v2010.account.call.siprec.SiprecList 1004 """ 1005 return self._proxy.siprec 1006 1007 def __repr__(self): 1008 """ 1009 Provide a friendly representation 1010 1011 :returns: Machine friendly representation 1012 :rtype: str 1013 """ 1014 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 1015 return '<Twilio.Api.V2010.CallInstance {}>'.format(context) 1016