github.com/twilio/twilio-go@v1.20.1/rest/taskrouter/v1/workspaces.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Taskrouter 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 23 "github.com/twilio/twilio-go/client" 24 ) 25 26 // Optional parameters for the method 'CreateWorkspace' 27 type CreateWorkspaceParams struct { 28 // A descriptive string that you create to describe the Workspace resource. It can be up to 64 characters long. For example: `Customer Support` or `2014 Election Campaign`. 29 FriendlyName *string `json:"FriendlyName,omitempty"` 30 // The URL we should call when an event occurs. If provided, the Workspace will publish events to this URL, for example, to collect data for reporting. See [Workspace Events](https://www.twilio.com/docs/taskrouter/api/event) for more information. This parameter supports Twilio's [Webhooks (HTTP callbacks) Connection Overrides](https://www.twilio.com/docs/usage/webhooks/webhooks-connection-overrides). 31 EventCallbackUrl *string `json:"EventCallbackUrl,omitempty"` 32 // The list of Workspace events for which to call event_callback_url. For example, if `EventsFilter=task.created, task.canceled, worker.activity.update`, then TaskRouter will call event_callback_url only when a task is created, canceled, or a Worker activity is updated. 33 EventsFilter *string `json:"EventsFilter,omitempty"` 34 // Whether to enable multi-tasking. Can be: `true` to enable multi-tasking, or `false` to disable it. However, all workspaces should be created as multi-tasking. The default is `true`. Multi-tasking allows Workers to handle multiple Tasks simultaneously. When enabled (`true`), each Worker can receive parallel reservations up to the per-channel maximums defined in the Workers section. In single-tasking mode (legacy mode), each Worker will only receive a new reservation when the previous task is completed. Learn more at [Multitasking](https://www.twilio.com/docs/taskrouter/multitasking). 35 MultiTaskEnabled *bool `json:"MultiTaskEnabled,omitempty"` 36 // An available template name. Can be: `NONE` or `FIFO` and the default is `NONE`. Pre-configures the Workspace with the Workflow and Activities specified in the template. `NONE` will create a Workspace with only a set of default activities. `FIFO` will configure TaskRouter with a set of default activities and a single TaskQueue for first-in, first-out distribution, which can be useful when you are getting started with TaskRouter. 37 Template *string `json:"Template,omitempty"` 38 // 39 PrioritizeQueueOrder *string `json:"PrioritizeQueueOrder,omitempty"` 40 } 41 42 func (params *CreateWorkspaceParams) SetFriendlyName(FriendlyName string) *CreateWorkspaceParams { 43 params.FriendlyName = &FriendlyName 44 return params 45 } 46 func (params *CreateWorkspaceParams) SetEventCallbackUrl(EventCallbackUrl string) *CreateWorkspaceParams { 47 params.EventCallbackUrl = &EventCallbackUrl 48 return params 49 } 50 func (params *CreateWorkspaceParams) SetEventsFilter(EventsFilter string) *CreateWorkspaceParams { 51 params.EventsFilter = &EventsFilter 52 return params 53 } 54 func (params *CreateWorkspaceParams) SetMultiTaskEnabled(MultiTaskEnabled bool) *CreateWorkspaceParams { 55 params.MultiTaskEnabled = &MultiTaskEnabled 56 return params 57 } 58 func (params *CreateWorkspaceParams) SetTemplate(Template string) *CreateWorkspaceParams { 59 params.Template = &Template 60 return params 61 } 62 func (params *CreateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrder string) *CreateWorkspaceParams { 63 params.PrioritizeQueueOrder = &PrioritizeQueueOrder 64 return params 65 } 66 67 // 68 func (c *ApiService) CreateWorkspace(params *CreateWorkspaceParams) (*TaskrouterV1Workspace, error) { 69 path := "/v1/Workspaces" 70 71 data := url.Values{} 72 headers := make(map[string]interface{}) 73 74 if params != nil && params.FriendlyName != nil { 75 data.Set("FriendlyName", *params.FriendlyName) 76 } 77 if params != nil && params.EventCallbackUrl != nil { 78 data.Set("EventCallbackUrl", *params.EventCallbackUrl) 79 } 80 if params != nil && params.EventsFilter != nil { 81 data.Set("EventsFilter", *params.EventsFilter) 82 } 83 if params != nil && params.MultiTaskEnabled != nil { 84 data.Set("MultiTaskEnabled", fmt.Sprint(*params.MultiTaskEnabled)) 85 } 86 if params != nil && params.Template != nil { 87 data.Set("Template", *params.Template) 88 } 89 if params != nil && params.PrioritizeQueueOrder != nil { 90 data.Set("PrioritizeQueueOrder", *params.PrioritizeQueueOrder) 91 } 92 93 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 94 if err != nil { 95 return nil, err 96 } 97 98 defer resp.Body.Close() 99 100 ps := &TaskrouterV1Workspace{} 101 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 102 return nil, err 103 } 104 105 return ps, err 106 } 107 108 // 109 func (c *ApiService) DeleteWorkspace(Sid string) error { 110 path := "/v1/Workspaces/{Sid}" 111 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 112 113 data := url.Values{} 114 headers := make(map[string]interface{}) 115 116 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 117 if err != nil { 118 return err 119 } 120 121 defer resp.Body.Close() 122 123 return nil 124 } 125 126 // 127 func (c *ApiService) FetchWorkspace(Sid string) (*TaskrouterV1Workspace, error) { 128 path := "/v1/Workspaces/{Sid}" 129 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 130 131 data := url.Values{} 132 headers := make(map[string]interface{}) 133 134 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 135 if err != nil { 136 return nil, err 137 } 138 139 defer resp.Body.Close() 140 141 ps := &TaskrouterV1Workspace{} 142 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 143 return nil, err 144 } 145 146 return ps, err 147 } 148 149 // Optional parameters for the method 'ListWorkspace' 150 type ListWorkspaceParams struct { 151 // The `friendly_name` of the Workspace resources to read. For example `Customer Support` or `2014 Election Campaign`. 152 FriendlyName *string `json:"FriendlyName,omitempty"` 153 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 154 PageSize *int `json:"PageSize,omitempty"` 155 // Max number of records to return. 156 Limit *int `json:"limit,omitempty"` 157 } 158 159 func (params *ListWorkspaceParams) SetFriendlyName(FriendlyName string) *ListWorkspaceParams { 160 params.FriendlyName = &FriendlyName 161 return params 162 } 163 func (params *ListWorkspaceParams) SetPageSize(PageSize int) *ListWorkspaceParams { 164 params.PageSize = &PageSize 165 return params 166 } 167 func (params *ListWorkspaceParams) SetLimit(Limit int) *ListWorkspaceParams { 168 params.Limit = &Limit 169 return params 170 } 171 172 // Retrieve a single page of Workspace records from the API. Request is executed immediately. 173 func (c *ApiService) PageWorkspace(params *ListWorkspaceParams, pageToken, pageNumber string) (*ListWorkspaceResponse, error) { 174 path := "/v1/Workspaces" 175 176 data := url.Values{} 177 headers := make(map[string]interface{}) 178 179 if params != nil && params.FriendlyName != nil { 180 data.Set("FriendlyName", *params.FriendlyName) 181 } 182 if params != nil && params.PageSize != nil { 183 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 184 } 185 186 if pageToken != "" { 187 data.Set("PageToken", pageToken) 188 } 189 if pageNumber != "" { 190 data.Set("Page", pageNumber) 191 } 192 193 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 194 if err != nil { 195 return nil, err 196 } 197 198 defer resp.Body.Close() 199 200 ps := &ListWorkspaceResponse{} 201 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 202 return nil, err 203 } 204 205 return ps, err 206 } 207 208 // Lists Workspace records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 209 func (c *ApiService) ListWorkspace(params *ListWorkspaceParams) ([]TaskrouterV1Workspace, error) { 210 response, errors := c.StreamWorkspace(params) 211 212 records := make([]TaskrouterV1Workspace, 0) 213 for record := range response { 214 records = append(records, record) 215 } 216 217 if err := <-errors; err != nil { 218 return nil, err 219 } 220 221 return records, nil 222 } 223 224 // Streams Workspace records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 225 func (c *ApiService) StreamWorkspace(params *ListWorkspaceParams) (chan TaskrouterV1Workspace, chan error) { 226 if params == nil { 227 params = &ListWorkspaceParams{} 228 } 229 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 230 231 recordChannel := make(chan TaskrouterV1Workspace, 1) 232 errorChannel := make(chan error, 1) 233 234 response, err := c.PageWorkspace(params, "", "") 235 if err != nil { 236 errorChannel <- err 237 close(recordChannel) 238 close(errorChannel) 239 } else { 240 go c.streamWorkspace(response, params, recordChannel, errorChannel) 241 } 242 243 return recordChannel, errorChannel 244 } 245 246 func (c *ApiService) streamWorkspace(response *ListWorkspaceResponse, params *ListWorkspaceParams, recordChannel chan TaskrouterV1Workspace, errorChannel chan error) { 247 curRecord := 1 248 249 for response != nil { 250 responseRecords := response.Workspaces 251 for item := range responseRecords { 252 recordChannel <- responseRecords[item] 253 curRecord += 1 254 if params.Limit != nil && *params.Limit < curRecord { 255 close(recordChannel) 256 close(errorChannel) 257 return 258 } 259 } 260 261 record, err := client.GetNext(c.baseURL, response, c.getNextListWorkspaceResponse) 262 if err != nil { 263 errorChannel <- err 264 break 265 } else if record == nil { 266 break 267 } 268 269 response = record.(*ListWorkspaceResponse) 270 } 271 272 close(recordChannel) 273 close(errorChannel) 274 } 275 276 func (c *ApiService) getNextListWorkspaceResponse(nextPageUrl string) (interface{}, error) { 277 if nextPageUrl == "" { 278 return nil, nil 279 } 280 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 281 if err != nil { 282 return nil, err 283 } 284 285 defer resp.Body.Close() 286 287 ps := &ListWorkspaceResponse{} 288 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 289 return nil, err 290 } 291 return ps, nil 292 } 293 294 // Optional parameters for the method 'UpdateWorkspace' 295 type UpdateWorkspaceParams struct { 296 // The SID of the Activity that will be used when new Workers are created in the Workspace. 297 DefaultActivitySid *string `json:"DefaultActivitySid,omitempty"` 298 // The URL we should call when an event occurs. See [Workspace Events](https://www.twilio.com/docs/taskrouter/api/event) for more information. This parameter supports Twilio's [Webhooks (HTTP callbacks) Connection Overrides](https://www.twilio.com/docs/usage/webhooks/webhooks-connection-overrides). 299 EventCallbackUrl *string `json:"EventCallbackUrl,omitempty"` 300 // The list of Workspace events for which to call event_callback_url. For example if `EventsFilter=task.created,task.canceled,worker.activity.update`, then TaskRouter will call event_callback_url only when a task is created, canceled, or a Worker activity is updated. 301 EventsFilter *string `json:"EventsFilter,omitempty"` 302 // A descriptive string that you create to describe the Workspace resource. For example: `Sales Call Center` or `Customer Support Team`. 303 FriendlyName *string `json:"FriendlyName,omitempty"` 304 // Whether to enable multi-tasking. Can be: `true` to enable multi-tasking, or `false` to disable it. However, all workspaces should be maintained as multi-tasking. There is no default when omitting this parameter. A multi-tasking Workspace can't be updated to single-tasking unless it is not a Flex Project and another (legacy) single-tasking Workspace exists. Multi-tasking allows Workers to handle multiple Tasks simultaneously. In multi-tasking mode, each Worker can receive parallel reservations up to the per-channel maximums defined in the Workers section. In single-tasking mode (legacy mode), each Worker will only receive a new reservation when the previous task is completed. Learn more at [Multitasking](https://www.twilio.com/docs/taskrouter/multitasking). 305 MultiTaskEnabled *bool `json:"MultiTaskEnabled,omitempty"` 306 // The SID of the Activity that will be assigned to a Worker when a Task reservation times out without a response. 307 TimeoutActivitySid *string `json:"TimeoutActivitySid,omitempty"` 308 // 309 PrioritizeQueueOrder *string `json:"PrioritizeQueueOrder,omitempty"` 310 } 311 312 func (params *UpdateWorkspaceParams) SetDefaultActivitySid(DefaultActivitySid string) *UpdateWorkspaceParams { 313 params.DefaultActivitySid = &DefaultActivitySid 314 return params 315 } 316 func (params *UpdateWorkspaceParams) SetEventCallbackUrl(EventCallbackUrl string) *UpdateWorkspaceParams { 317 params.EventCallbackUrl = &EventCallbackUrl 318 return params 319 } 320 func (params *UpdateWorkspaceParams) SetEventsFilter(EventsFilter string) *UpdateWorkspaceParams { 321 params.EventsFilter = &EventsFilter 322 return params 323 } 324 func (params *UpdateWorkspaceParams) SetFriendlyName(FriendlyName string) *UpdateWorkspaceParams { 325 params.FriendlyName = &FriendlyName 326 return params 327 } 328 func (params *UpdateWorkspaceParams) SetMultiTaskEnabled(MultiTaskEnabled bool) *UpdateWorkspaceParams { 329 params.MultiTaskEnabled = &MultiTaskEnabled 330 return params 331 } 332 func (params *UpdateWorkspaceParams) SetTimeoutActivitySid(TimeoutActivitySid string) *UpdateWorkspaceParams { 333 params.TimeoutActivitySid = &TimeoutActivitySid 334 return params 335 } 336 func (params *UpdateWorkspaceParams) SetPrioritizeQueueOrder(PrioritizeQueueOrder string) *UpdateWorkspaceParams { 337 params.PrioritizeQueueOrder = &PrioritizeQueueOrder 338 return params 339 } 340 341 // 342 func (c *ApiService) UpdateWorkspace(Sid string, params *UpdateWorkspaceParams) (*TaskrouterV1Workspace, error) { 343 path := "/v1/Workspaces/{Sid}" 344 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 345 346 data := url.Values{} 347 headers := make(map[string]interface{}) 348 349 if params != nil && params.DefaultActivitySid != nil { 350 data.Set("DefaultActivitySid", *params.DefaultActivitySid) 351 } 352 if params != nil && params.EventCallbackUrl != nil { 353 data.Set("EventCallbackUrl", *params.EventCallbackUrl) 354 } 355 if params != nil && params.EventsFilter != nil { 356 data.Set("EventsFilter", *params.EventsFilter) 357 } 358 if params != nil && params.FriendlyName != nil { 359 data.Set("FriendlyName", *params.FriendlyName) 360 } 361 if params != nil && params.MultiTaskEnabled != nil { 362 data.Set("MultiTaskEnabled", fmt.Sprint(*params.MultiTaskEnabled)) 363 } 364 if params != nil && params.TimeoutActivitySid != nil { 365 data.Set("TimeoutActivitySid", *params.TimeoutActivitySid) 366 } 367 if params != nil && params.PrioritizeQueueOrder != nil { 368 data.Set("PrioritizeQueueOrder", *params.PrioritizeQueueOrder) 369 } 370 371 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 372 if err != nil { 373 return nil, err 374 } 375 376 defer resp.Body.Close() 377 378 ps := &TaskrouterV1Workspace{} 379 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 380 return nil, err 381 } 382 383 return ps, err 384 }