|
| 1 | +""" |
| 2 | +gather.py |
| 3 | +
|
| 4 | +Bandwidth's Gather BXML verb |
| 5 | +
|
| 6 | +@copyright Bandwidth INC |
| 7 | +""" |
| 8 | +from typing import Union, List |
| 9 | +from ..verb import Verb |
| 10 | +from .play_audio import PlayAudio |
| 11 | +from .speak_sentence import SpeakSentence |
| 12 | + |
| 13 | + |
| 14 | +class Gather(Verb): |
| 15 | + |
| 16 | + def __init__( |
| 17 | + self, audio_verbs: List[Union[PlayAudio, SpeakSentence]] = [], |
| 18 | + gather_url: str=None, gather_method: str=None, |
| 19 | + gather_fallback_url: str=None, gather_fallback_method: str=None, |
| 20 | + username: str=None, password: str=None, |
| 21 | + fallback_username: str=None, fallback_password: str=None, |
| 22 | + tag: str=None, terminating_digits: str=None, |
| 23 | + max_digits: str=None, inter_digit_timeout: str=None, |
| 24 | + first_digit_timeout: str=None, repeat_count: str=None |
| 25 | + ): |
| 26 | + """Initialize a <Gather> verb |
| 27 | +
|
| 28 | + Args: |
| 29 | + gather_url (str, optional): URL to send Gather event to and request new BXML. May be a relative URL. |
| 30 | + gather_method (str, optional): The HTTP method to use for the request to gather_url. GET or POST. Default value is POST. |
| 31 | + gather_fallback_url (str, optional): A fallback url which, if provided, will be used to retry the Gather event callback delivery in case gather_url fails to respond. |
| 32 | + gather_fallback_method (str, optional): The HTTP method to use to deliver the Gather event callback to gather_fallback_url. GET or POST. Default value is POST. |
| 33 | + username (str, optional): The username to send in the HTTP request to gather_url. |
| 34 | + password (str, optional): The password to send in the HTTP request to gather_url. |
| 35 | + fallback_username (str, optional): The username to send in the HTTP request to gather_fallback_url. |
| 36 | + fallback_password (str, optional): The password to send in the HTTP request to gather_fallback_url. |
| 37 | + tag (str, optional): A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or <Tag> verb, or cleared. |
| 38 | + May be cleared by setting tag="". Max length 256 characters. |
| 39 | + terminating_digits (str, optional): When any of these digits are pressed, it will terminate the Gather. Default value is "", which disables this feature. |
| 40 | + max_digits (str, optional): Max number of digits to collect. Default value is 50. Range: decimal values between 1 - 50. |
| 41 | + inter_digit_timeout (str, optional): Time (in seconds) allowed between digit presses before automatically terminating the Gather. Default value is 5. Range: decimal values between 1 - 60. |
| 42 | + first_digit_timeout (str, optional): Time (in seconds) to pause after any audio from nested <SpeakSentence> or <PlayAudio> verb is played (in seconds) before terminating the Gather. |
| 43 | + Default value is 5. Range: decimal values between 0 - 60. |
| 44 | + repeat_count (str, optional): The number of times the audio prompt should be played if no digits are pressed. For example, if this value is 3, the nested audio clip will be played a maximum of three times. |
| 45 | + The delay between repetitions will be equal to first_digit_timeout. Default value is 1. repeat_count * number of verbs must not be greater than 20. |
| 46 | +
|
| 47 | + Nested Verbs: |
| 48 | + PlayAudio: (optional) Using the PlayAudio inside the Gather verb will play the media until a digit is received. |
| 49 | + SpeakSentence: (optional) Using the SpeakSentence inside the Gather verb will speak the text until a digit is received. |
| 50 | + """ |
| 51 | + self.gather_url = gather_url |
| 52 | + self.gather_method = gather_method |
| 53 | + self.gather_fallback_url = gather_fallback_url |
| 54 | + self.gather_fallback_method = gather_fallback_method |
| 55 | + self.username = username |
| 56 | + self.password = password |
| 57 | + self.fallback_username = fallback_username |
| 58 | + self.fallback_password = fallback_password |
| 59 | + self.tag = tag |
| 60 | + self.terminating_digits = terminating_digits |
| 61 | + self.max_digits = max_digits |
| 62 | + self.inter_digit_timeout = inter_digit_timeout |
| 63 | + self.first_digit_timeout = first_digit_timeout |
| 64 | + self.repeat_count = repeat_count |
| 65 | + self.audio_verbs = audio_verbs |
| 66 | + super().__init__( |
| 67 | + tag="Gather", |
| 68 | + nested_verbs=self.audio_verbs) |
| 69 | + |
| 70 | + @property |
| 71 | + def _attributes(self): |
| 72 | + return { |
| 73 | + "gatherUrl": self.gather_url, |
| 74 | + "gatherMethod": self.gather_method, |
| 75 | + "gatherFallbackUrl": self.gather_fallback_url, |
| 76 | + "gatherFallbackMethod": self.gather_fallback_method, |
| 77 | + "username": self.username, |
| 78 | + "password": self.password, |
| 79 | + "fallbackUsername": self.fallback_username, |
| 80 | + "fallbackPassword": self.fallback_password, |
| 81 | + "tag": self.tag, |
| 82 | + "terminatingDigits": self.terminating_digits, |
| 83 | + "maxDigits": self.max_digits, |
| 84 | + "interDigitTimeout": self.inter_digit_timeout, |
| 85 | + "firstDigitTimeout": self.first_digit_timeout, |
| 86 | + "repeatCount": self.repeat_count, |
| 87 | + } |
0 commit comments