github.com/twilio/twilio-go@v1.20.1/rest/conversations/v1/services_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  	"strings"
    21  )
    22  
    23  // Fetch a specific service webhook configuration.
    24  func (c *ApiService) FetchServiceWebhookConfiguration(ChatServiceSid string) (*ConversationsV1ServiceWebhookConfiguration, error) {
    25  	path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"
    26  	path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1)
    27  
    28  	data := url.Values{}
    29  	headers := make(map[string]interface{})
    30  
    31  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	defer resp.Body.Close()
    37  
    38  	ps := &ConversationsV1ServiceWebhookConfiguration{}
    39  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	return ps, err
    44  }
    45  
    46  // Optional parameters for the method 'UpdateServiceWebhookConfiguration'
    47  type UpdateServiceWebhookConfigurationParams struct {
    48  	// The absolute url the pre-event webhook request should be sent to.
    49  	PreWebhookUrl *string `json:"PreWebhookUrl,omitempty"`
    50  	// The absolute url the post-event webhook request should be sent to.
    51  	PostWebhookUrl *string `json:"PostWebhookUrl,omitempty"`
    52  	// The list of events that your configured webhook targets will receive. Events not configured here will not fire. Possible values are `onParticipantAdd`, `onParticipantAdded`, `onDeliveryUpdated`, `onConversationUpdated`, `onConversationRemove`, `onParticipantRemove`, `onConversationUpdate`, `onMessageAdd`, `onMessageRemoved`, `onParticipantUpdated`, `onConversationAdded`, `onMessageAdded`, `onConversationAdd`, `onConversationRemoved`, `onParticipantUpdate`, `onMessageRemove`, `onMessageUpdated`, `onParticipantRemoved`, `onMessageUpdate` or `onConversationStateUpdated`.
    53  	Filters *[]string `json:"Filters,omitempty"`
    54  	// The HTTP method to be used when sending a webhook request. One of `GET` or `POST`.
    55  	Method *string `json:"Method,omitempty"`
    56  }
    57  
    58  func (params *UpdateServiceWebhookConfigurationParams) SetPreWebhookUrl(PreWebhookUrl string) *UpdateServiceWebhookConfigurationParams {
    59  	params.PreWebhookUrl = &PreWebhookUrl
    60  	return params
    61  }
    62  func (params *UpdateServiceWebhookConfigurationParams) SetPostWebhookUrl(PostWebhookUrl string) *UpdateServiceWebhookConfigurationParams {
    63  	params.PostWebhookUrl = &PostWebhookUrl
    64  	return params
    65  }
    66  func (params *UpdateServiceWebhookConfigurationParams) SetFilters(Filters []string) *UpdateServiceWebhookConfigurationParams {
    67  	params.Filters = &Filters
    68  	return params
    69  }
    70  func (params *UpdateServiceWebhookConfigurationParams) SetMethod(Method string) *UpdateServiceWebhookConfigurationParams {
    71  	params.Method = &Method
    72  	return params
    73  }
    74  
    75  // Update a specific Webhook.
    76  func (c *ApiService) UpdateServiceWebhookConfiguration(ChatServiceSid string, params *UpdateServiceWebhookConfigurationParams) (*ConversationsV1ServiceWebhookConfiguration, error) {
    77  	path := "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"
    78  	path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1)
    79  
    80  	data := url.Values{}
    81  	headers := make(map[string]interface{})
    82  
    83  	if params != nil && params.PreWebhookUrl != nil {
    84  		data.Set("PreWebhookUrl", *params.PreWebhookUrl)
    85  	}
    86  	if params != nil && params.PostWebhookUrl != nil {
    87  		data.Set("PostWebhookUrl", *params.PostWebhookUrl)
    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.Method != nil {
    95  		data.Set("Method", *params.Method)
    96  	}
    97  
    98  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    99  	if err != nil {
   100  		return nil, err
   101  	}
   102  
   103  	defer resp.Body.Close()
   104  
   105  	ps := &ConversationsV1ServiceWebhookConfiguration{}
   106  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   107  		return nil, err
   108  	}
   109  
   110  	return ps, err
   111  }