github.com/twilio/twilio-go@v1.20.1/rest/flex/v1/insights_quality_management_assessments.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Flex 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 'CreateInsightsAssessments' 27 type CreateInsightsAssessmentsParams struct { 28 // The Authorization HTTP request header 29 Authorization *string `json:"Authorization,omitempty"` 30 // The SID of the category 31 CategorySid *string `json:"CategorySid,omitempty"` 32 // The name of the category 33 CategoryName *string `json:"CategoryName,omitempty"` 34 // Segment Id of the conversation 35 SegmentId *string `json:"SegmentId,omitempty"` 36 // The id of the Agent 37 AgentId *string `json:"AgentId,omitempty"` 38 // The offset of the conversation. 39 Offset *float32 `json:"Offset,omitempty"` 40 // The question SID selected for assessment 41 MetricId *string `json:"MetricId,omitempty"` 42 // The question name of the assessment 43 MetricName *string `json:"MetricName,omitempty"` 44 // The answer text selected by user 45 AnswerText *string `json:"AnswerText,omitempty"` 46 // The id of the answer selected by user 47 AnswerId *string `json:"AnswerId,omitempty"` 48 // Questionnaire SID of the associated question 49 QuestionnaireSid *string `json:"QuestionnaireSid,omitempty"` 50 } 51 52 func (params *CreateInsightsAssessmentsParams) SetAuthorization(Authorization string) *CreateInsightsAssessmentsParams { 53 params.Authorization = &Authorization 54 return params 55 } 56 func (params *CreateInsightsAssessmentsParams) SetCategorySid(CategorySid string) *CreateInsightsAssessmentsParams { 57 params.CategorySid = &CategorySid 58 return params 59 } 60 func (params *CreateInsightsAssessmentsParams) SetCategoryName(CategoryName string) *CreateInsightsAssessmentsParams { 61 params.CategoryName = &CategoryName 62 return params 63 } 64 func (params *CreateInsightsAssessmentsParams) SetSegmentId(SegmentId string) *CreateInsightsAssessmentsParams { 65 params.SegmentId = &SegmentId 66 return params 67 } 68 func (params *CreateInsightsAssessmentsParams) SetAgentId(AgentId string) *CreateInsightsAssessmentsParams { 69 params.AgentId = &AgentId 70 return params 71 } 72 func (params *CreateInsightsAssessmentsParams) SetOffset(Offset float32) *CreateInsightsAssessmentsParams { 73 params.Offset = &Offset 74 return params 75 } 76 func (params *CreateInsightsAssessmentsParams) SetMetricId(MetricId string) *CreateInsightsAssessmentsParams { 77 params.MetricId = &MetricId 78 return params 79 } 80 func (params *CreateInsightsAssessmentsParams) SetMetricName(MetricName string) *CreateInsightsAssessmentsParams { 81 params.MetricName = &MetricName 82 return params 83 } 84 func (params *CreateInsightsAssessmentsParams) SetAnswerText(AnswerText string) *CreateInsightsAssessmentsParams { 85 params.AnswerText = &AnswerText 86 return params 87 } 88 func (params *CreateInsightsAssessmentsParams) SetAnswerId(AnswerId string) *CreateInsightsAssessmentsParams { 89 params.AnswerId = &AnswerId 90 return params 91 } 92 func (params *CreateInsightsAssessmentsParams) SetQuestionnaireSid(QuestionnaireSid string) *CreateInsightsAssessmentsParams { 93 params.QuestionnaireSid = &QuestionnaireSid 94 return params 95 } 96 97 // Add assessments against conversation to dynamo db. Used in assessments screen by user. Users can select the questionnaire and pick up answers for each and every question. 98 func (c *ApiService) CreateInsightsAssessments(params *CreateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { 99 path := "/v1/Insights/QualityManagement/Assessments" 100 101 data := url.Values{} 102 headers := make(map[string]interface{}) 103 104 if params != nil && params.CategorySid != nil { 105 data.Set("CategorySid", *params.CategorySid) 106 } 107 if params != nil && params.CategoryName != nil { 108 data.Set("CategoryName", *params.CategoryName) 109 } 110 if params != nil && params.SegmentId != nil { 111 data.Set("SegmentId", *params.SegmentId) 112 } 113 if params != nil && params.AgentId != nil { 114 data.Set("AgentId", *params.AgentId) 115 } 116 if params != nil && params.Offset != nil { 117 data.Set("Offset", fmt.Sprint(*params.Offset)) 118 } 119 if params != nil && params.MetricId != nil { 120 data.Set("MetricId", *params.MetricId) 121 } 122 if params != nil && params.MetricName != nil { 123 data.Set("MetricName", *params.MetricName) 124 } 125 if params != nil && params.AnswerText != nil { 126 data.Set("AnswerText", *params.AnswerText) 127 } 128 if params != nil && params.AnswerId != nil { 129 data.Set("AnswerId", *params.AnswerId) 130 } 131 if params != nil && params.QuestionnaireSid != nil { 132 data.Set("QuestionnaireSid", *params.QuestionnaireSid) 133 } 134 135 if params != nil && params.Authorization != nil { 136 headers["Authorization"] = *params.Authorization 137 } 138 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 139 if err != nil { 140 return nil, err 141 } 142 143 defer resp.Body.Close() 144 145 ps := &FlexV1InsightsAssessments{} 146 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 147 return nil, err 148 } 149 150 return ps, err 151 } 152 153 // Optional parameters for the method 'ListInsightsAssessments' 154 type ListInsightsAssessmentsParams struct { 155 // The Authorization HTTP request header 156 Authorization *string `json:"Authorization,omitempty"` 157 // The id of the segment. 158 SegmentId *string `json:"SegmentId,omitempty"` 159 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 160 PageSize *int `json:"PageSize,omitempty"` 161 // Max number of records to return. 162 Limit *int `json:"limit,omitempty"` 163 } 164 165 func (params *ListInsightsAssessmentsParams) SetAuthorization(Authorization string) *ListInsightsAssessmentsParams { 166 params.Authorization = &Authorization 167 return params 168 } 169 func (params *ListInsightsAssessmentsParams) SetSegmentId(SegmentId string) *ListInsightsAssessmentsParams { 170 params.SegmentId = &SegmentId 171 return params 172 } 173 func (params *ListInsightsAssessmentsParams) SetPageSize(PageSize int) *ListInsightsAssessmentsParams { 174 params.PageSize = &PageSize 175 return params 176 } 177 func (params *ListInsightsAssessmentsParams) SetLimit(Limit int) *ListInsightsAssessmentsParams { 178 params.Limit = &Limit 179 return params 180 } 181 182 // Retrieve a single page of InsightsAssessments records from the API. Request is executed immediately. 183 func (c *ApiService) PageInsightsAssessments(params *ListInsightsAssessmentsParams, pageToken, pageNumber string) (*ListInsightsAssessmentsResponse, error) { 184 path := "/v1/Insights/QualityManagement/Assessments" 185 186 data := url.Values{} 187 headers := make(map[string]interface{}) 188 189 if params != nil && params.SegmentId != nil { 190 data.Set("SegmentId", *params.SegmentId) 191 } 192 if params != nil && params.PageSize != nil { 193 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 194 } 195 196 if pageToken != "" { 197 data.Set("PageToken", pageToken) 198 } 199 if pageNumber != "" { 200 data.Set("Page", pageNumber) 201 } 202 203 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 204 if err != nil { 205 return nil, err 206 } 207 208 defer resp.Body.Close() 209 210 ps := &ListInsightsAssessmentsResponse{} 211 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 212 return nil, err 213 } 214 215 return ps, err 216 } 217 218 // Lists InsightsAssessments records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 219 func (c *ApiService) ListInsightsAssessments(params *ListInsightsAssessmentsParams) ([]FlexV1InsightsAssessments, error) { 220 response, errors := c.StreamInsightsAssessments(params) 221 222 records := make([]FlexV1InsightsAssessments, 0) 223 for record := range response { 224 records = append(records, record) 225 } 226 227 if err := <-errors; err != nil { 228 return nil, err 229 } 230 231 return records, nil 232 } 233 234 // Streams InsightsAssessments records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 235 func (c *ApiService) StreamInsightsAssessments(params *ListInsightsAssessmentsParams) (chan FlexV1InsightsAssessments, chan error) { 236 if params == nil { 237 params = &ListInsightsAssessmentsParams{} 238 } 239 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 240 241 recordChannel := make(chan FlexV1InsightsAssessments, 1) 242 errorChannel := make(chan error, 1) 243 244 response, err := c.PageInsightsAssessments(params, "", "") 245 if err != nil { 246 errorChannel <- err 247 close(recordChannel) 248 close(errorChannel) 249 } else { 250 go c.streamInsightsAssessments(response, params, recordChannel, errorChannel) 251 } 252 253 return recordChannel, errorChannel 254 } 255 256 func (c *ApiService) streamInsightsAssessments(response *ListInsightsAssessmentsResponse, params *ListInsightsAssessmentsParams, recordChannel chan FlexV1InsightsAssessments, errorChannel chan error) { 257 curRecord := 1 258 259 for response != nil { 260 responseRecords := response.Assessments 261 for item := range responseRecords { 262 recordChannel <- responseRecords[item] 263 curRecord += 1 264 if params.Limit != nil && *params.Limit < curRecord { 265 close(recordChannel) 266 close(errorChannel) 267 return 268 } 269 } 270 271 record, err := client.GetNext(c.baseURL, response, c.getNextListInsightsAssessmentsResponse) 272 if err != nil { 273 errorChannel <- err 274 break 275 } else if record == nil { 276 break 277 } 278 279 response = record.(*ListInsightsAssessmentsResponse) 280 } 281 282 close(recordChannel) 283 close(errorChannel) 284 } 285 286 func (c *ApiService) getNextListInsightsAssessmentsResponse(nextPageUrl string) (interface{}, error) { 287 if nextPageUrl == "" { 288 return nil, nil 289 } 290 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 291 if err != nil { 292 return nil, err 293 } 294 295 defer resp.Body.Close() 296 297 ps := &ListInsightsAssessmentsResponse{} 298 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 299 return nil, err 300 } 301 return ps, nil 302 } 303 304 // Optional parameters for the method 'UpdateInsightsAssessments' 305 type UpdateInsightsAssessmentsParams struct { 306 // The Authorization HTTP request header 307 Authorization *string `json:"Authorization,omitempty"` 308 // The offset of the conversation 309 Offset *float32 `json:"Offset,omitempty"` 310 // The answer text selected by user 311 AnswerText *string `json:"AnswerText,omitempty"` 312 // The id of the answer selected by user 313 AnswerId *string `json:"AnswerId,omitempty"` 314 } 315 316 func (params *UpdateInsightsAssessmentsParams) SetAuthorization(Authorization string) *UpdateInsightsAssessmentsParams { 317 params.Authorization = &Authorization 318 return params 319 } 320 func (params *UpdateInsightsAssessmentsParams) SetOffset(Offset float32) *UpdateInsightsAssessmentsParams { 321 params.Offset = &Offset 322 return params 323 } 324 func (params *UpdateInsightsAssessmentsParams) SetAnswerText(AnswerText string) *UpdateInsightsAssessmentsParams { 325 params.AnswerText = &AnswerText 326 return params 327 } 328 func (params *UpdateInsightsAssessmentsParams) SetAnswerId(AnswerId string) *UpdateInsightsAssessmentsParams { 329 params.AnswerId = &AnswerId 330 return params 331 } 332 333 // Update a specific Assessment assessed earlier 334 func (c *ApiService) UpdateInsightsAssessments(AssessmentSid string, params *UpdateInsightsAssessmentsParams) (*FlexV1InsightsAssessments, error) { 335 path := "/v1/Insights/QualityManagement/Assessments/{AssessmentSid}" 336 path = strings.Replace(path, "{"+"AssessmentSid"+"}", AssessmentSid, -1) 337 338 data := url.Values{} 339 headers := make(map[string]interface{}) 340 341 if params != nil && params.Offset != nil { 342 data.Set("Offset", fmt.Sprint(*params.Offset)) 343 } 344 if params != nil && params.AnswerText != nil { 345 data.Set("AnswerText", *params.AnswerText) 346 } 347 if params != nil && params.AnswerId != nil { 348 data.Set("AnswerId", *params.AnswerId) 349 } 350 351 if params != nil && params.Authorization != nil { 352 headers["Authorization"] = *params.Authorization 353 } 354 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 355 if err != nil { 356 return nil, err 357 } 358 359 defer resp.Body.Close() 360 361 ps := &FlexV1InsightsAssessments{} 362 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 363 return nil, err 364 } 365 366 return ps, err 367 }