github.com/twilio/twilio-go@v1.20.1/rest/insights/v1/voice_summaries.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Insights 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 22 "github.com/twilio/twilio-go/client" 23 ) 24 25 // Optional parameters for the method 'ListCallSummaries' 26 type ListCallSummariesParams struct { 27 // A calling party. Could be an E.164 number, a SIP URI, or a Twilio Client registered name. 28 From *string `json:"From,omitempty"` 29 // A called party. Could be an E.164 number, a SIP URI, or a Twilio Client registered name. 30 To *string `json:"To,omitempty"` 31 // An origination carrier. 32 FromCarrier *string `json:"FromCarrier,omitempty"` 33 // A destination carrier. 34 ToCarrier *string `json:"ToCarrier,omitempty"` 35 // A source country code based on phone number in From. 36 FromCountryCode *string `json:"FromCountryCode,omitempty"` 37 // A destination country code. Based on phone number in To. 38 ToCountryCode *string `json:"ToCountryCode,omitempty"` 39 // A boolean flag indicating whether or not the calls were branded using Twilio Branded Calls. 40 Branded *bool `json:"Branded,omitempty"` 41 // A boolean flag indicating whether or not the caller was verified using SHAKEN/STIR. 42 VerifiedCaller *bool `json:"VerifiedCaller,omitempty"` 43 // A boolean flag indicating the presence of one or more [Voice Insights Call Tags](https://www.twilio.com/docs/voice/voice-insights/api/call/details-call-tags). 44 HasTag *bool `json:"HasTag,omitempty"` 45 // A Start time of the calls. xm (x minutes), xh (x hours), xd (x days), 1w, 30m, 3d, 4w or datetime-ISO. Defaults to 4h. 46 StartTime *string `json:"StartTime,omitempty"` 47 // An End Time of the calls. xm (x minutes), xh (x hours), xd (x days), 1w, 30m, 3d, 4w or datetime-ISO. Defaults to 0m. 48 EndTime *string `json:"EndTime,omitempty"` 49 // A Call Type of the calls. One of `carrier`, `sip`, `trunking` or `client`. 50 CallType *string `json:"CallType,omitempty"` 51 // A Call State of the calls. One of `ringing`, `completed`, `busy`, `fail`, `noanswer`, `canceled`, `answered`, `undialed`. 52 CallState *string `json:"CallState,omitempty"` 53 // A Direction of the calls. One of `outbound_api`, `outbound_dial`, `inbound`, `trunking_originating`, `trunking_terminating`. 54 Direction *string `json:"Direction,omitempty"` 55 // A Processing State of the Call Summaries. One of `completed`, `partial` or `all`. 56 ProcessingState *string `json:"ProcessingState,omitempty"` 57 // A Sort By criterion for the returned list of Call Summaries. One of `start_time` or `end_time`. 58 SortBy *string `json:"SortBy,omitempty"` 59 // A unique SID identifier of a Subaccount. 60 Subaccount *string `json:"Subaccount,omitempty"` 61 // A boolean flag indicating an abnormal session where the last SIP response was not 200 OK. 62 AbnormalSession *bool `json:"AbnormalSession,omitempty"` 63 // An Answered By value for the calls based on `Answering Machine Detection (AMD)`. One of `unknown`, `machine_start`, `machine_end_beep`, `machine_end_silence`, `machine_end_other`, `human` or `fax`. 64 AnsweredBy *string `json:"AnsweredBy,omitempty"` 65 // Either machine or human. 66 AnsweredByAnnotation *string `json:"AnsweredByAnnotation,omitempty"` 67 // A Connectivity Issue with the calls. One of `no_connectivity_issue`, `invalid_number`, `caller_id`, `dropped_call`, or `number_reachability`. 68 ConnectivityIssueAnnotation *string `json:"ConnectivityIssueAnnotation,omitempty"` 69 // A subjective Quality Issue with the calls. One of `no_quality_issue`, `low_volume`, `choppy_robotic`, `echo`, `dtmf`, `latency`, `owa`, `static_noise`. 70 QualityIssueAnnotation *string `json:"QualityIssueAnnotation,omitempty"` 71 // A boolean flag indicating spam calls. 72 SpamAnnotation *bool `json:"SpamAnnotation,omitempty"` 73 // A Call Score of the calls. Use a range of 1-5 to indicate the call experience score, with the following mapping as a reference for the rated call [5: Excellent, 4: Good, 3 : Fair, 2 : Poor, 1: Bad]. 74 CallScoreAnnotation *string `json:"CallScoreAnnotation,omitempty"` 75 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 76 PageSize *int `json:"PageSize,omitempty"` 77 // Max number of records to return. 78 Limit *int `json:"limit,omitempty"` 79 } 80 81 func (params *ListCallSummariesParams) SetFrom(From string) *ListCallSummariesParams { 82 params.From = &From 83 return params 84 } 85 func (params *ListCallSummariesParams) SetTo(To string) *ListCallSummariesParams { 86 params.To = &To 87 return params 88 } 89 func (params *ListCallSummariesParams) SetFromCarrier(FromCarrier string) *ListCallSummariesParams { 90 params.FromCarrier = &FromCarrier 91 return params 92 } 93 func (params *ListCallSummariesParams) SetToCarrier(ToCarrier string) *ListCallSummariesParams { 94 params.ToCarrier = &ToCarrier 95 return params 96 } 97 func (params *ListCallSummariesParams) SetFromCountryCode(FromCountryCode string) *ListCallSummariesParams { 98 params.FromCountryCode = &FromCountryCode 99 return params 100 } 101 func (params *ListCallSummariesParams) SetToCountryCode(ToCountryCode string) *ListCallSummariesParams { 102 params.ToCountryCode = &ToCountryCode 103 return params 104 } 105 func (params *ListCallSummariesParams) SetBranded(Branded bool) *ListCallSummariesParams { 106 params.Branded = &Branded 107 return params 108 } 109 func (params *ListCallSummariesParams) SetVerifiedCaller(VerifiedCaller bool) *ListCallSummariesParams { 110 params.VerifiedCaller = &VerifiedCaller 111 return params 112 } 113 func (params *ListCallSummariesParams) SetHasTag(HasTag bool) *ListCallSummariesParams { 114 params.HasTag = &HasTag 115 return params 116 } 117 func (params *ListCallSummariesParams) SetStartTime(StartTime string) *ListCallSummariesParams { 118 params.StartTime = &StartTime 119 return params 120 } 121 func (params *ListCallSummariesParams) SetEndTime(EndTime string) *ListCallSummariesParams { 122 params.EndTime = &EndTime 123 return params 124 } 125 func (params *ListCallSummariesParams) SetCallType(CallType string) *ListCallSummariesParams { 126 params.CallType = &CallType 127 return params 128 } 129 func (params *ListCallSummariesParams) SetCallState(CallState string) *ListCallSummariesParams { 130 params.CallState = &CallState 131 return params 132 } 133 func (params *ListCallSummariesParams) SetDirection(Direction string) *ListCallSummariesParams { 134 params.Direction = &Direction 135 return params 136 } 137 func (params *ListCallSummariesParams) SetProcessingState(ProcessingState string) *ListCallSummariesParams { 138 params.ProcessingState = &ProcessingState 139 return params 140 } 141 func (params *ListCallSummariesParams) SetSortBy(SortBy string) *ListCallSummariesParams { 142 params.SortBy = &SortBy 143 return params 144 } 145 func (params *ListCallSummariesParams) SetSubaccount(Subaccount string) *ListCallSummariesParams { 146 params.Subaccount = &Subaccount 147 return params 148 } 149 func (params *ListCallSummariesParams) SetAbnormalSession(AbnormalSession bool) *ListCallSummariesParams { 150 params.AbnormalSession = &AbnormalSession 151 return params 152 } 153 func (params *ListCallSummariesParams) SetAnsweredBy(AnsweredBy string) *ListCallSummariesParams { 154 params.AnsweredBy = &AnsweredBy 155 return params 156 } 157 func (params *ListCallSummariesParams) SetAnsweredByAnnotation(AnsweredByAnnotation string) *ListCallSummariesParams { 158 params.AnsweredByAnnotation = &AnsweredByAnnotation 159 return params 160 } 161 func (params *ListCallSummariesParams) SetConnectivityIssueAnnotation(ConnectivityIssueAnnotation string) *ListCallSummariesParams { 162 params.ConnectivityIssueAnnotation = &ConnectivityIssueAnnotation 163 return params 164 } 165 func (params *ListCallSummariesParams) SetQualityIssueAnnotation(QualityIssueAnnotation string) *ListCallSummariesParams { 166 params.QualityIssueAnnotation = &QualityIssueAnnotation 167 return params 168 } 169 func (params *ListCallSummariesParams) SetSpamAnnotation(SpamAnnotation bool) *ListCallSummariesParams { 170 params.SpamAnnotation = &SpamAnnotation 171 return params 172 } 173 func (params *ListCallSummariesParams) SetCallScoreAnnotation(CallScoreAnnotation string) *ListCallSummariesParams { 174 params.CallScoreAnnotation = &CallScoreAnnotation 175 return params 176 } 177 func (params *ListCallSummariesParams) SetPageSize(PageSize int) *ListCallSummariesParams { 178 params.PageSize = &PageSize 179 return params 180 } 181 func (params *ListCallSummariesParams) SetLimit(Limit int) *ListCallSummariesParams { 182 params.Limit = &Limit 183 return params 184 } 185 186 // Retrieve a single page of CallSummaries records from the API. Request is executed immediately. 187 func (c *ApiService) PageCallSummaries(params *ListCallSummariesParams, pageToken, pageNumber string) (*ListCallSummariesResponse, error) { 188 path := "/v1/Voice/Summaries" 189 190 data := url.Values{} 191 headers := make(map[string]interface{}) 192 193 if params != nil && params.From != nil { 194 data.Set("From", *params.From) 195 } 196 if params != nil && params.To != nil { 197 data.Set("To", *params.To) 198 } 199 if params != nil && params.FromCarrier != nil { 200 data.Set("FromCarrier", *params.FromCarrier) 201 } 202 if params != nil && params.ToCarrier != nil { 203 data.Set("ToCarrier", *params.ToCarrier) 204 } 205 if params != nil && params.FromCountryCode != nil { 206 data.Set("FromCountryCode", *params.FromCountryCode) 207 } 208 if params != nil && params.ToCountryCode != nil { 209 data.Set("ToCountryCode", *params.ToCountryCode) 210 } 211 if params != nil && params.Branded != nil { 212 data.Set("Branded", fmt.Sprint(*params.Branded)) 213 } 214 if params != nil && params.VerifiedCaller != nil { 215 data.Set("VerifiedCaller", fmt.Sprint(*params.VerifiedCaller)) 216 } 217 if params != nil && params.HasTag != nil { 218 data.Set("HasTag", fmt.Sprint(*params.HasTag)) 219 } 220 if params != nil && params.StartTime != nil { 221 data.Set("StartTime", *params.StartTime) 222 } 223 if params != nil && params.EndTime != nil { 224 data.Set("EndTime", *params.EndTime) 225 } 226 if params != nil && params.CallType != nil { 227 data.Set("CallType", *params.CallType) 228 } 229 if params != nil && params.CallState != nil { 230 data.Set("CallState", *params.CallState) 231 } 232 if params != nil && params.Direction != nil { 233 data.Set("Direction", *params.Direction) 234 } 235 if params != nil && params.ProcessingState != nil { 236 data.Set("ProcessingState", *params.ProcessingState) 237 } 238 if params != nil && params.SortBy != nil { 239 data.Set("SortBy", *params.SortBy) 240 } 241 if params != nil && params.Subaccount != nil { 242 data.Set("Subaccount", *params.Subaccount) 243 } 244 if params != nil && params.AbnormalSession != nil { 245 data.Set("AbnormalSession", fmt.Sprint(*params.AbnormalSession)) 246 } 247 if params != nil && params.AnsweredBy != nil { 248 data.Set("AnsweredBy", *params.AnsweredBy) 249 } 250 if params != nil && params.AnsweredByAnnotation != nil { 251 data.Set("AnsweredByAnnotation", *params.AnsweredByAnnotation) 252 } 253 if params != nil && params.ConnectivityIssueAnnotation != nil { 254 data.Set("ConnectivityIssueAnnotation", *params.ConnectivityIssueAnnotation) 255 } 256 if params != nil && params.QualityIssueAnnotation != nil { 257 data.Set("QualityIssueAnnotation", *params.QualityIssueAnnotation) 258 } 259 if params != nil && params.SpamAnnotation != nil { 260 data.Set("SpamAnnotation", fmt.Sprint(*params.SpamAnnotation)) 261 } 262 if params != nil && params.CallScoreAnnotation != nil { 263 data.Set("CallScoreAnnotation", *params.CallScoreAnnotation) 264 } 265 if params != nil && params.PageSize != nil { 266 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 267 } 268 269 if pageToken != "" { 270 data.Set("PageToken", pageToken) 271 } 272 if pageNumber != "" { 273 data.Set("Page", pageNumber) 274 } 275 276 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 277 if err != nil { 278 return nil, err 279 } 280 281 defer resp.Body.Close() 282 283 ps := &ListCallSummariesResponse{} 284 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 285 return nil, err 286 } 287 288 return ps, err 289 } 290 291 // Lists CallSummaries records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 292 func (c *ApiService) ListCallSummaries(params *ListCallSummariesParams) ([]InsightsV1CallSummaries, error) { 293 response, errors := c.StreamCallSummaries(params) 294 295 records := make([]InsightsV1CallSummaries, 0) 296 for record := range response { 297 records = append(records, record) 298 } 299 300 if err := <-errors; err != nil { 301 return nil, err 302 } 303 304 return records, nil 305 } 306 307 // Streams CallSummaries records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 308 func (c *ApiService) StreamCallSummaries(params *ListCallSummariesParams) (chan InsightsV1CallSummaries, chan error) { 309 if params == nil { 310 params = &ListCallSummariesParams{} 311 } 312 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 313 314 recordChannel := make(chan InsightsV1CallSummaries, 1) 315 errorChannel := make(chan error, 1) 316 317 response, err := c.PageCallSummaries(params, "", "") 318 if err != nil { 319 errorChannel <- err 320 close(recordChannel) 321 close(errorChannel) 322 } else { 323 go c.streamCallSummaries(response, params, recordChannel, errorChannel) 324 } 325 326 return recordChannel, errorChannel 327 } 328 329 func (c *ApiService) streamCallSummaries(response *ListCallSummariesResponse, params *ListCallSummariesParams, recordChannel chan InsightsV1CallSummaries, errorChannel chan error) { 330 curRecord := 1 331 332 for response != nil { 333 responseRecords := response.CallSummaries 334 for item := range responseRecords { 335 recordChannel <- responseRecords[item] 336 curRecord += 1 337 if params.Limit != nil && *params.Limit < curRecord { 338 close(recordChannel) 339 close(errorChannel) 340 return 341 } 342 } 343 344 record, err := client.GetNext(c.baseURL, response, c.getNextListCallSummariesResponse) 345 if err != nil { 346 errorChannel <- err 347 break 348 } else if record == nil { 349 break 350 } 351 352 response = record.(*ListCallSummariesResponse) 353 } 354 355 close(recordChannel) 356 close(errorChannel) 357 } 358 359 func (c *ApiService) getNextListCallSummariesResponse(nextPageUrl string) (interface{}, error) { 360 if nextPageUrl == "" { 361 return nil, nil 362 } 363 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 364 if err != nil { 365 return nil, err 366 } 367 368 defer resp.Body.Close() 369 370 ps := &ListCallSummariesResponse{} 371 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 372 return nil, err 373 } 374 return ps, nil 375 }