/src/Plivo/XML/MultiPartyCall.php

https://github.com/plivo/plivohelper-php · PHP · 223 lines · 208 code · 5 blank · 10 comment · 36 complexity · d57256d3c8e8d006bcad9e723214a380 MD5 · raw file

  1. <?php
  2. namespace Plivo\XML;
  3. use Plivo\Exceptions\PlivoXMLException;
  4. use Plivo\Util\MPCUtils;
  5. /**
  6. * Class Conference
  7. * @package Plivo\XML
  8. */
  9. class MultiPartyCall extends Element {
  10. protected $nestables = [];
  11. protected $valid_attributes = [
  12. 'role', 'maxDuration', 'maxParticipants', 'waitMusicUrl',
  13. 'waitMusicMethod', 'agentHoldMusicUrl', 'agentHoldMusicMethod',
  14. 'customerHoldMusicUrl', 'customerHoldMusicMethod', 'record',
  15. 'recordFileFormat', 'recordingCallbackUrl', 'recordingCallbackMethod',
  16. 'statusCallbackEvents', 'statusCallbackUrl', 'statusCallbackMethod',
  17. 'stayAlone', 'coachMode', 'mute', 'hold', 'startMpcOnEnter', 'endMpcOnExit',
  18. 'enterSound', 'enterSoundMethod', 'exitSound', 'exitSoundMethod',
  19. 'onExitActionUrl', 'onExitActionMethod', 'relayDTMFInputs',
  20. 'startRecordingAudio', 'startRecordingAudioMethod', 'stopRecordingAudio', 'stopRecordingAudioMethod',
  21. 'recordMinMemberCount'
  22. ];
  23. /**
  24. * Conference constructor.
  25. * @param string $body
  26. * @param array $attributes
  27. * @throws PlivoXMLException
  28. */
  29. function __construct($body, $attributes = []) {
  30. parent::__construct($body, $attributes);
  31. $VALID_ROLE_VALUES = ['agent', 'supervisor', 'customer'];
  32. $VALID_METHOD_VALUES = ['GET', 'POST'];
  33. $VALID_RECORD_FILE_FORMAT_VALUES = ['mp3', 'wav'];
  34. if (!$body) {
  35. throw new PlivoXMLException("No MultiPartyCall name set for ".$this->getName());
  36. }
  37. if(isset($attributes['role']) and !in_array(strtolower($attributes['role']), $VALID_ROLE_VALUES, true)){
  38. throw new PlivoXMLException('Invalid attribute value ' . $attributes['role']. ' for role');
  39. }
  40. elseif (!isset($attributes['role'])){
  41. throw new PlivoXMLException('role not mentioned : possible values - Agent / Supervisor / Customer');
  42. }
  43. if(isset($attributes['maxDuration']) and ($attributes['maxDuration'] < 300 or $attributes['maxDuration'] > 28800)){
  44. throw new PlivoXMLException('Invalid attribute value ' . $attributes['maxDuration']. ' for maxDuration');
  45. }
  46. elseif (!isset($attributes['maxDuration'])){
  47. $attributes['maxDuration'] = 14400;
  48. }
  49. if(isset($attributes['maxParticipants']) and ($attributes['maxParticipants'] < 2 or $attributes['maxParticipants'] > 10)){
  50. throw new PlivoXMLException('Invalid attribute value ' . $attributes['maxParticipants']. ' for maxParticipants');
  51. }
  52. elseif (!isset($attributes['maxParticipants'])){
  53. $attributes['maxParticipants'] = 10;
  54. }
  55. if(isset($attributes['recordMinMemberCount']) and ($attributes['recordMinMemberCount'] < 1 or $attributes['recordMinMemberCount'] > 2)){
  56. throw new PlivoXMLException('Invalid attribute value ' . $attributes['recordMinMemberCount']. ' for recordMinMemberCount');
  57. }
  58. elseif (!isset($attributes['recordMinMemberCount'])){
  59. $attributes['recordMinMemberCount'] = 1;
  60. }
  61. if(isset($attributes['waitMusicMethod']) and !in_array(strtoupper($attributes['waitMusicMethod']), $VALID_METHOD_VALUES, true)){
  62. throw new PlivoXMLException('Invalid attribute value ' . $attributes['waitMusicMethod']. ' for waitMusicMethod');
  63. }
  64. elseif (!isset($attributes['waitMusicMethod'])){
  65. $attributes['waitMusicMethod'] = 'GET';
  66. }
  67. if(isset($attributes['agentHoldMusicMethod']) and !in_array(strtoupper($attributes['agentHoldMusicMethod']), $VALID_METHOD_VALUES, true)){
  68. throw new PlivoXMLException('Invalid attribute value ' . $attributes['agentHoldMusicMethod']. ' for agentHoldMusicMethod');
  69. }
  70. elseif (!isset($attributes['agentHoldMusicMethod'])){
  71. $attributes['agentHoldMusicMethod'] = 'GET';
  72. }
  73. if(isset($attributes['customerHoldMusicMethod']) and !in_array(strtoupper($attributes['customerHoldMusicMethod']), $VALID_METHOD_VALUES, true)){
  74. throw new PlivoXMLException('Invalid attribute value ' . $attributes['customerHoldMusicMethod']. ' for customerHoldMusicMethod');
  75. }
  76. elseif (!isset($attributes['customerHoldMusicMethod'])){
  77. $attributes['customerHoldMusicMethod'] = 'GET';
  78. }
  79. if(isset($attributes['record']) and is_bool($attributes['record'])){
  80. throw new PlivoXMLException('Invalid attribute value ' . $attributes['record']. ' for record');
  81. }
  82. elseif (!isset($attributes['record'])){
  83. $attributes['record'] = false;
  84. }
  85. if(isset($attributes['recordFileFormat']) and !in_array(strtolower($attributes['recordFileFormat']), $VALID_RECORD_FILE_FORMAT_VALUES, true)){
  86. throw new PlivoXMLException('Invalid attribute value ' . $attributes['recordFileFormat']. ' for recordFileFormat');
  87. }
  88. elseif (!isset($attributes['recordFileFormat'])){
  89. $attributes['recordFileFormat'] = 'mp3';
  90. }
  91. if(isset($attributes['recordingCallbackMethod']) and !in_array(strtoupper($attributes['recordingCallbackMethod']), $VALID_METHOD_VALUES, true)){
  92. throw new PlivoXMLException('Invalid attribute value ' . $attributes['recordingCallbackMethod']. ' for recordingCallbackMethod');
  93. }
  94. elseif (!isset($attributes['recordingCallbackMethod'])){
  95. $attributes['recordingCallbackMethod'] = 'GET';
  96. }
  97. if(isset($attributes['statusCallbackEvents']) and !MPCUtils::multiValidParam('statusCallbackEvents', $attributes['statusCallbackEvents'], ['string'], false, ['mpc-state-changes', 'participant-state-changes', 'participant-speak-events', 'participant-digit-input-events', 'add-participant-api-events'], true,',')){
  98. throw new PlivoXMLException('Invalid attribute value ' . $attributes['statusCallbackEvents']. ' for statusCallbackEvents');
  99. }
  100. elseif (!isset($attributes['statusCallbackEvents'])){
  101. $attributes['statusCallbackEvents'] = 'mpc-state-changes,participant-state-changes';
  102. }
  103. if(isset($attributes['statusCallbackMethod']) and !in_array(strtoupper($attributes['statusCallbackMethod']), $VALID_METHOD_VALUES, true)){
  104. throw new PlivoXMLException('Invalid attribute value ' . $attributes['statusCallbackMethod']. ' for statusCallbackMethod');
  105. }
  106. elseif (!isset($attributes['statusCallbackMethod'])){
  107. $attributes['statusCallbackMethod'] = 'POST';
  108. }
  109. if(isset($attributes['stayAlone']) and is_bool($attributes['stayAlone'])){
  110. throw new PlivoXMLException('Invalid attribute value ' . $attributes['stayAlone']. ' for stayAlone');
  111. }
  112. elseif (!isset($attributes['stayAlone'])){
  113. $attributes['stayAlone'] = false;
  114. }
  115. if(isset($attributes['coachMode']) and is_bool($attributes['coachMode'])){
  116. throw new PlivoXMLException('Invalid attribute value ' . $attributes['coachMode']. ' for coachMode');
  117. }
  118. elseif (!isset($attributes['coachMode'])){
  119. $attributes['coachMode'] = true;
  120. }
  121. if(isset($attributes['mute']) and is_bool($attributes['mute'])){
  122. throw new PlivoXMLException('Invalid attribute value ' . $attributes['mute']. ' for mute');
  123. }
  124. elseif (!isset($attributes['mute'])){
  125. $attributes['mute'] = false;
  126. }
  127. if(isset($attributes['hold']) and is_bool($attributes['hold'])){
  128. throw new PlivoXMLException('Invalid attribute value ' . $attributes['hold']. ' for hold');
  129. }
  130. elseif (!isset($attributes['hold'])){
  131. $attributes['hold'] = false;
  132. }
  133. if(isset($attributes['startMpcOnEnter']) and is_bool($attributes['startMpcOnEnter'])){
  134. throw new PlivoXMLException('Invalid attribute value ' . $attributes['startMpcOnEnter']. ' for startMpcOnEnter');
  135. }
  136. elseif (!isset($attributes['startMpcOnEnter'])){
  137. $attributes['startMpcOnEnter'] = true;
  138. }
  139. if(isset($attributes['endMpcOnExit']) and is_bool($attributes['endMpcOnExit'])){
  140. throw new PlivoXMLException('Invalid attribute value ' . $attributes['endMpcOnExit']. ' for endMpcOnExit');
  141. }
  142. elseif (!isset($attributes['endMpcOnExit'])){
  143. $attributes['endMpcOnExit'] = false;
  144. }
  145. if(isset($attributes['enterSound']) and !MPCUtils::isOneAmongStringUrl('enterSound', $attributes['enterSound'], false, ['beep:1', 'beep:2', 'none'])){
  146. throw new PlivoXMLException('Invalid attribute value ' . $attributes['enterSound']. ' for enterSound');
  147. }
  148. elseif (!isset($attributes['enterSound'])){
  149. $attributes['enterSound'] = 'beep:1';
  150. }
  151. if(isset($attributes['enterSoundMethod']) and !in_array(strtoupper($attributes['enterSoundMethod']), $VALID_METHOD_VALUES, true)){
  152. throw new PlivoXMLException('Invalid attribute value ' . $attributes['enterSoundMethod']. ' for enterSoundMethod');
  153. }
  154. elseif (!isset($attributes['enterSoundMethod'])){
  155. $attributes['enterSoundMethod'] = 'GET';
  156. }
  157. if(isset($attributes['exitSound']) and !MPCUtils::isOneAmongStringUrl('exitSound', $attributes['exitSound'], false, ['beep:1', 'beep:2', 'none'])){
  158. throw new PlivoXMLException('Invalid attribute value ' . $attributes['exitSound']. ' for exitSound');
  159. }
  160. elseif (!isset($attributes['exitSound'])){
  161. $attributes['exitSound'] = 'beep:2';
  162. }
  163. if(isset($attributes['exitSoundMethod']) and !in_array(strtoupper($attributes['exitSoundMethod']), $VALID_METHOD_VALUES, true)){
  164. throw new PlivoXMLException('Invalid attribute value ' . $attributes['exitSoundMethod']. ' for exitSoundMethod');
  165. }
  166. elseif (!isset($attributes['exitSoundMethod'])){
  167. $attributes['exitSoundMethod'] = 'GET';
  168. }
  169. if(isset($attributes['onExitActionMethod']) and !in_array(strtoupper($attributes['onExitActionMethod']), $VALID_METHOD_VALUES, true)){
  170. throw new PlivoXMLException('Invalid attribute value ' . $attributes['onExitActionMethod']. ' for onExitActionMethod');
  171. }
  172. elseif (!isset($attributes['onExitActionMethod'])){
  173. $attributes['onExitActionMethod'] = 'POST';
  174. }
  175. if(isset($attributes['relayDTMFInputs']) and is_bool($attributes['relayDTMFInputs'])){
  176. throw new PlivoXMLException('Invalid attribute value ' . $attributes['relayDTMFInputs']. ' for relayDTMFInputs');
  177. }
  178. elseif (!isset($attributes['relayDTMFInputs'])){
  179. $attributes['relayDTMFInputs'] = false;
  180. }
  181. if(isset($attributes['waitMusicUrl']) and !MPCUtils::validUrl('waitMusicUrl', $attributes['waitMusicUrl'], false)){
  182. throw new PlivoXMLException('Invalid attribute value ' . $attributes['waitMusicUrl']. ' for waitMusicUrl');
  183. }
  184. if(isset($attributes['agentHoldMusicUrl']) and !MPCUtils::validUrl('agentHoldMusicUrl', $attributes['agentHoldMusicUrl'], false)){
  185. throw new PlivoXMLException('Invalid attribute value ' . $attributes['agentHoldMusicUrl']. ' for agentHoldMusicUrl');
  186. }
  187. if(isset($attributes['customerHoldMusicUrl']) and !MPCUtils::validUrl('customerHoldMusicUrl', $attributes['customerHoldMusicUrl'], false)){
  188. throw new PlivoXMLException('Invalid attribute value ' . $attributes['customerHoldMusicUrl']. ' for customerHoldMusicUrl');
  189. }
  190. if(isset($attributes['recordingCallbackUrl']) and !MPCUtils::validUrl('recordingCallbackUrl', $attributes['recordingCallbackUrl'], false)){
  191. throw new PlivoXMLException('Invalid attribute value ' . $attributes['recordingCallbackUrl']. ' for recordingCallbackUrl');
  192. }
  193. if(isset($attributes['statusCallbackUrl']) and !MPCUtils::validUrl('statusCallbackUrl', $attributes['statusCallbackUrl'], false)){
  194. throw new PlivoXMLException('Invalid attribute value ' . $attributes['statusCallbackUrl']. ' for statusCallbackUrl');
  195. }
  196. if(isset($attributes['onExitActionUrl']) and !MPCUtils::validUrl('onExitActionUrl', $attributes['onExitActionUrl'], false)){
  197. throw new PlivoXMLException('Invalid attribute value ' . $attributes['onExitActionUrl']. ' for onExitActionUrl');
  198. }
  199. if(isset($attributes['startRecordingAudio']) and !MPCUtils::validUrl('startRecordingAudio', $attributes['startRecordingAudio'], false)){
  200. throw new PlivoXMLException('Invalid attribute value ' . $attributes['startRecordingAudio']. ' for startRecordingAudio');
  201. }
  202. if(isset($attributes['stopRecordingAudio']) and !MPCUtils::validUrl('stopRecordingAudio', $attributes['stopRecordingAudio'], false)){
  203. throw new PlivoXMLException('Invalid attribute value ' . $attributes['stopRecordingAudio']. ' for stopRecordingAudio');
  204. }
  205. if(isset($attributes['startRecordingAudioMethod']) and !in_array(strtoupper($attributes['startRecordingAudioMethod']), $VALID_METHOD_VALUES, true)){
  206. throw new PlivoXMLException('Invalid attribute value ' . $attributes['startRecordingAudioMethod']. ' for startRecordingAudioMethod');
  207. }
  208. elseif (!isset($attributes['startRecordingAudioMethod'])){
  209. $attributes['startRecordingAudioMethod'] = 'GET';
  210. }
  211. if(isset($attributes['stopRecordingAudioMethod']) and !in_array(strtoupper($attributes['stopRecordingAudioMethod']), $VALID_METHOD_VALUES, true)){
  212. throw new PlivoXMLException('Invalid attribute value ' . $attributes['stopRecordingAudioMethod']. ' for stopRecordingAudioMethod');
  213. }
  214. elseif (!isset($attributes['stopRecordingAudioMethod'])){
  215. $attributes['stopRecordingAudioMethod'] = 'GET';
  216. }
  217. }
  218. }