github.com/twilio/twilio-go@v1.20.1/rest/messaging/v1/services_compliance_usa2p.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Messaging 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 'CreateUsAppToPerson' 27 type CreateUsAppToPersonParams struct { 28 // A2P Brand Registration SID 29 BrandRegistrationSid *string `json:"BrandRegistrationSid,omitempty"` 30 // A short description of what this SMS campaign does. Min length: 40 characters. Max length: 4096 characters. 31 Description *string `json:"Description,omitempty"` 32 // Required for all Campaigns. Details around how a consumer opts-in to their campaign, therefore giving consent to receive their messages. If multiple opt-in methods can be used for the same campaign, they must all be listed. 40 character minimum. 2048 character maximum. 33 MessageFlow *string `json:"MessageFlow,omitempty"` 34 // An array of sample message strings, min two and max five. Min length for each sample: 20 chars. Max length for each sample: 1024 chars. 35 MessageSamples *[]string `json:"MessageSamples,omitempty"` 36 // A2P Campaign Use Case. Examples: [ 2FA, EMERGENCY, MARKETING..] 37 UsAppToPersonUsecase *string `json:"UsAppToPersonUsecase,omitempty"` 38 // Indicates that this SMS campaign will send messages that contain links. 39 HasEmbeddedLinks *bool `json:"HasEmbeddedLinks,omitempty"` 40 // Indicates that this SMS campaign will send messages that contain phone numbers. 41 HasEmbeddedPhone *bool `json:"HasEmbeddedPhone,omitempty"` 42 // If end users can text in a keyword to start receiving messages from this campaign, the auto-reply messages sent to the end users must be provided. The opt-in response should include the Brand name, confirmation of opt-in enrollment to a recurring message campaign, how to get help, and clear description of how to opt-out. This field is required if end users can text in a keyword to start receiving messages from this campaign. 20 character minimum. 320 character maximum. 43 OptInMessage *string `json:"OptInMessage,omitempty"` 44 // Upon receiving the opt-out keywords from the end users, Twilio customers are expected to send back an auto-generated response, which must provide acknowledgment of the opt-out request and confirmation that no further messages will be sent. It is also recommended that these opt-out messages include the brand name. This field is required if managing opt out keywords yourself (i.e. not using Twilio's Default or Advanced Opt Out features). 20 character minimum. 320 character maximum. 45 OptOutMessage *string `json:"OptOutMessage,omitempty"` 46 // When customers receive the help keywords from their end users, Twilio customers are expected to send back an auto-generated response; this may include the brand name and additional support contact information. This field is required if managing help keywords yourself (i.e. not using Twilio's Default or Advanced Opt Out features). 20 character minimum. 320 character maximum. 47 HelpMessage *string `json:"HelpMessage,omitempty"` 48 // If end users can text in a keyword to start receiving messages from this campaign, those keywords must be provided. This field is required if end users can text in a keyword to start receiving messages from this campaign. Values must be alphanumeric. 255 character maximum. 49 OptInKeywords *[]string `json:"OptInKeywords,omitempty"` 50 // End users should be able to text in a keyword to stop receiving messages from this campaign. Those keywords must be provided. This field is required if managing opt out keywords yourself (i.e. not using Twilio's Default or Advanced Opt Out features). Values must be alphanumeric. 255 character maximum. 51 OptOutKeywords *[]string `json:"OptOutKeywords,omitempty"` 52 // End users should be able to text in a keyword to receive help. Those keywords must be provided as part of the campaign registration request. This field is required if managing help keywords yourself (i.e. not using Twilio's Default or Advanced Opt Out features). Values must be alphanumeric. 255 character maximum. 53 HelpKeywords *[]string `json:"HelpKeywords,omitempty"` 54 // A boolean that specifies whether campaign has Subscriber Optin or not. 55 SubscriberOptIn *bool `json:"SubscriberOptIn,omitempty"` 56 // A boolean that specifies whether campaign is age gated or not. 57 AgeGated *bool `json:"AgeGated,omitempty"` 58 // A boolean that specifies whether campaign allows direct lending or not. 59 DirectLending *bool `json:"DirectLending,omitempty"` 60 } 61 62 func (params *CreateUsAppToPersonParams) SetBrandRegistrationSid(BrandRegistrationSid string) *CreateUsAppToPersonParams { 63 params.BrandRegistrationSid = &BrandRegistrationSid 64 return params 65 } 66 func (params *CreateUsAppToPersonParams) SetDescription(Description string) *CreateUsAppToPersonParams { 67 params.Description = &Description 68 return params 69 } 70 func (params *CreateUsAppToPersonParams) SetMessageFlow(MessageFlow string) *CreateUsAppToPersonParams { 71 params.MessageFlow = &MessageFlow 72 return params 73 } 74 func (params *CreateUsAppToPersonParams) SetMessageSamples(MessageSamples []string) *CreateUsAppToPersonParams { 75 params.MessageSamples = &MessageSamples 76 return params 77 } 78 func (params *CreateUsAppToPersonParams) SetUsAppToPersonUsecase(UsAppToPersonUsecase string) *CreateUsAppToPersonParams { 79 params.UsAppToPersonUsecase = &UsAppToPersonUsecase 80 return params 81 } 82 func (params *CreateUsAppToPersonParams) SetHasEmbeddedLinks(HasEmbeddedLinks bool) *CreateUsAppToPersonParams { 83 params.HasEmbeddedLinks = &HasEmbeddedLinks 84 return params 85 } 86 func (params *CreateUsAppToPersonParams) SetHasEmbeddedPhone(HasEmbeddedPhone bool) *CreateUsAppToPersonParams { 87 params.HasEmbeddedPhone = &HasEmbeddedPhone 88 return params 89 } 90 func (params *CreateUsAppToPersonParams) SetOptInMessage(OptInMessage string) *CreateUsAppToPersonParams { 91 params.OptInMessage = &OptInMessage 92 return params 93 } 94 func (params *CreateUsAppToPersonParams) SetOptOutMessage(OptOutMessage string) *CreateUsAppToPersonParams { 95 params.OptOutMessage = &OptOutMessage 96 return params 97 } 98 func (params *CreateUsAppToPersonParams) SetHelpMessage(HelpMessage string) *CreateUsAppToPersonParams { 99 params.HelpMessage = &HelpMessage 100 return params 101 } 102 func (params *CreateUsAppToPersonParams) SetOptInKeywords(OptInKeywords []string) *CreateUsAppToPersonParams { 103 params.OptInKeywords = &OptInKeywords 104 return params 105 } 106 func (params *CreateUsAppToPersonParams) SetOptOutKeywords(OptOutKeywords []string) *CreateUsAppToPersonParams { 107 params.OptOutKeywords = &OptOutKeywords 108 return params 109 } 110 func (params *CreateUsAppToPersonParams) SetHelpKeywords(HelpKeywords []string) *CreateUsAppToPersonParams { 111 params.HelpKeywords = &HelpKeywords 112 return params 113 } 114 func (params *CreateUsAppToPersonParams) SetSubscriberOptIn(SubscriberOptIn bool) *CreateUsAppToPersonParams { 115 params.SubscriberOptIn = &SubscriberOptIn 116 return params 117 } 118 func (params *CreateUsAppToPersonParams) SetAgeGated(AgeGated bool) *CreateUsAppToPersonParams { 119 params.AgeGated = &AgeGated 120 return params 121 } 122 func (params *CreateUsAppToPersonParams) SetDirectLending(DirectLending bool) *CreateUsAppToPersonParams { 123 params.DirectLending = &DirectLending 124 return params 125 } 126 127 // 128 func (c *ApiService) CreateUsAppToPerson(MessagingServiceSid string, params *CreateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { 129 path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p" 130 path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) 131 132 data := url.Values{} 133 headers := make(map[string]interface{}) 134 135 if params != nil && params.BrandRegistrationSid != nil { 136 data.Set("BrandRegistrationSid", *params.BrandRegistrationSid) 137 } 138 if params != nil && params.Description != nil { 139 data.Set("Description", *params.Description) 140 } 141 if params != nil && params.MessageFlow != nil { 142 data.Set("MessageFlow", *params.MessageFlow) 143 } 144 if params != nil && params.MessageSamples != nil { 145 for _, item := range *params.MessageSamples { 146 data.Add("MessageSamples", item) 147 } 148 } 149 if params != nil && params.UsAppToPersonUsecase != nil { 150 data.Set("UsAppToPersonUsecase", *params.UsAppToPersonUsecase) 151 } 152 if params != nil && params.HasEmbeddedLinks != nil { 153 data.Set("HasEmbeddedLinks", fmt.Sprint(*params.HasEmbeddedLinks)) 154 } 155 if params != nil && params.HasEmbeddedPhone != nil { 156 data.Set("HasEmbeddedPhone", fmt.Sprint(*params.HasEmbeddedPhone)) 157 } 158 if params != nil && params.OptInMessage != nil { 159 data.Set("OptInMessage", *params.OptInMessage) 160 } 161 if params != nil && params.OptOutMessage != nil { 162 data.Set("OptOutMessage", *params.OptOutMessage) 163 } 164 if params != nil && params.HelpMessage != nil { 165 data.Set("HelpMessage", *params.HelpMessage) 166 } 167 if params != nil && params.OptInKeywords != nil { 168 for _, item := range *params.OptInKeywords { 169 data.Add("OptInKeywords", item) 170 } 171 } 172 if params != nil && params.OptOutKeywords != nil { 173 for _, item := range *params.OptOutKeywords { 174 data.Add("OptOutKeywords", item) 175 } 176 } 177 if params != nil && params.HelpKeywords != nil { 178 for _, item := range *params.HelpKeywords { 179 data.Add("HelpKeywords", item) 180 } 181 } 182 if params != nil && params.SubscriberOptIn != nil { 183 data.Set("SubscriberOptIn", fmt.Sprint(*params.SubscriberOptIn)) 184 } 185 if params != nil && params.AgeGated != nil { 186 data.Set("AgeGated", fmt.Sprint(*params.AgeGated)) 187 } 188 if params != nil && params.DirectLending != nil { 189 data.Set("DirectLending", fmt.Sprint(*params.DirectLending)) 190 } 191 192 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 193 if err != nil { 194 return nil, err 195 } 196 197 defer resp.Body.Close() 198 199 ps := &MessagingV1UsAppToPerson{} 200 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 201 return nil, err 202 } 203 204 return ps, err 205 } 206 207 // 208 func (c *ApiService) DeleteUsAppToPerson(MessagingServiceSid string, Sid string) error { 209 path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" 210 path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) 211 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 212 213 data := url.Values{} 214 headers := make(map[string]interface{}) 215 216 resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers) 217 if err != nil { 218 return err 219 } 220 221 defer resp.Body.Close() 222 223 return nil 224 } 225 226 // 227 func (c *ApiService) FetchUsAppToPerson(MessagingServiceSid string, Sid string) (*MessagingV1UsAppToPerson, error) { 228 path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" 229 path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) 230 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 231 232 data := url.Values{} 233 headers := make(map[string]interface{}) 234 235 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 236 if err != nil { 237 return nil, err 238 } 239 240 defer resp.Body.Close() 241 242 ps := &MessagingV1UsAppToPerson{} 243 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 244 return nil, err 245 } 246 247 return ps, err 248 } 249 250 // Optional parameters for the method 'ListUsAppToPerson' 251 type ListUsAppToPersonParams struct { 252 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 253 PageSize *int `json:"PageSize,omitempty"` 254 // Max number of records to return. 255 Limit *int `json:"limit,omitempty"` 256 } 257 258 func (params *ListUsAppToPersonParams) SetPageSize(PageSize int) *ListUsAppToPersonParams { 259 params.PageSize = &PageSize 260 return params 261 } 262 func (params *ListUsAppToPersonParams) SetLimit(Limit int) *ListUsAppToPersonParams { 263 params.Limit = &Limit 264 return params 265 } 266 267 // Retrieve a single page of UsAppToPerson records from the API. Request is executed immediately. 268 func (c *ApiService) PageUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams, pageToken, pageNumber string) (*ListUsAppToPersonResponse, error) { 269 path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p" 270 271 path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) 272 273 data := url.Values{} 274 headers := make(map[string]interface{}) 275 276 if params != nil && params.PageSize != nil { 277 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 278 } 279 280 if pageToken != "" { 281 data.Set("PageToken", pageToken) 282 } 283 if pageNumber != "" { 284 data.Set("Page", pageNumber) 285 } 286 287 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 288 if err != nil { 289 return nil, err 290 } 291 292 defer resp.Body.Close() 293 294 ps := &ListUsAppToPersonResponse{} 295 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 296 return nil, err 297 } 298 299 return ps, err 300 } 301 302 // Lists UsAppToPerson records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 303 func (c *ApiService) ListUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams) ([]MessagingV1UsAppToPerson, error) { 304 response, errors := c.StreamUsAppToPerson(MessagingServiceSid, params) 305 306 records := make([]MessagingV1UsAppToPerson, 0) 307 for record := range response { 308 records = append(records, record) 309 } 310 311 if err := <-errors; err != nil { 312 return nil, err 313 } 314 315 return records, nil 316 } 317 318 // Streams UsAppToPerson records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 319 func (c *ApiService) StreamUsAppToPerson(MessagingServiceSid string, params *ListUsAppToPersonParams) (chan MessagingV1UsAppToPerson, chan error) { 320 if params == nil { 321 params = &ListUsAppToPersonParams{} 322 } 323 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 324 325 recordChannel := make(chan MessagingV1UsAppToPerson, 1) 326 errorChannel := make(chan error, 1) 327 328 response, err := c.PageUsAppToPerson(MessagingServiceSid, params, "", "") 329 if err != nil { 330 errorChannel <- err 331 close(recordChannel) 332 close(errorChannel) 333 } else { 334 go c.streamUsAppToPerson(response, params, recordChannel, errorChannel) 335 } 336 337 return recordChannel, errorChannel 338 } 339 340 func (c *ApiService) streamUsAppToPerson(response *ListUsAppToPersonResponse, params *ListUsAppToPersonParams, recordChannel chan MessagingV1UsAppToPerson, errorChannel chan error) { 341 curRecord := 1 342 343 for response != nil { 344 responseRecords := response.Compliance 345 for item := range responseRecords { 346 recordChannel <- responseRecords[item] 347 curRecord += 1 348 if params.Limit != nil && *params.Limit < curRecord { 349 close(recordChannel) 350 close(errorChannel) 351 return 352 } 353 } 354 355 record, err := client.GetNext(c.baseURL, response, c.getNextListUsAppToPersonResponse) 356 if err != nil { 357 errorChannel <- err 358 break 359 } else if record == nil { 360 break 361 } 362 363 response = record.(*ListUsAppToPersonResponse) 364 } 365 366 close(recordChannel) 367 close(errorChannel) 368 } 369 370 func (c *ApiService) getNextListUsAppToPersonResponse(nextPageUrl string) (interface{}, error) { 371 if nextPageUrl == "" { 372 return nil, nil 373 } 374 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 375 if err != nil { 376 return nil, err 377 } 378 379 defer resp.Body.Close() 380 381 ps := &ListUsAppToPersonResponse{} 382 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 383 return nil, err 384 } 385 return ps, nil 386 } 387 388 // Optional parameters for the method 'UpdateUsAppToPerson' 389 type UpdateUsAppToPersonParams struct { 390 // Indicates that this SMS campaign will send messages that contain links. 391 HasEmbeddedLinks *bool `json:"HasEmbeddedLinks,omitempty"` 392 // Indicates that this SMS campaign will send messages that contain phone numbers. 393 HasEmbeddedPhone *bool `json:"HasEmbeddedPhone,omitempty"` 394 // An array of sample message strings, min two and max five. Min length for each sample: 20 chars. Max length for each sample: 1024 chars. 395 MessageSamples *[]string `json:"MessageSamples,omitempty"` 396 // Required for all Campaigns. Details around how a consumer opts-in to their campaign, therefore giving consent to receive their messages. If multiple opt-in methods can be used for the same campaign, they must all be listed. 40 character minimum. 2048 character maximum. 397 MessageFlow *string `json:"MessageFlow,omitempty"` 398 // A short description of what this SMS campaign does. Min length: 40 characters. Max length: 4096 characters. 399 Description *string `json:"Description,omitempty"` 400 // A boolean that specifies whether campaign requires age gate for federally legal content. 401 AgeGated *bool `json:"AgeGated,omitempty"` 402 // A boolean that specifies whether campaign allows direct lending or not. 403 DirectLending *bool `json:"DirectLending,omitempty"` 404 } 405 406 func (params *UpdateUsAppToPersonParams) SetHasEmbeddedLinks(HasEmbeddedLinks bool) *UpdateUsAppToPersonParams { 407 params.HasEmbeddedLinks = &HasEmbeddedLinks 408 return params 409 } 410 func (params *UpdateUsAppToPersonParams) SetHasEmbeddedPhone(HasEmbeddedPhone bool) *UpdateUsAppToPersonParams { 411 params.HasEmbeddedPhone = &HasEmbeddedPhone 412 return params 413 } 414 func (params *UpdateUsAppToPersonParams) SetMessageSamples(MessageSamples []string) *UpdateUsAppToPersonParams { 415 params.MessageSamples = &MessageSamples 416 return params 417 } 418 func (params *UpdateUsAppToPersonParams) SetMessageFlow(MessageFlow string) *UpdateUsAppToPersonParams { 419 params.MessageFlow = &MessageFlow 420 return params 421 } 422 func (params *UpdateUsAppToPersonParams) SetDescription(Description string) *UpdateUsAppToPersonParams { 423 params.Description = &Description 424 return params 425 } 426 func (params *UpdateUsAppToPersonParams) SetAgeGated(AgeGated bool) *UpdateUsAppToPersonParams { 427 params.AgeGated = &AgeGated 428 return params 429 } 430 func (params *UpdateUsAppToPersonParams) SetDirectLending(DirectLending bool) *UpdateUsAppToPersonParams { 431 params.DirectLending = &DirectLending 432 return params 433 } 434 435 // 436 func (c *ApiService) UpdateUsAppToPerson(MessagingServiceSid string, Sid string, params *UpdateUsAppToPersonParams) (*MessagingV1UsAppToPerson, error) { 437 path := "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}" 438 path = strings.Replace(path, "{"+"MessagingServiceSid"+"}", MessagingServiceSid, -1) 439 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 440 441 data := url.Values{} 442 headers := make(map[string]interface{}) 443 444 if params != nil && params.HasEmbeddedLinks != nil { 445 data.Set("HasEmbeddedLinks", fmt.Sprint(*params.HasEmbeddedLinks)) 446 } 447 if params != nil && params.HasEmbeddedPhone != nil { 448 data.Set("HasEmbeddedPhone", fmt.Sprint(*params.HasEmbeddedPhone)) 449 } 450 if params != nil && params.MessageSamples != nil { 451 for _, item := range *params.MessageSamples { 452 data.Add("MessageSamples", item) 453 } 454 } 455 if params != nil && params.MessageFlow != nil { 456 data.Set("MessageFlow", *params.MessageFlow) 457 } 458 if params != nil && params.Description != nil { 459 data.Set("Description", *params.Description) 460 } 461 if params != nil && params.AgeGated != nil { 462 data.Set("AgeGated", fmt.Sprint(*params.AgeGated)) 463 } 464 if params != nil && params.DirectLending != nil { 465 data.Set("DirectLending", fmt.Sprint(*params.DirectLending)) 466 } 467 468 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 469 if err != nil { 470 return nil, err 471 } 472 473 defer resp.Body.Close() 474 475 ps := &MessagingV1UsAppToPerson{} 476 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 477 return nil, err 478 } 479 480 return ps, err 481 }