github.com/twilio/twilio-go@v1.20.1/rest/conversations/v1/configuration_webhooks.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Conversations
     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  )
    21  
    22  //
    23  func (c *ApiService) FetchConfigurationWebhook() (*ConversationsV1ConfigurationWebhook, error) {
    24  	path := "/v1/Configuration/Webhooks"
    25  
    26  	data := url.Values{}
    27  	headers := make(map[string]interface{})
    28  
    29  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	defer resp.Body.Close()
    35  
    36  	ps := &ConversationsV1ConfigurationWebhook{}
    37  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	return ps, err
    42  }
    43  
    44  // Optional parameters for the method 'UpdateConfigurationWebhook'
    45  type UpdateConfigurationWebhookParams struct {
    46  	// The HTTP method to be used when sending a webhook request.
    47  	Method *string `json:"Method,omitempty"`
    48  	// The list of webhook event triggers that are enabled for this Service: `onMessageAdded`, `onMessageUpdated`, `onMessageRemoved`, `onConversationUpdated`, `onConversationRemoved`, `onParticipantAdded`, `onParticipantUpdated`, `onParticipantRemoved`
    49  	Filters *[]string `json:"Filters,omitempty"`
    50  	// The absolute url the pre-event webhook request should be sent to.
    51  	PreWebhookUrl *string `json:"PreWebhookUrl,omitempty"`
    52  	// The absolute url the post-event webhook request should be sent to.
    53  	PostWebhookUrl *string `json:"PostWebhookUrl,omitempty"`
    54  	//
    55  	Target *string `json:"Target,omitempty"`
    56  }
    57  
    58  func (params *UpdateConfigurationWebhookParams) SetMethod(Method string) *UpdateConfigurationWebhookParams {
    59  	params.Method = &Method
    60  	return params
    61  }
    62  func (params *UpdateConfigurationWebhookParams) SetFilters(Filters []string) *UpdateConfigurationWebhookParams {
    63  	params.Filters = &Filters
    64  	return params
    65  }
    66  func (params *UpdateConfigurationWebhookParams) SetPreWebhookUrl(PreWebhookUrl string) *UpdateConfigurationWebhookParams {
    67  	params.PreWebhookUrl = &PreWebhookUrl
    68  	return params
    69  }
    70  func (params *UpdateConfigurationWebhookParams) SetPostWebhookUrl(PostWebhookUrl string) *UpdateConfigurationWebhookParams {
    71  	params.PostWebhookUrl = &PostWebhookUrl
    72  	return params
    73  }
    74  func (params *UpdateConfigurationWebhookParams) SetTarget(Target string) *UpdateConfigurationWebhookParams {
    75  	params.Target = &Target
    76  	return params
    77  }
    78  
    79  //
    80  func (c *ApiService) UpdateConfigurationWebhook(params *UpdateConfigurationWebhookParams) (*ConversationsV1ConfigurationWebhook, error) {
    81  	path := "/v1/Configuration/Webhooks"
    82  
    83  	data := url.Values{}
    84  	headers := make(map[string]interface{})
    85  
    86  	if params != nil && params.Method != nil {
    87  		data.Set("Method", *params.Method)
    88  	}
    89  	if params != nil && params.Filters != nil {
    90  		for _, item := range *params.Filters {
    91  			data.Add("Filters", item)
    92  		}
    93  	}
    94  	if params != nil && params.PreWebhookUrl != nil {
    95  		data.Set("PreWebhookUrl", *params.PreWebhookUrl)
    96  	}
    97  	if params != nil && params.PostWebhookUrl != nil {
    98  		data.Set("PostWebhookUrl", *params.PostWebhookUrl)
    99  	}
   100  	if params != nil && params.Target != nil {
   101  		data.Set("Target", *params.Target)
   102  	}
   103  
   104  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   105  	if err != nil {
   106  		return nil, err
   107  	}
   108  
   109  	defer resp.Body.Close()
   110  
   111  	ps := &ConversationsV1ConfigurationWebhook{}
   112  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   113  		return nil, err
   114  	}
   115  
   116  	return ps, err
   117  }