github.com/twilio/twilio-go@v1.20.1/rest/verify/v2/services_verifications.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Verify
     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  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // Optional parameters for the method 'CreateVerification'
    24  type CreateVerificationParams struct {
    25  	// The phone number or [email](https://www.twilio.com/docs/verify/email) to verify. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164).
    26  	To *string `json:"To,omitempty"`
    27  	// The verification method to use. One of: [`email`](https://www.twilio.com/docs/verify/email), `sms`, `whatsapp`, `call`, `sna` or `auto`.
    28  	Channel *string `json:"Channel,omitempty"`
    29  	// A custom user defined friendly name that overwrites the existing one in the verification message
    30  	CustomFriendlyName *string `json:"CustomFriendlyName,omitempty"`
    31  	// The text of a custom message to use for the verification.
    32  	CustomMessage *string `json:"CustomMessage,omitempty"`
    33  	// The digits to send after a phone call is answered, for example, to dial an extension. For more information, see the Programmable Voice documentation of [sendDigits](https://www.twilio.com/docs/voice/twiml/number#attributes-sendDigits).
    34  	SendDigits *string `json:"SendDigits,omitempty"`
    35  	// Locale will automatically resolve based on phone number country code for SMS, WhatsApp, and call channel verifications. It will fallback to English or the template’s default translation if the selected translation is not available. This parameter will override the automatic locale resolution. [See supported languages and more information here](https://www.twilio.com/docs/verify/supported-languages).
    36  	Locale *string `json:"Locale,omitempty"`
    37  	// A pre-generated code to use for verification. The code can be between 4 and 10 characters, inclusive.
    38  	CustomCode *string `json:"CustomCode,omitempty"`
    39  	// The amount of the associated PSD2 compliant transaction. Requires the PSD2 Service flag enabled.
    40  	Amount *string `json:"Amount,omitempty"`
    41  	// The payee of the associated PSD2 compliant transaction. Requires the PSD2 Service flag enabled.
    42  	Payee *string `json:"Payee,omitempty"`
    43  	// The custom key-value pairs of Programmable Rate Limits. Keys correspond to `unique_name` fields defined when [creating your Rate Limit](https://www.twilio.com/docs/verify/api/service-rate-limits). Associated value pairs represent values in the request that you are rate limiting on. You may include multiple Rate Limit values in each request.
    44  	RateLimits *interface{} `json:"RateLimits,omitempty"`
    45  	// [`email`](https://www.twilio.com/docs/verify/email) channel configuration in json format. The fields 'from' and 'from_name' are optional but if included the 'from' field must have a valid email address.
    46  	ChannelConfiguration *interface{} `json:"ChannelConfiguration,omitempty"`
    47  	// Your [App Hash](https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string) to be appended at the end of your verification SMS body. Applies only to SMS. Example SMS body: `<#> Your AppName verification code is: 1234 He42w354ol9`.
    48  	AppHash *string `json:"AppHash,omitempty"`
    49  	// The message [template](https://www.twilio.com/docs/verify/api/templates). If provided, will override the default template for the Service. SMS and Voice channels only.
    50  	TemplateSid *string `json:"TemplateSid,omitempty"`
    51  	// A stringified JSON object in which the keys are the template's special variables and the values are the variables substitutions.
    52  	TemplateCustomSubstitutions *string `json:"TemplateCustomSubstitutions,omitempty"`
    53  	// Strongly encouraged if using the auto channel. The IP address of the client's device. If provided, it has to be a valid IPv4 or IPv6 address.
    54  	DeviceIp *string `json:"DeviceIp,omitempty"`
    55  	//
    56  	RiskCheck *string `json:"RiskCheck,omitempty"`
    57  	// A string containing a JSON map of key value pairs of tags to be recorded as metadata for the message. The object may contain up to 10 tags. Keys and values can each be up to 128 characters in length.
    58  	Tags *string `json:"Tags,omitempty"`
    59  }
    60  
    61  func (params *CreateVerificationParams) SetTo(To string) *CreateVerificationParams {
    62  	params.To = &To
    63  	return params
    64  }
    65  func (params *CreateVerificationParams) SetChannel(Channel string) *CreateVerificationParams {
    66  	params.Channel = &Channel
    67  	return params
    68  }
    69  func (params *CreateVerificationParams) SetCustomFriendlyName(CustomFriendlyName string) *CreateVerificationParams {
    70  	params.CustomFriendlyName = &CustomFriendlyName
    71  	return params
    72  }
    73  func (params *CreateVerificationParams) SetCustomMessage(CustomMessage string) *CreateVerificationParams {
    74  	params.CustomMessage = &CustomMessage
    75  	return params
    76  }
    77  func (params *CreateVerificationParams) SetSendDigits(SendDigits string) *CreateVerificationParams {
    78  	params.SendDigits = &SendDigits
    79  	return params
    80  }
    81  func (params *CreateVerificationParams) SetLocale(Locale string) *CreateVerificationParams {
    82  	params.Locale = &Locale
    83  	return params
    84  }
    85  func (params *CreateVerificationParams) SetCustomCode(CustomCode string) *CreateVerificationParams {
    86  	params.CustomCode = &CustomCode
    87  	return params
    88  }
    89  func (params *CreateVerificationParams) SetAmount(Amount string) *CreateVerificationParams {
    90  	params.Amount = &Amount
    91  	return params
    92  }
    93  func (params *CreateVerificationParams) SetPayee(Payee string) *CreateVerificationParams {
    94  	params.Payee = &Payee
    95  	return params
    96  }
    97  func (params *CreateVerificationParams) SetRateLimits(RateLimits interface{}) *CreateVerificationParams {
    98  	params.RateLimits = &RateLimits
    99  	return params
   100  }
   101  func (params *CreateVerificationParams) SetChannelConfiguration(ChannelConfiguration interface{}) *CreateVerificationParams {
   102  	params.ChannelConfiguration = &ChannelConfiguration
   103  	return params
   104  }
   105  func (params *CreateVerificationParams) SetAppHash(AppHash string) *CreateVerificationParams {
   106  	params.AppHash = &AppHash
   107  	return params
   108  }
   109  func (params *CreateVerificationParams) SetTemplateSid(TemplateSid string) *CreateVerificationParams {
   110  	params.TemplateSid = &TemplateSid
   111  	return params
   112  }
   113  func (params *CreateVerificationParams) SetTemplateCustomSubstitutions(TemplateCustomSubstitutions string) *CreateVerificationParams {
   114  	params.TemplateCustomSubstitutions = &TemplateCustomSubstitutions
   115  	return params
   116  }
   117  func (params *CreateVerificationParams) SetDeviceIp(DeviceIp string) *CreateVerificationParams {
   118  	params.DeviceIp = &DeviceIp
   119  	return params
   120  }
   121  func (params *CreateVerificationParams) SetRiskCheck(RiskCheck string) *CreateVerificationParams {
   122  	params.RiskCheck = &RiskCheck
   123  	return params
   124  }
   125  func (params *CreateVerificationParams) SetTags(Tags string) *CreateVerificationParams {
   126  	params.Tags = &Tags
   127  	return params
   128  }
   129  
   130  // Create a new Verification using a Service
   131  func (c *ApiService) CreateVerification(ServiceSid string, params *CreateVerificationParams) (*VerifyV2Verification, error) {
   132  	path := "/v2/Services/{ServiceSid}/Verifications"
   133  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
   134  
   135  	data := url.Values{}
   136  	headers := make(map[string]interface{})
   137  
   138  	if params != nil && params.To != nil {
   139  		data.Set("To", *params.To)
   140  	}
   141  	if params != nil && params.Channel != nil {
   142  		data.Set("Channel", *params.Channel)
   143  	}
   144  	if params != nil && params.CustomFriendlyName != nil {
   145  		data.Set("CustomFriendlyName", *params.CustomFriendlyName)
   146  	}
   147  	if params != nil && params.CustomMessage != nil {
   148  		data.Set("CustomMessage", *params.CustomMessage)
   149  	}
   150  	if params != nil && params.SendDigits != nil {
   151  		data.Set("SendDigits", *params.SendDigits)
   152  	}
   153  	if params != nil && params.Locale != nil {
   154  		data.Set("Locale", *params.Locale)
   155  	}
   156  	if params != nil && params.CustomCode != nil {
   157  		data.Set("CustomCode", *params.CustomCode)
   158  	}
   159  	if params != nil && params.Amount != nil {
   160  		data.Set("Amount", *params.Amount)
   161  	}
   162  	if params != nil && params.Payee != nil {
   163  		data.Set("Payee", *params.Payee)
   164  	}
   165  	if params != nil && params.RateLimits != nil {
   166  		v, err := json.Marshal(params.RateLimits)
   167  
   168  		if err != nil {
   169  			return nil, err
   170  		}
   171  
   172  		data.Set("RateLimits", string(v))
   173  	}
   174  	if params != nil && params.ChannelConfiguration != nil {
   175  		v, err := json.Marshal(params.ChannelConfiguration)
   176  
   177  		if err != nil {
   178  			return nil, err
   179  		}
   180  
   181  		data.Set("ChannelConfiguration", string(v))
   182  	}
   183  	if params != nil && params.AppHash != nil {
   184  		data.Set("AppHash", *params.AppHash)
   185  	}
   186  	if params != nil && params.TemplateSid != nil {
   187  		data.Set("TemplateSid", *params.TemplateSid)
   188  	}
   189  	if params != nil && params.TemplateCustomSubstitutions != nil {
   190  		data.Set("TemplateCustomSubstitutions", *params.TemplateCustomSubstitutions)
   191  	}
   192  	if params != nil && params.DeviceIp != nil {
   193  		data.Set("DeviceIp", *params.DeviceIp)
   194  	}
   195  	if params != nil && params.RiskCheck != nil {
   196  		data.Set("RiskCheck", *params.RiskCheck)
   197  	}
   198  	if params != nil && params.Tags != nil {
   199  		data.Set("Tags", *params.Tags)
   200  	}
   201  
   202  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   203  	if err != nil {
   204  		return nil, err
   205  	}
   206  
   207  	defer resp.Body.Close()
   208  
   209  	ps := &VerifyV2Verification{}
   210  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   211  		return nil, err
   212  	}
   213  
   214  	return ps, err
   215  }
   216  
   217  // Fetch a specific Verification
   218  func (c *ApiService) FetchVerification(ServiceSid string, Sid string) (*VerifyV2Verification, error) {
   219  	path := "/v2/Services/{ServiceSid}/Verifications/{Sid}"
   220  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
   221  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   222  
   223  	data := url.Values{}
   224  	headers := make(map[string]interface{})
   225  
   226  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   227  	if err != nil {
   228  		return nil, err
   229  	}
   230  
   231  	defer resp.Body.Close()
   232  
   233  	ps := &VerifyV2Verification{}
   234  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   235  		return nil, err
   236  	}
   237  
   238  	return ps, err
   239  }
   240  
   241  // Optional parameters for the method 'UpdateVerification'
   242  type UpdateVerificationParams struct {
   243  	//
   244  	Status *string `json:"Status,omitempty"`
   245  }
   246  
   247  func (params *UpdateVerificationParams) SetStatus(Status string) *UpdateVerificationParams {
   248  	params.Status = &Status
   249  	return params
   250  }
   251  
   252  // Update a Verification status
   253  func (c *ApiService) UpdateVerification(ServiceSid string, Sid string, params *UpdateVerificationParams) (*VerifyV2Verification, error) {
   254  	path := "/v2/Services/{ServiceSid}/Verifications/{Sid}"
   255  	path = strings.Replace(path, "{"+"ServiceSid"+"}", ServiceSid, -1)
   256  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   257  
   258  	data := url.Values{}
   259  	headers := make(map[string]interface{})
   260  
   261  	if params != nil && params.Status != nil {
   262  		data.Set("Status", *params.Status)
   263  	}
   264  
   265  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   266  	if err != nil {
   267  		return nil, err
   268  	}
   269  
   270  	defer resp.Body.Close()
   271  
   272  	ps := &VerifyV2Verification{}
   273  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   274  		return nil, err
   275  	}
   276  
   277  	return ps, err
   278  }