github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_calls.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Api 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "net/url" 21 "strings" 22 "time" 23 24 "github.com/twilio/twilio-go/client" 25 ) 26 27 // Optional parameters for the method 'CreateCall' 28 type CreateCallParams struct { 29 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource. 30 PathAccountSid *string `json:"PathAccountSid,omitempty"` 31 // The phone number, SIP address, or client identifier to call. 32 To *string `json:"To,omitempty"` 33 // The phone number or client identifier to use as the caller id. If using a phone number, it must be a Twilio number or a Verified [outgoing caller id](https://www.twilio.com/docs/voice/api/outgoing-caller-ids) for your account. If the `to` parameter is a phone number, `From` must also be a phone number. 34 From *string `json:"From,omitempty"` 35 // The HTTP method we should use when calling the `url` parameter's value. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 36 Method *string `json:"Method,omitempty"` 37 // The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored. 38 FallbackUrl *string `json:"FallbackUrl,omitempty"` 39 // The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 40 FallbackMethod *string `json:"FallbackMethod,omitempty"` 41 // The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted). 42 StatusCallback *string `json:"StatusCallback,omitempty"` 43 // The call progress events that we will send to the `status_callback` URL. Can be: `initiated`, `ringing`, `answered`, and `completed`. If no event is specified, we send the `completed` status. If you want to receive multiple events, specify each one in a separate `status_callback_event` parameter. See the code sample for [monitoring call progress](https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-create-a-call-resource-and-specify-a-statuscallbackevent&code-sdk-version=json). If an `application_sid` is present, this parameter is ignored. 44 StatusCallbackEvent *[]string `json:"StatusCallbackEvent,omitempty"` 45 // The HTTP method we should use when calling the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 46 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 47 // A string of keys to dial after connecting to the number, maximum of 32 digits. Valid digits in the string include: any digit (`0`-`9`), '`#`', '`*`' and '`w`', to insert a half second pause. For example, if you connected to a company phone number and wanted to pause for one second, and then dial extension 1234 followed by the pound key, the value of this parameter would be `ww1234#`. Remember to URL-encode this string, since the '`#`' character has special meaning in a URL. If both `SendDigits` and `MachineDetection` parameters are provided, then `MachineDetection` will be ignored. 48 SendDigits *string `json:"SendDigits,omitempty"` 49 // The integer number of seconds that we should allow the phone to ring before assuming there is no answer. The default is `60` seconds and the maximum is `600` seconds. For some call flows, we will add a 5-second buffer to the timeout value you provide. For this reason, a timeout value of 10 seconds could result in an actual timeout closer to 15 seconds. You can set this to a short time, such as `15` seconds, to hang up before reaching an answering machine or voicemail. 50 Timeout *int `json:"Timeout,omitempty"` 51 // Whether to record the call. Can be `true` to record the phone call, or `false` to not. The default is `false`. The `recording_url` is sent to the `status_callback` URL. 52 Record *bool `json:"Record,omitempty"` 53 // The number of channels in the final recording. Can be: `mono` or `dual`. The default is `mono`. `mono` records both legs of the call in a single channel of the recording file. `dual` records each leg to a separate channel of the recording file. The first channel of a dual-channel recording contains the parent call and the second channel contains the child call. 54 RecordingChannels *string `json:"RecordingChannels,omitempty"` 55 // The URL that we call when the recording is available to be accessed. 56 RecordingStatusCallback *string `json:"RecordingStatusCallback,omitempty"` 57 // The HTTP method we should use when calling the `recording_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. 58 RecordingStatusCallbackMethod *string `json:"RecordingStatusCallbackMethod,omitempty"` 59 // The username used to authenticate the caller making a SIP call. 60 SipAuthUsername *string `json:"SipAuthUsername,omitempty"` 61 // The password required to authenticate the user account specified in `sip_auth_username`. 62 SipAuthPassword *string `json:"SipAuthPassword,omitempty"` 63 // Whether to detect if a human, answering machine, or fax has picked up the call. Can be: `Enable` or `DetectMessageEnd`. Use `Enable` if you would like us to return `AnsweredBy` as soon as the called party is identified. Use `DetectMessageEnd`, if you would like to leave a message on an answering machine. If `send_digits` is provided, this parameter is ignored. For more information, see [Answering Machine Detection](https://www.twilio.com/docs/voice/answering-machine-detection). 64 MachineDetection *string `json:"MachineDetection,omitempty"` 65 // The number of seconds that we should attempt to detect an answering machine before timing out and sending a voice request with `AnsweredBy` of `unknown`. The default timeout is 30 seconds. 66 MachineDetectionTimeout *int `json:"MachineDetectionTimeout,omitempty"` 67 // The recording status events that will trigger calls to the URL specified in `recording_status_callback`. Can be: `in-progress`, `completed` and `absent`. Defaults to `completed`. Separate multiple values with a space. 68 RecordingStatusCallbackEvent *[]string `json:"RecordingStatusCallbackEvent,omitempty"` 69 // Whether to trim any leading and trailing silence from the recording. Can be: `trim-silence` or `do-not-trim` and the default is `trim-silence`. 70 Trim *string `json:"Trim,omitempty"` 71 // The phone number, SIP address, or Client identifier that made this call. Phone numbers are in [E.164 format](https://wwnw.twilio.com/docs/glossary/what-e164) (e.g., +16175551212). SIP addresses are formatted as `name@company.com`. 72 CallerId *string `json:"CallerId,omitempty"` 73 // The number of milliseconds that is used as the measuring stick for the length of the speech activity, where durations lower than this value will be interpreted as a human and longer than this value as a machine. Possible Values: 1000-6000. Default: 2400. 74 MachineDetectionSpeechThreshold *int `json:"MachineDetectionSpeechThreshold,omitempty"` 75 // The number of milliseconds of silence after speech activity at which point the speech activity is considered complete. Possible Values: 500-5000. Default: 1200. 76 MachineDetectionSpeechEndThreshold *int `json:"MachineDetectionSpeechEndThreshold,omitempty"` 77 // The number of milliseconds of initial silence after which an `unknown` AnsweredBy result will be returned. Possible Values: 2000-10000. Default: 5000. 78 MachineDetectionSilenceTimeout *int `json:"MachineDetectionSilenceTimeout,omitempty"` 79 // Select whether to perform answering machine detection in the background. Default, blocks the execution of the call until Answering Machine Detection is completed. Can be: `true` or `false`. 80 AsyncAmd *string `json:"AsyncAmd,omitempty"` 81 // The URL that we should call using the `async_amd_status_callback_method` to notify customer application whether the call was answered by human, machine or fax. 82 AsyncAmdStatusCallback *string `json:"AsyncAmdStatusCallback,omitempty"` 83 // The HTTP method we should use when calling the `async_amd_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. 84 AsyncAmdStatusCallbackMethod *string `json:"AsyncAmdStatusCallbackMethod,omitempty"` 85 // The SID of a BYOC (Bring Your Own Carrier) trunk to route this call with. Note that `byoc` is only meaningful when `to` is a phone number; it will otherwise be ignored. (Beta) 86 Byoc *string `json:"Byoc,omitempty"` 87 // The Reason for the outgoing call. Use it to specify the purpose of the call that is presented on the called party's phone. (Branded Calls Beta) 88 CallReason *string `json:"CallReason,omitempty"` 89 // A token string needed to invoke a forwarded call. A call_token is generated when an incoming call is received on a Twilio number. Pass an incoming call's call_token value to a forwarded call via the call_token parameter when creating a new call. A forwarded call should bear the same CallerID of the original incoming call. 90 CallToken *string `json:"CallToken,omitempty"` 91 // The audio track to record for the call. Can be: `inbound`, `outbound` or `both`. The default is `both`. `inbound` records the audio that is received by Twilio. `outbound` records the audio that is generated from Twilio. `both` records the audio that is received and generated by Twilio. 92 RecordingTrack *string `json:"RecordingTrack,omitempty"` 93 // The maximum duration of the call in seconds. Constraints depend on account and configuration. 94 TimeLimit *int `json:"TimeLimit,omitempty"` 95 // The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls). 96 Url *string `json:"Url,omitempty"` 97 // TwiML instructions for the call Twilio will use without fetching Twiml from url parameter. If both `twiml` and `url` are provided then `twiml` parameter will be ignored. Max 4000 characters. 98 Twiml *string `json:"Twiml,omitempty"` 99 // The SID of the Application resource that will handle the call, if the call will be handled by an application. 100 ApplicationSid *string `json:"ApplicationSid,omitempty"` 101 } 102 103 func (params *CreateCallParams) SetPathAccountSid(PathAccountSid string) *CreateCallParams { 104 params.PathAccountSid = &PathAccountSid 105 return params 106 } 107 func (params *CreateCallParams) SetTo(To string) *CreateCallParams { 108 params.To = &To 109 return params 110 } 111 func (params *CreateCallParams) SetFrom(From string) *CreateCallParams { 112 params.From = &From 113 return params 114 } 115 func (params *CreateCallParams) SetMethod(Method string) *CreateCallParams { 116 params.Method = &Method 117 return params 118 } 119 func (params *CreateCallParams) SetFallbackUrl(FallbackUrl string) *CreateCallParams { 120 params.FallbackUrl = &FallbackUrl 121 return params 122 } 123 func (params *CreateCallParams) SetFallbackMethod(FallbackMethod string) *CreateCallParams { 124 params.FallbackMethod = &FallbackMethod 125 return params 126 } 127 func (params *CreateCallParams) SetStatusCallback(StatusCallback string) *CreateCallParams { 128 params.StatusCallback = &StatusCallback 129 return params 130 } 131 func (params *CreateCallParams) SetStatusCallbackEvent(StatusCallbackEvent []string) *CreateCallParams { 132 params.StatusCallbackEvent = &StatusCallbackEvent 133 return params 134 } 135 func (params *CreateCallParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateCallParams { 136 params.StatusCallbackMethod = &StatusCallbackMethod 137 return params 138 } 139 func (params *CreateCallParams) SetSendDigits(SendDigits string) *CreateCallParams { 140 params.SendDigits = &SendDigits 141 return params 142 } 143 func (params *CreateCallParams) SetTimeout(Timeout int) *CreateCallParams { 144 params.Timeout = &Timeout 145 return params 146 } 147 func (params *CreateCallParams) SetRecord(Record bool) *CreateCallParams { 148 params.Record = &Record 149 return params 150 } 151 func (params *CreateCallParams) SetRecordingChannels(RecordingChannels string) *CreateCallParams { 152 params.RecordingChannels = &RecordingChannels 153 return params 154 } 155 func (params *CreateCallParams) SetRecordingStatusCallback(RecordingStatusCallback string) *CreateCallParams { 156 params.RecordingStatusCallback = &RecordingStatusCallback 157 return params 158 } 159 func (params *CreateCallParams) SetRecordingStatusCallbackMethod(RecordingStatusCallbackMethod string) *CreateCallParams { 160 params.RecordingStatusCallbackMethod = &RecordingStatusCallbackMethod 161 return params 162 } 163 func (params *CreateCallParams) SetSipAuthUsername(SipAuthUsername string) *CreateCallParams { 164 params.SipAuthUsername = &SipAuthUsername 165 return params 166 } 167 func (params *CreateCallParams) SetSipAuthPassword(SipAuthPassword string) *CreateCallParams { 168 params.SipAuthPassword = &SipAuthPassword 169 return params 170 } 171 func (params *CreateCallParams) SetMachineDetection(MachineDetection string) *CreateCallParams { 172 params.MachineDetection = &MachineDetection 173 return params 174 } 175 func (params *CreateCallParams) SetMachineDetectionTimeout(MachineDetectionTimeout int) *CreateCallParams { 176 params.MachineDetectionTimeout = &MachineDetectionTimeout 177 return params 178 } 179 func (params *CreateCallParams) SetRecordingStatusCallbackEvent(RecordingStatusCallbackEvent []string) *CreateCallParams { 180 params.RecordingStatusCallbackEvent = &RecordingStatusCallbackEvent 181 return params 182 } 183 func (params *CreateCallParams) SetTrim(Trim string) *CreateCallParams { 184 params.Trim = &Trim 185 return params 186 } 187 func (params *CreateCallParams) SetCallerId(CallerId string) *CreateCallParams { 188 params.CallerId = &CallerId 189 return params 190 } 191 func (params *CreateCallParams) SetMachineDetectionSpeechThreshold(MachineDetectionSpeechThreshold int) *CreateCallParams { 192 params.MachineDetectionSpeechThreshold = &MachineDetectionSpeechThreshold 193 return params 194 } 195 func (params *CreateCallParams) SetMachineDetectionSpeechEndThreshold(MachineDetectionSpeechEndThreshold int) *CreateCallParams { 196 params.MachineDetectionSpeechEndThreshold = &MachineDetectionSpeechEndThreshold 197 return params 198 } 199 func (params *CreateCallParams) SetMachineDetectionSilenceTimeout(MachineDetectionSilenceTimeout int) *CreateCallParams { 200 params.MachineDetectionSilenceTimeout = &MachineDetectionSilenceTimeout 201 return params 202 } 203 func (params *CreateCallParams) SetAsyncAmd(AsyncAmd string) *CreateCallParams { 204 params.AsyncAmd = &AsyncAmd 205 return params 206 } 207 func (params *CreateCallParams) SetAsyncAmdStatusCallback(AsyncAmdStatusCallback string) *CreateCallParams { 208 params.AsyncAmdStatusCallback = &AsyncAmdStatusCallback 209 return params 210 } 211 func (params *CreateCallParams) SetAsyncAmdStatusCallbackMethod(AsyncAmdStatusCallbackMethod string) *CreateCallParams { 212 params.AsyncAmdStatusCallbackMethod = &AsyncAmdStatusCallbackMethod 213 return params 214 } 215 func (params *CreateCallParams) SetByoc(Byoc string) *CreateCallParams { 216 params.Byoc = &Byoc 217 return params 218 } 219 func (params *CreateCallParams) SetCallReason(CallReason string) *CreateCallParams { 220 params.CallReason = &CallReason 221 return params 222 } 223 func (params *CreateCallParams) SetCallToken(CallToken string) *CreateCallParams { 224 params.CallToken = &CallToken 225 return params 226 } 227 func (params *CreateCallParams) SetRecordingTrack(RecordingTrack string) *CreateCallParams { 228 params.RecordingTrack = &RecordingTrack 229 return params 230 } 231 func (params *CreateCallParams) SetTimeLimit(TimeLimit int) *CreateCallParams { 232 params.TimeLimit = &TimeLimit 233 return params 234 } 235 func (params *CreateCallParams) SetUrl(Url string) *CreateCallParams { 236 params.Url = &Url 237 return params 238 } 239 func (params *CreateCallParams) SetTwiml(Twiml string) *CreateCallParams { 240 params.Twiml = &Twiml 241 return params 242 } 243 func (params *CreateCallParams) SetApplicationSid(ApplicationSid string) *CreateCallParams { 244 params.ApplicationSid = &ApplicationSid 245 return params 246 } 247 248 // Create a new outgoing call to phones, SIP-enabled endpoints or Twilio Client connections 249 func (c *ApiService) CreateCall(params *CreateCallParams) (*ApiV2010Call, error) { 250 path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" 251 if params != nil && params.PathAccountSid != nil { 252 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 253 } else { 254 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 255 } 256 257 data := url.Values{} 258 headers := make(map[string]interface{}) 259 260 if params != nil && params.To != nil { 261 data.Set("To", *params.To) 262 } 263 if params != nil && params.From != nil { 264 data.Set("From", *params.From) 265 } 266 if params != nil && params.Method != nil { 267 data.Set("Method", *params.Method) 268 } 269 if params != nil && params.FallbackUrl != nil { 270 data.Set("FallbackUrl", *params.FallbackUrl) 271 } 272 if params != nil && params.FallbackMethod != nil { 273 data.Set("FallbackMethod", *params.FallbackMethod) 274 } 275 if params != nil && params.StatusCallback != nil { 276 data.Set("StatusCallback", *params.StatusCallback) 277 } 278 if params != nil && params.StatusCallbackEvent != nil { 279 for _, item := range *params.StatusCallbackEvent { 280 data.Add("StatusCallbackEvent", item) 281 } 282 } 283 if params != nil && params.StatusCallbackMethod != nil { 284 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 285 } 286 if params != nil && params.SendDigits != nil { 287 data.Set("SendDigits", *params.SendDigits) 288 } 289 if params != nil && params.Timeout != nil { 290 data.Set("Timeout", fmt.Sprint(*params.Timeout)) 291 } 292 if params != nil && params.Record != nil { 293 data.Set("Record", fmt.Sprint(*params.Record)) 294 } 295 if params != nil && params.RecordingChannels != nil { 296 data.Set("RecordingChannels", *params.RecordingChannels) 297 } 298 if params != nil && params.RecordingStatusCallback != nil { 299 data.Set("RecordingStatusCallback", *params.RecordingStatusCallback) 300 } 301 if params != nil && params.RecordingStatusCallbackMethod != nil { 302 data.Set("RecordingStatusCallbackMethod", *params.RecordingStatusCallbackMethod) 303 } 304 if params != nil && params.SipAuthUsername != nil { 305 data.Set("SipAuthUsername", *params.SipAuthUsername) 306 } 307 if params != nil && params.SipAuthPassword != nil { 308 data.Set("SipAuthPassword", *params.SipAuthPassword) 309 } 310 if params != nil && params.MachineDetection != nil { 311 data.Set("MachineDetection", *params.MachineDetection) 312 } 313 if params != nil && params.MachineDetectionTimeout != nil { 314 data.Set("MachineDetectionTimeout", fmt.Sprint(*params.MachineDetectionTimeout)) 315 } 316 if params != nil && params.RecordingStatusCallbackEvent != nil { 317 for _, item := range *params.RecordingStatusCallbackEvent { 318 data.Add("RecordingStatusCallbackEvent", item) 319 } 320 } 321 if params != nil && params.Trim != nil { 322 data.Set("Trim", *params.Trim) 323 } 324 if params != nil && params.CallerId != nil { 325 data.Set("CallerId", *params.CallerId) 326 } 327 if params != nil && params.MachineDetectionSpeechThreshold != nil { 328 data.Set("MachineDetectionSpeechThreshold", fmt.Sprint(*params.MachineDetectionSpeechThreshold)) 329 } 330 if params != nil && params.MachineDetectionSpeechEndThreshold != nil { 331 data.Set("MachineDetectionSpeechEndThreshold", fmt.Sprint(*params.MachineDetectionSpeechEndThreshold)) 332 } 333 if params != nil && params.MachineDetectionSilenceTimeout != nil { 334 data.Set("MachineDetectionSilenceTimeout", fmt.Sprint(*params.MachineDetectionSilenceTimeout)) 335 } 336 if params != nil && params.AsyncAmd != nil { 337 data.Set("AsyncAmd", *params.AsyncAmd) 338 } 339 if params != nil && params.AsyncAmdStatusCallback != nil { 340 data.Set("AsyncAmdStatusCallback", *params.AsyncAmdStatusCallback) 341 } 342 if params != nil && params.AsyncAmdStatusCallbackMethod != nil { 343 data.Set("AsyncAmdStatusCallbackMethod", *params.AsyncAmdStatusCallbackMethod) 344 } 345 if params != nil && params.Byoc != nil { 346 data.Set("Byoc", *params.Byoc) 347 } 348 if params != nil && params.CallReason != nil { 349 data.Set("CallReason", *params.CallReason) 350 } 351 if params != nil && params.CallToken != nil { 352 data.Set("CallToken", *params.CallToken) 353 } 354 if params != nil && params.RecordingTrack != nil { 355 data.Set("RecordingTrack", *params.RecordingTrack) 356 } 357 if params != nil && params.TimeLimit != nil { 358 data.Set("TimeLimit", fmt.Sprint(*params.TimeLimit)) 359 } 360 if params != nil && params.Url != nil { 361 data.Set("Url", *params.Url) 362 } 363 if params != nil && params.Twiml != nil { 364 data.Set("Twiml", *params.Twiml) 365 } 366 if params != nil && params.ApplicationSid != nil { 367 data.Set("ApplicationSid", *params.ApplicationSid) 368 } 369 370 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 371 if err != nil { 372 return nil, err 373 } 374 375 defer resp.Body.Close() 376 377 ps := &ApiV2010Call{} 378 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 379 return nil, err 380 } 381 382 return ps, err 383 } 384 385 // Optional parameters for the method 'DeleteCall' 386 type DeleteCallParams struct { 387 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to delete. 388 PathAccountSid *string `json:"PathAccountSid,omitempty"` 389 } 390 391 func (params *DeleteCallParams) SetPathAccountSid(PathAccountSid string) *DeleteCallParams { 392 params.PathAccountSid = &PathAccountSid 393 return params 394 } 395 396 // Delete a Call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs. 397 func (c *ApiService) DeleteCall(Sid string, params *DeleteCallParams) error { 398 path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" 399 if params != nil && params.PathAccountSid != nil { 400 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 401 } else { 402 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 403 } 404 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 405 406 data := url.Values{} 407 headers := make(map[string]interface{}) 408 409 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 410 if err != nil { 411 return err 412 } 413 414 defer resp.Body.Close() 415 416 return nil 417 } 418 419 // Optional parameters for the method 'FetchCall' 420 type FetchCallParams struct { 421 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to fetch. 422 PathAccountSid *string `json:"PathAccountSid,omitempty"` 423 } 424 425 func (params *FetchCallParams) SetPathAccountSid(PathAccountSid string) *FetchCallParams { 426 params.PathAccountSid = &PathAccountSid 427 return params 428 } 429 430 // Fetch the call specified by the provided Call SID 431 func (c *ApiService) FetchCall(Sid string, params *FetchCallParams) (*ApiV2010Call, error) { 432 path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" 433 if params != nil && params.PathAccountSid != nil { 434 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 435 } else { 436 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 437 } 438 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 439 440 data := url.Values{} 441 headers := make(map[string]interface{}) 442 443 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 444 if err != nil { 445 return nil, err 446 } 447 448 defer resp.Body.Close() 449 450 ps := &ApiV2010Call{} 451 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 452 return nil, err 453 } 454 455 return ps, err 456 } 457 458 // Optional parameters for the method 'ListCall' 459 type ListCallParams struct { 460 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to read. 461 PathAccountSid *string `json:"PathAccountSid,omitempty"` 462 // Only show calls made to this phone number, SIP address, Client identifier or SIM SID. 463 To *string `json:"To,omitempty"` 464 // Only include calls from this phone number, SIP address, Client identifier or SIM SID. 465 From *string `json:"From,omitempty"` 466 // Only include calls spawned by calls with this SID. 467 ParentCallSid *string `json:"ParentCallSid,omitempty"` 468 // The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`. 469 Status *string `json:"Status,omitempty"` 470 // Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. 471 StartTime *time.Time `json:"StartTime,omitempty"` 472 // Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. 473 StartTimeBefore *time.Time `json:"StartTime<,omitempty"` 474 // Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date. 475 StartTimeAfter *time.Time `json:"StartTime>,omitempty"` 476 // Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. 477 EndTime *time.Time `json:"EndTime,omitempty"` 478 // Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. 479 EndTimeBefore *time.Time `json:"EndTime<,omitempty"` 480 // Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date. 481 EndTimeAfter *time.Time `json:"EndTime>,omitempty"` 482 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 483 PageSize *int `json:"PageSize,omitempty"` 484 // Max number of records to return. 485 Limit *int `json:"limit,omitempty"` 486 } 487 488 func (params *ListCallParams) SetPathAccountSid(PathAccountSid string) *ListCallParams { 489 params.PathAccountSid = &PathAccountSid 490 return params 491 } 492 func (params *ListCallParams) SetTo(To string) *ListCallParams { 493 params.To = &To 494 return params 495 } 496 func (params *ListCallParams) SetFrom(From string) *ListCallParams { 497 params.From = &From 498 return params 499 } 500 func (params *ListCallParams) SetParentCallSid(ParentCallSid string) *ListCallParams { 501 params.ParentCallSid = &ParentCallSid 502 return params 503 } 504 func (params *ListCallParams) SetStatus(Status string) *ListCallParams { 505 params.Status = &Status 506 return params 507 } 508 func (params *ListCallParams) SetStartTime(StartTime time.Time) *ListCallParams { 509 params.StartTime = &StartTime 510 return params 511 } 512 func (params *ListCallParams) SetStartTimeBefore(StartTimeBefore time.Time) *ListCallParams { 513 params.StartTimeBefore = &StartTimeBefore 514 return params 515 } 516 func (params *ListCallParams) SetStartTimeAfter(StartTimeAfter time.Time) *ListCallParams { 517 params.StartTimeAfter = &StartTimeAfter 518 return params 519 } 520 func (params *ListCallParams) SetEndTime(EndTime time.Time) *ListCallParams { 521 params.EndTime = &EndTime 522 return params 523 } 524 func (params *ListCallParams) SetEndTimeBefore(EndTimeBefore time.Time) *ListCallParams { 525 params.EndTimeBefore = &EndTimeBefore 526 return params 527 } 528 func (params *ListCallParams) SetEndTimeAfter(EndTimeAfter time.Time) *ListCallParams { 529 params.EndTimeAfter = &EndTimeAfter 530 return params 531 } 532 func (params *ListCallParams) SetPageSize(PageSize int) *ListCallParams { 533 params.PageSize = &PageSize 534 return params 535 } 536 func (params *ListCallParams) SetLimit(Limit int) *ListCallParams { 537 params.Limit = &Limit 538 return params 539 } 540 541 // Retrieve a single page of Call records from the API. Request is executed immediately. 542 func (c *ApiService) PageCall(params *ListCallParams, pageToken, pageNumber string) (*ListCallResponse, error) { 543 path := "/2010-04-01/Accounts/{AccountSid}/Calls.json" 544 545 if params != nil && params.PathAccountSid != nil { 546 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 547 } else { 548 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 549 } 550 551 data := url.Values{} 552 headers := make(map[string]interface{}) 553 554 if params != nil && params.To != nil { 555 data.Set("To", *params.To) 556 } 557 if params != nil && params.From != nil { 558 data.Set("From", *params.From) 559 } 560 if params != nil && params.ParentCallSid != nil { 561 data.Set("ParentCallSid", *params.ParentCallSid) 562 } 563 if params != nil && params.Status != nil { 564 data.Set("Status", *params.Status) 565 } 566 if params != nil && params.StartTime != nil { 567 data.Set("StartTime", fmt.Sprint((*params.StartTime).Format(time.RFC3339))) 568 } 569 if params != nil && params.StartTimeBefore != nil { 570 data.Set("StartTime<", fmt.Sprint((*params.StartTimeBefore).Format(time.RFC3339))) 571 } 572 if params != nil && params.StartTimeAfter != nil { 573 data.Set("StartTime>", fmt.Sprint((*params.StartTimeAfter).Format(time.RFC3339))) 574 } 575 if params != nil && params.EndTime != nil { 576 data.Set("EndTime", fmt.Sprint((*params.EndTime).Format(time.RFC3339))) 577 } 578 if params != nil && params.EndTimeBefore != nil { 579 data.Set("EndTime<", fmt.Sprint((*params.EndTimeBefore).Format(time.RFC3339))) 580 } 581 if params != nil && params.EndTimeAfter != nil { 582 data.Set("EndTime>", fmt.Sprint((*params.EndTimeAfter).Format(time.RFC3339))) 583 } 584 if params != nil && params.PageSize != nil { 585 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 586 } 587 588 if pageToken != "" { 589 data.Set("PageToken", pageToken) 590 } 591 if pageNumber != "" { 592 data.Set("Page", pageNumber) 593 } 594 595 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 596 if err != nil { 597 return nil, err 598 } 599 600 defer resp.Body.Close() 601 602 ps := &ListCallResponse{} 603 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 604 return nil, err 605 } 606 607 return ps, err 608 } 609 610 // Lists Call records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 611 func (c *ApiService) ListCall(params *ListCallParams) ([]ApiV2010Call, error) { 612 response, errors := c.StreamCall(params) 613 614 records := make([]ApiV2010Call, 0) 615 for record := range response { 616 records = append(records, record) 617 } 618 619 if err := <-errors; err != nil { 620 return nil, err 621 } 622 623 return records, nil 624 } 625 626 // Streams Call records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 627 func (c *ApiService) StreamCall(params *ListCallParams) (chan ApiV2010Call, chan error) { 628 if params == nil { 629 params = &ListCallParams{} 630 } 631 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 632 633 recordChannel := make(chan ApiV2010Call, 1) 634 errorChannel := make(chan error, 1) 635 636 response, err := c.PageCall(params, "", "") 637 if err != nil { 638 errorChannel <- err 639 close(recordChannel) 640 close(errorChannel) 641 } else { 642 go c.streamCall(response, params, recordChannel, errorChannel) 643 } 644 645 return recordChannel, errorChannel 646 } 647 648 func (c *ApiService) streamCall(response *ListCallResponse, params *ListCallParams, recordChannel chan ApiV2010Call, errorChannel chan error) { 649 curRecord := 1 650 651 for response != nil { 652 responseRecords := response.Calls 653 for item := range responseRecords { 654 recordChannel <- responseRecords[item] 655 curRecord += 1 656 if params.Limit != nil && *params.Limit < curRecord { 657 close(recordChannel) 658 close(errorChannel) 659 return 660 } 661 } 662 663 record, err := client.GetNext(c.baseURL, response, c.getNextListCallResponse) 664 if err != nil { 665 errorChannel <- err 666 break 667 } else if record == nil { 668 break 669 } 670 671 response = record.(*ListCallResponse) 672 } 673 674 close(recordChannel) 675 close(errorChannel) 676 } 677 678 func (c *ApiService) getNextListCallResponse(nextPageUrl string) (interface{}, error) { 679 if nextPageUrl == "" { 680 return nil, nil 681 } 682 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 683 if err != nil { 684 return nil, err 685 } 686 687 defer resp.Body.Close() 688 689 ps := &ListCallResponse{} 690 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 691 return nil, err 692 } 693 return ps, nil 694 } 695 696 // Optional parameters for the method 'UpdateCall' 697 type UpdateCallParams struct { 698 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to update. 699 PathAccountSid *string `json:"PathAccountSid,omitempty"` 700 // The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls). 701 Url *string `json:"Url,omitempty"` 702 // The HTTP method we should use when calling the `url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 703 Method *string `json:"Method,omitempty"` 704 // 705 Status *string `json:"Status,omitempty"` 706 // The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored. 707 FallbackUrl *string `json:"FallbackUrl,omitempty"` 708 // The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 709 FallbackMethod *string `json:"FallbackMethod,omitempty"` 710 // The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted). 711 StatusCallback *string `json:"StatusCallback,omitempty"` 712 // The HTTP method we should use when requesting the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored. 713 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 714 // TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive 715 Twiml *string `json:"Twiml,omitempty"` 716 // The maximum duration of the call in seconds. Constraints depend on account and configuration. 717 TimeLimit *int `json:"TimeLimit,omitempty"` 718 } 719 720 func (params *UpdateCallParams) SetPathAccountSid(PathAccountSid string) *UpdateCallParams { 721 params.PathAccountSid = &PathAccountSid 722 return params 723 } 724 func (params *UpdateCallParams) SetUrl(Url string) *UpdateCallParams { 725 params.Url = &Url 726 return params 727 } 728 func (params *UpdateCallParams) SetMethod(Method string) *UpdateCallParams { 729 params.Method = &Method 730 return params 731 } 732 func (params *UpdateCallParams) SetStatus(Status string) *UpdateCallParams { 733 params.Status = &Status 734 return params 735 } 736 func (params *UpdateCallParams) SetFallbackUrl(FallbackUrl string) *UpdateCallParams { 737 params.FallbackUrl = &FallbackUrl 738 return params 739 } 740 func (params *UpdateCallParams) SetFallbackMethod(FallbackMethod string) *UpdateCallParams { 741 params.FallbackMethod = &FallbackMethod 742 return params 743 } 744 func (params *UpdateCallParams) SetStatusCallback(StatusCallback string) *UpdateCallParams { 745 params.StatusCallback = &StatusCallback 746 return params 747 } 748 func (params *UpdateCallParams) SetStatusCallbackMethod(StatusCallbackMethod string) *UpdateCallParams { 749 params.StatusCallbackMethod = &StatusCallbackMethod 750 return params 751 } 752 func (params *UpdateCallParams) SetTwiml(Twiml string) *UpdateCallParams { 753 params.Twiml = &Twiml 754 return params 755 } 756 func (params *UpdateCallParams) SetTimeLimit(TimeLimit int) *UpdateCallParams { 757 params.TimeLimit = &TimeLimit 758 return params 759 } 760 761 // Initiates a call redirect or terminates a call 762 func (c *ApiService) UpdateCall(Sid string, params *UpdateCallParams) (*ApiV2010Call, error) { 763 path := "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json" 764 if params != nil && params.PathAccountSid != nil { 765 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 766 } else { 767 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 768 } 769 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 770 771 data := url.Values{} 772 headers := make(map[string]interface{}) 773 774 if params != nil && params.Url != nil { 775 data.Set("Url", *params.Url) 776 } 777 if params != nil && params.Method != nil { 778 data.Set("Method", *params.Method) 779 } 780 if params != nil && params.Status != nil { 781 data.Set("Status", *params.Status) 782 } 783 if params != nil && params.FallbackUrl != nil { 784 data.Set("FallbackUrl", *params.FallbackUrl) 785 } 786 if params != nil && params.FallbackMethod != nil { 787 data.Set("FallbackMethod", *params.FallbackMethod) 788 } 789 if params != nil && params.StatusCallback != nil { 790 data.Set("StatusCallback", *params.StatusCallback) 791 } 792 if params != nil && params.StatusCallbackMethod != nil { 793 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 794 } 795 if params != nil && params.Twiml != nil { 796 data.Set("Twiml", *params.Twiml) 797 } 798 if params != nil && params.TimeLimit != nil { 799 data.Set("TimeLimit", fmt.Sprint(*params.TimeLimit)) 800 } 801 802 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 803 if err != nil { 804 return nil, err 805 } 806 807 defer resp.Body.Close() 808 809 ps := &ApiV2010Call{} 810 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 811 return nil, err 812 } 813 814 return ps, err 815 }