github.com/twilio/twilio-go@v1.20.1/rest/chat/v1/services.go (about)

     1  /*
     2   * This code was generated by
     3   * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
     4   *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
     5   *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
     6   *
     7   * Twilio - Chat
     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 'CreateService'
    27  type CreateServiceParams struct {
    28  	// A descriptive string that you create to describe the resource. It can be up to 64 characters long.
    29  	FriendlyName *string `json:"FriendlyName,omitempty"`
    30  }
    31  
    32  func (params *CreateServiceParams) SetFriendlyName(FriendlyName string) *CreateServiceParams {
    33  	params.FriendlyName = &FriendlyName
    34  	return params
    35  }
    36  
    37  //
    38  func (c *ApiService) CreateService(params *CreateServiceParams) (*ChatV1Service, error) {
    39  	path := "/v1/Services"
    40  
    41  	data := url.Values{}
    42  	headers := make(map[string]interface{})
    43  
    44  	if params != nil && params.FriendlyName != nil {
    45  		data.Set("FriendlyName", *params.FriendlyName)
    46  	}
    47  
    48  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  
    53  	defer resp.Body.Close()
    54  
    55  	ps := &ChatV1Service{}
    56  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	return ps, err
    61  }
    62  
    63  //
    64  func (c *ApiService) DeleteService(Sid string) error {
    65  	path := "/v1/Services/{Sid}"
    66  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
    67  
    68  	data := url.Values{}
    69  	headers := make(map[string]interface{})
    70  
    71  	resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers)
    72  	if err != nil {
    73  		return err
    74  	}
    75  
    76  	defer resp.Body.Close()
    77  
    78  	return nil
    79  }
    80  
    81  //
    82  func (c *ApiService) FetchService(Sid string) (*ChatV1Service, error) {
    83  	path := "/v1/Services/{Sid}"
    84  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
    85  
    86  	data := url.Values{}
    87  	headers := make(map[string]interface{})
    88  
    89  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  
    94  	defer resp.Body.Close()
    95  
    96  	ps := &ChatV1Service{}
    97  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    98  		return nil, err
    99  	}
   100  
   101  	return ps, err
   102  }
   103  
   104  // Optional parameters for the method 'ListService'
   105  type ListServiceParams struct {
   106  	// How many resources to return in each list page. The default is 50, and the maximum is 1000.
   107  	PageSize *int `json:"PageSize,omitempty"`
   108  	// Max number of records to return.
   109  	Limit *int `json:"limit,omitempty"`
   110  }
   111  
   112  func (params *ListServiceParams) SetPageSize(PageSize int) *ListServiceParams {
   113  	params.PageSize = &PageSize
   114  	return params
   115  }
   116  func (params *ListServiceParams) SetLimit(Limit int) *ListServiceParams {
   117  	params.Limit = &Limit
   118  	return params
   119  }
   120  
   121  // Retrieve a single page of Service records from the API. Request is executed immediately.
   122  func (c *ApiService) PageService(params *ListServiceParams, pageToken, pageNumber string) (*ListServiceResponse, error) {
   123  	path := "/v1/Services"
   124  
   125  	data := url.Values{}
   126  	headers := make(map[string]interface{})
   127  
   128  	if params != nil && params.PageSize != nil {
   129  		data.Set("PageSize", fmt.Sprint(*params.PageSize))
   130  	}
   131  
   132  	if pageToken != "" {
   133  		data.Set("PageToken", pageToken)
   134  	}
   135  	if pageNumber != "" {
   136  		data.Set("Page", pageNumber)
   137  	}
   138  
   139  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   140  	if err != nil {
   141  		return nil, err
   142  	}
   143  
   144  	defer resp.Body.Close()
   145  
   146  	ps := &ListServiceResponse{}
   147  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   148  		return nil, err
   149  	}
   150  
   151  	return ps, err
   152  }
   153  
   154  // Lists Service records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
   155  func (c *ApiService) ListService(params *ListServiceParams) ([]ChatV1Service, error) {
   156  	response, errors := c.StreamService(params)
   157  
   158  	records := make([]ChatV1Service, 0)
   159  	for record := range response {
   160  		records = append(records, record)
   161  	}
   162  
   163  	if err := <-errors; err != nil {
   164  		return nil, err
   165  	}
   166  
   167  	return records, nil
   168  }
   169  
   170  // Streams Service records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
   171  func (c *ApiService) StreamService(params *ListServiceParams) (chan ChatV1Service, chan error) {
   172  	if params == nil {
   173  		params = &ListServiceParams{}
   174  	}
   175  	params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
   176  
   177  	recordChannel := make(chan ChatV1Service, 1)
   178  	errorChannel := make(chan error, 1)
   179  
   180  	response, err := c.PageService(params, "", "")
   181  	if err != nil {
   182  		errorChannel <- err
   183  		close(recordChannel)
   184  		close(errorChannel)
   185  	} else {
   186  		go c.streamService(response, params, recordChannel, errorChannel)
   187  	}
   188  
   189  	return recordChannel, errorChannel
   190  }
   191  
   192  func (c *ApiService) streamService(response *ListServiceResponse, params *ListServiceParams, recordChannel chan ChatV1Service, errorChannel chan error) {
   193  	curRecord := 1
   194  
   195  	for response != nil {
   196  		responseRecords := response.Services
   197  		for item := range responseRecords {
   198  			recordChannel <- responseRecords[item]
   199  			curRecord += 1
   200  			if params.Limit != nil && *params.Limit < curRecord {
   201  				close(recordChannel)
   202  				close(errorChannel)
   203  				return
   204  			}
   205  		}
   206  
   207  		record, err := client.GetNext(c.baseURL, response, c.getNextListServiceResponse)
   208  		if err != nil {
   209  			errorChannel <- err
   210  			break
   211  		} else if record == nil {
   212  			break
   213  		}
   214  
   215  		response = record.(*ListServiceResponse)
   216  	}
   217  
   218  	close(recordChannel)
   219  	close(errorChannel)
   220  }
   221  
   222  func (c *ApiService) getNextListServiceResponse(nextPageUrl string) (interface{}, error) {
   223  	if nextPageUrl == "" {
   224  		return nil, nil
   225  	}
   226  	resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
   227  	if err != nil {
   228  		return nil, err
   229  	}
   230  
   231  	defer resp.Body.Close()
   232  
   233  	ps := &ListServiceResponse{}
   234  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   235  		return nil, err
   236  	}
   237  	return ps, nil
   238  }
   239  
   240  // Optional parameters for the method 'UpdateService'
   241  type UpdateServiceParams struct {
   242  	// A descriptive string that you create to describe the resource. It can be up to 64 characters long.
   243  	FriendlyName *string `json:"FriendlyName,omitempty"`
   244  	// The service role assigned to users when they are added to the service. See the [Roles endpoint](https://www.twilio.com/docs/chat/api/roles) for more details.
   245  	DefaultServiceRoleSid *string `json:"DefaultServiceRoleSid,omitempty"`
   246  	// The channel role assigned to users when they are added to a channel. See the [Roles endpoint](https://www.twilio.com/docs/chat/api/roles) for more details.
   247  	DefaultChannelRoleSid *string `json:"DefaultChannelRoleSid,omitempty"`
   248  	// The channel role assigned to a channel creator when they join a new channel. See the [Roles endpoint](https://www.twilio.com/docs/chat/api/roles) for more details.
   249  	DefaultChannelCreatorRoleSid *string `json:"DefaultChannelCreatorRoleSid,omitempty"`
   250  	// Whether to enable the [Message Consumption Horizon](https://www.twilio.com/docs/chat/consumption-horizon) feature. The default is `true`.
   251  	ReadStatusEnabled *bool `json:"ReadStatusEnabled,omitempty"`
   252  	// Whether to enable the [Reachability Indicator](https://www.twilio.com/docs/chat/reachability-indicator) for this Service instance. The default is `false`.
   253  	ReachabilityEnabled *bool `json:"ReachabilityEnabled,omitempty"`
   254  	// How long in seconds after a `started typing` event until clients should assume that user is no longer typing, even if no `ended typing` message was received.  The default is 5 seconds.
   255  	TypingIndicatorTimeout *int `json:"TypingIndicatorTimeout,omitempty"`
   256  	// DEPRECATED. The interval in seconds between consumption reports submission batches from client endpoints.
   257  	ConsumptionReportInterval *int `json:"ConsumptionReportInterval,omitempty"`
   258  	// Whether to send a notification when a new message is added to a channel. Can be: `true` or `false` and the default is `false`.
   259  	NotificationsNewMessageEnabled *bool `json:"Notifications.NewMessage.Enabled,omitempty"`
   260  	// The template to use to create the notification text displayed when a new message is added to a channel and `notifications.new_message.enabled` is `true`.
   261  	NotificationsNewMessageTemplate *string `json:"Notifications.NewMessage.Template,omitempty"`
   262  	// Whether to send a notification when a member is added to a channel. Can be: `true` or `false` and the default is `false`.
   263  	NotificationsAddedToChannelEnabled *bool `json:"Notifications.AddedToChannel.Enabled,omitempty"`
   264  	// The template to use to create the notification text displayed when a member is added to a channel and `notifications.added_to_channel.enabled` is `true`.
   265  	NotificationsAddedToChannelTemplate *string `json:"Notifications.AddedToChannel.Template,omitempty"`
   266  	// Whether to send a notification to a user when they are removed from a channel. Can be: `true` or `false` and the default is `false`.
   267  	NotificationsRemovedFromChannelEnabled *bool `json:"Notifications.RemovedFromChannel.Enabled,omitempty"`
   268  	// The template to use to create the notification text displayed to a user when they are removed from a channel and `notifications.removed_from_channel.enabled` is `true`.
   269  	NotificationsRemovedFromChannelTemplate *string `json:"Notifications.RemovedFromChannel.Template,omitempty"`
   270  	// Whether to send a notification when a user is invited to a channel. Can be: `true` or `false` and the default is `false`.
   271  	NotificationsInvitedToChannelEnabled *bool `json:"Notifications.InvitedToChannel.Enabled,omitempty"`
   272  	// The template to use to create the notification text displayed when a user is invited to a channel and `notifications.invited_to_channel.enabled` is `true`.
   273  	NotificationsInvitedToChannelTemplate *string `json:"Notifications.InvitedToChannel.Template,omitempty"`
   274  	// The URL for pre-event webhooks, which are called by using the `webhook_method`. See [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.
   275  	PreWebhookUrl *string `json:"PreWebhookUrl,omitempty"`
   276  	// The URL for post-event webhooks, which are called by using the `webhook_method`. See [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.
   277  	PostWebhookUrl *string `json:"PostWebhookUrl,omitempty"`
   278  	// The HTTP method to use for calls to the `pre_webhook_url` and `post_webhook_url` webhooks.  Can be: `POST` or `GET` and the default is `POST`. See [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more details.
   279  	WebhookMethod *string `json:"WebhookMethod,omitempty"`
   280  	// The list of WebHook events that are enabled for this Service instance. See [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more details.
   281  	WebhookFilters *[]string `json:"WebhookFilters,omitempty"`
   282  	// The URL of the webhook to call in response to the `on_message_send` event using the `webhooks.on_message_send.method` HTTP method.
   283  	WebhooksOnMessageSendUrl *string `json:"Webhooks.OnMessageSend.Url,omitempty"`
   284  	// The HTTP method to use when calling the `webhooks.on_message_send.url`.
   285  	WebhooksOnMessageSendMethod *string `json:"Webhooks.OnMessageSend.Method,omitempty"`
   286  	// The URL of the webhook to call in response to the `on_message_update` event using the `webhooks.on_message_update.method` HTTP method.
   287  	WebhooksOnMessageUpdateUrl *string `json:"Webhooks.OnMessageUpdate.Url,omitempty"`
   288  	// The HTTP method to use when calling the `webhooks.on_message_update.url`.
   289  	WebhooksOnMessageUpdateMethod *string `json:"Webhooks.OnMessageUpdate.Method,omitempty"`
   290  	// The URL of the webhook to call in response to the `on_message_remove` event using the `webhooks.on_message_remove.method` HTTP method.
   291  	WebhooksOnMessageRemoveUrl *string `json:"Webhooks.OnMessageRemove.Url,omitempty"`
   292  	// The HTTP method to use when calling the `webhooks.on_message_remove.url`.
   293  	WebhooksOnMessageRemoveMethod *string `json:"Webhooks.OnMessageRemove.Method,omitempty"`
   294  	// The URL of the webhook to call in response to the `on_channel_add` event using the `webhooks.on_channel_add.method` HTTP method.
   295  	WebhooksOnChannelAddUrl *string `json:"Webhooks.OnChannelAdd.Url,omitempty"`
   296  	// The HTTP method to use when calling the `webhooks.on_channel_add.url`.
   297  	WebhooksOnChannelAddMethod *string `json:"Webhooks.OnChannelAdd.Method,omitempty"`
   298  	// The URL of the webhook to call in response to the `on_channel_destroy` event using the `webhooks.on_channel_destroy.method` HTTP method.
   299  	WebhooksOnChannelDestroyUrl *string `json:"Webhooks.OnChannelDestroy.Url,omitempty"`
   300  	// The HTTP method to use when calling the `webhooks.on_channel_destroy.url`.
   301  	WebhooksOnChannelDestroyMethod *string `json:"Webhooks.OnChannelDestroy.Method,omitempty"`
   302  	// The URL of the webhook to call in response to the `on_channel_update` event using the `webhooks.on_channel_update.method` HTTP method.
   303  	WebhooksOnChannelUpdateUrl *string `json:"Webhooks.OnChannelUpdate.Url,omitempty"`
   304  	// The HTTP method to use when calling the `webhooks.on_channel_update.url`.
   305  	WebhooksOnChannelUpdateMethod *string `json:"Webhooks.OnChannelUpdate.Method,omitempty"`
   306  	// The URL of the webhook to call in response to the `on_member_add` event using the `webhooks.on_member_add.method` HTTP method.
   307  	WebhooksOnMemberAddUrl *string `json:"Webhooks.OnMemberAdd.Url,omitempty"`
   308  	// The HTTP method to use when calling the `webhooks.on_member_add.url`.
   309  	WebhooksOnMemberAddMethod *string `json:"Webhooks.OnMemberAdd.Method,omitempty"`
   310  	// The URL of the webhook to call in response to the `on_member_remove` event using the `webhooks.on_member_remove.method` HTTP method.
   311  	WebhooksOnMemberRemoveUrl *string `json:"Webhooks.OnMemberRemove.Url,omitempty"`
   312  	// The HTTP method to use when calling the `webhooks.on_member_remove.url`.
   313  	WebhooksOnMemberRemoveMethod *string `json:"Webhooks.OnMemberRemove.Method,omitempty"`
   314  	// The URL of the webhook to call in response to the `on_message_sent` event using the `webhooks.on_message_sent.method` HTTP method.
   315  	WebhooksOnMessageSentUrl *string `json:"Webhooks.OnMessageSent.Url,omitempty"`
   316  	// The URL of the webhook to call in response to the `on_message_sent` event`.
   317  	WebhooksOnMessageSentMethod *string `json:"Webhooks.OnMessageSent.Method,omitempty"`
   318  	// The URL of the webhook to call in response to the `on_message_updated` event using the `webhooks.on_message_updated.method` HTTP method.
   319  	WebhooksOnMessageUpdatedUrl *string `json:"Webhooks.OnMessageUpdated.Url,omitempty"`
   320  	// The HTTP method to use when calling the `webhooks.on_message_updated.url`.
   321  	WebhooksOnMessageUpdatedMethod *string `json:"Webhooks.OnMessageUpdated.Method,omitempty"`
   322  	// The URL of the webhook to call in response to the `on_message_removed` event using the `webhooks.on_message_removed.method` HTTP method.
   323  	WebhooksOnMessageRemovedUrl *string `json:"Webhooks.OnMessageRemoved.Url,omitempty"`
   324  	// The HTTP method to use when calling the `webhooks.on_message_removed.url`.
   325  	WebhooksOnMessageRemovedMethod *string `json:"Webhooks.OnMessageRemoved.Method,omitempty"`
   326  	// The URL of the webhook to call in response to the `on_channel_added` event using the `webhooks.on_channel_added.method` HTTP method.
   327  	WebhooksOnChannelAddedUrl *string `json:"Webhooks.OnChannelAdded.Url,omitempty"`
   328  	// The URL of the webhook to call in response to the `on_channel_added` event`.
   329  	WebhooksOnChannelAddedMethod *string `json:"Webhooks.OnChannelAdded.Method,omitempty"`
   330  	// The URL of the webhook to call in response to the `on_channel_added` event using the `webhooks.on_channel_destroyed.method` HTTP method.
   331  	WebhooksOnChannelDestroyedUrl *string `json:"Webhooks.OnChannelDestroyed.Url,omitempty"`
   332  	// The HTTP method to use when calling the `webhooks.on_channel_destroyed.url`.
   333  	WebhooksOnChannelDestroyedMethod *string `json:"Webhooks.OnChannelDestroyed.Method,omitempty"`
   334  	// The URL of the webhook to call in response to the `on_channel_updated` event using the `webhooks.on_channel_updated.method` HTTP method.
   335  	WebhooksOnChannelUpdatedUrl *string `json:"Webhooks.OnChannelUpdated.Url,omitempty"`
   336  	// The HTTP method to use when calling the `webhooks.on_channel_updated.url`.
   337  	WebhooksOnChannelUpdatedMethod *string `json:"Webhooks.OnChannelUpdated.Method,omitempty"`
   338  	// The URL of the webhook to call in response to the `on_channel_updated` event using the `webhooks.on_channel_updated.method` HTTP method.
   339  	WebhooksOnMemberAddedUrl *string `json:"Webhooks.OnMemberAdded.Url,omitempty"`
   340  	// The HTTP method to use when calling the `webhooks.on_channel_updated.url`.
   341  	WebhooksOnMemberAddedMethod *string `json:"Webhooks.OnMemberAdded.Method,omitempty"`
   342  	// The URL of the webhook to call in response to the `on_member_removed` event using the `webhooks.on_member_removed.method` HTTP method.
   343  	WebhooksOnMemberRemovedUrl *string `json:"Webhooks.OnMemberRemoved.Url,omitempty"`
   344  	// The HTTP method to use when calling the `webhooks.on_member_removed.url`.
   345  	WebhooksOnMemberRemovedMethod *string `json:"Webhooks.OnMemberRemoved.Method,omitempty"`
   346  	// The maximum number of Members that can be added to Channels within this Service. Can be up to 1,000.
   347  	LimitsChannelMembers *int `json:"Limits.ChannelMembers,omitempty"`
   348  	// The maximum number of Channels Users can be a Member of within this Service. Can be up to 1,000.
   349  	LimitsUserChannels *int `json:"Limits.UserChannels,omitempty"`
   350  }
   351  
   352  func (params *UpdateServiceParams) SetFriendlyName(FriendlyName string) *UpdateServiceParams {
   353  	params.FriendlyName = &FriendlyName
   354  	return params
   355  }
   356  func (params *UpdateServiceParams) SetDefaultServiceRoleSid(DefaultServiceRoleSid string) *UpdateServiceParams {
   357  	params.DefaultServiceRoleSid = &DefaultServiceRoleSid
   358  	return params
   359  }
   360  func (params *UpdateServiceParams) SetDefaultChannelRoleSid(DefaultChannelRoleSid string) *UpdateServiceParams {
   361  	params.DefaultChannelRoleSid = &DefaultChannelRoleSid
   362  	return params
   363  }
   364  func (params *UpdateServiceParams) SetDefaultChannelCreatorRoleSid(DefaultChannelCreatorRoleSid string) *UpdateServiceParams {
   365  	params.DefaultChannelCreatorRoleSid = &DefaultChannelCreatorRoleSid
   366  	return params
   367  }
   368  func (params *UpdateServiceParams) SetReadStatusEnabled(ReadStatusEnabled bool) *UpdateServiceParams {
   369  	params.ReadStatusEnabled = &ReadStatusEnabled
   370  	return params
   371  }
   372  func (params *UpdateServiceParams) SetReachabilityEnabled(ReachabilityEnabled bool) *UpdateServiceParams {
   373  	params.ReachabilityEnabled = &ReachabilityEnabled
   374  	return params
   375  }
   376  func (params *UpdateServiceParams) SetTypingIndicatorTimeout(TypingIndicatorTimeout int) *UpdateServiceParams {
   377  	params.TypingIndicatorTimeout = &TypingIndicatorTimeout
   378  	return params
   379  }
   380  func (params *UpdateServiceParams) SetConsumptionReportInterval(ConsumptionReportInterval int) *UpdateServiceParams {
   381  	params.ConsumptionReportInterval = &ConsumptionReportInterval
   382  	return params
   383  }
   384  func (params *UpdateServiceParams) SetNotificationsNewMessageEnabled(NotificationsNewMessageEnabled bool) *UpdateServiceParams {
   385  	params.NotificationsNewMessageEnabled = &NotificationsNewMessageEnabled
   386  	return params
   387  }
   388  func (params *UpdateServiceParams) SetNotificationsNewMessageTemplate(NotificationsNewMessageTemplate string) *UpdateServiceParams {
   389  	params.NotificationsNewMessageTemplate = &NotificationsNewMessageTemplate
   390  	return params
   391  }
   392  func (params *UpdateServiceParams) SetNotificationsAddedToChannelEnabled(NotificationsAddedToChannelEnabled bool) *UpdateServiceParams {
   393  	params.NotificationsAddedToChannelEnabled = &NotificationsAddedToChannelEnabled
   394  	return params
   395  }
   396  func (params *UpdateServiceParams) SetNotificationsAddedToChannelTemplate(NotificationsAddedToChannelTemplate string) *UpdateServiceParams {
   397  	params.NotificationsAddedToChannelTemplate = &NotificationsAddedToChannelTemplate
   398  	return params
   399  }
   400  func (params *UpdateServiceParams) SetNotificationsRemovedFromChannelEnabled(NotificationsRemovedFromChannelEnabled bool) *UpdateServiceParams {
   401  	params.NotificationsRemovedFromChannelEnabled = &NotificationsRemovedFromChannelEnabled
   402  	return params
   403  }
   404  func (params *UpdateServiceParams) SetNotificationsRemovedFromChannelTemplate(NotificationsRemovedFromChannelTemplate string) *UpdateServiceParams {
   405  	params.NotificationsRemovedFromChannelTemplate = &NotificationsRemovedFromChannelTemplate
   406  	return params
   407  }
   408  func (params *UpdateServiceParams) SetNotificationsInvitedToChannelEnabled(NotificationsInvitedToChannelEnabled bool) *UpdateServiceParams {
   409  	params.NotificationsInvitedToChannelEnabled = &NotificationsInvitedToChannelEnabled
   410  	return params
   411  }
   412  func (params *UpdateServiceParams) SetNotificationsInvitedToChannelTemplate(NotificationsInvitedToChannelTemplate string) *UpdateServiceParams {
   413  	params.NotificationsInvitedToChannelTemplate = &NotificationsInvitedToChannelTemplate
   414  	return params
   415  }
   416  func (params *UpdateServiceParams) SetPreWebhookUrl(PreWebhookUrl string) *UpdateServiceParams {
   417  	params.PreWebhookUrl = &PreWebhookUrl
   418  	return params
   419  }
   420  func (params *UpdateServiceParams) SetPostWebhookUrl(PostWebhookUrl string) *UpdateServiceParams {
   421  	params.PostWebhookUrl = &PostWebhookUrl
   422  	return params
   423  }
   424  func (params *UpdateServiceParams) SetWebhookMethod(WebhookMethod string) *UpdateServiceParams {
   425  	params.WebhookMethod = &WebhookMethod
   426  	return params
   427  }
   428  func (params *UpdateServiceParams) SetWebhookFilters(WebhookFilters []string) *UpdateServiceParams {
   429  	params.WebhookFilters = &WebhookFilters
   430  	return params
   431  }
   432  func (params *UpdateServiceParams) SetWebhooksOnMessageSendUrl(WebhooksOnMessageSendUrl string) *UpdateServiceParams {
   433  	params.WebhooksOnMessageSendUrl = &WebhooksOnMessageSendUrl
   434  	return params
   435  }
   436  func (params *UpdateServiceParams) SetWebhooksOnMessageSendMethod(WebhooksOnMessageSendMethod string) *UpdateServiceParams {
   437  	params.WebhooksOnMessageSendMethod = &WebhooksOnMessageSendMethod
   438  	return params
   439  }
   440  func (params *UpdateServiceParams) SetWebhooksOnMessageUpdateUrl(WebhooksOnMessageUpdateUrl string) *UpdateServiceParams {
   441  	params.WebhooksOnMessageUpdateUrl = &WebhooksOnMessageUpdateUrl
   442  	return params
   443  }
   444  func (params *UpdateServiceParams) SetWebhooksOnMessageUpdateMethod(WebhooksOnMessageUpdateMethod string) *UpdateServiceParams {
   445  	params.WebhooksOnMessageUpdateMethod = &WebhooksOnMessageUpdateMethod
   446  	return params
   447  }
   448  func (params *UpdateServiceParams) SetWebhooksOnMessageRemoveUrl(WebhooksOnMessageRemoveUrl string) *UpdateServiceParams {
   449  	params.WebhooksOnMessageRemoveUrl = &WebhooksOnMessageRemoveUrl
   450  	return params
   451  }
   452  func (params *UpdateServiceParams) SetWebhooksOnMessageRemoveMethod(WebhooksOnMessageRemoveMethod string) *UpdateServiceParams {
   453  	params.WebhooksOnMessageRemoveMethod = &WebhooksOnMessageRemoveMethod
   454  	return params
   455  }
   456  func (params *UpdateServiceParams) SetWebhooksOnChannelAddUrl(WebhooksOnChannelAddUrl string) *UpdateServiceParams {
   457  	params.WebhooksOnChannelAddUrl = &WebhooksOnChannelAddUrl
   458  	return params
   459  }
   460  func (params *UpdateServiceParams) SetWebhooksOnChannelAddMethod(WebhooksOnChannelAddMethod string) *UpdateServiceParams {
   461  	params.WebhooksOnChannelAddMethod = &WebhooksOnChannelAddMethod
   462  	return params
   463  }
   464  func (params *UpdateServiceParams) SetWebhooksOnChannelDestroyUrl(WebhooksOnChannelDestroyUrl string) *UpdateServiceParams {
   465  	params.WebhooksOnChannelDestroyUrl = &WebhooksOnChannelDestroyUrl
   466  	return params
   467  }
   468  func (params *UpdateServiceParams) SetWebhooksOnChannelDestroyMethod(WebhooksOnChannelDestroyMethod string) *UpdateServiceParams {
   469  	params.WebhooksOnChannelDestroyMethod = &WebhooksOnChannelDestroyMethod
   470  	return params
   471  }
   472  func (params *UpdateServiceParams) SetWebhooksOnChannelUpdateUrl(WebhooksOnChannelUpdateUrl string) *UpdateServiceParams {
   473  	params.WebhooksOnChannelUpdateUrl = &WebhooksOnChannelUpdateUrl
   474  	return params
   475  }
   476  func (params *UpdateServiceParams) SetWebhooksOnChannelUpdateMethod(WebhooksOnChannelUpdateMethod string) *UpdateServiceParams {
   477  	params.WebhooksOnChannelUpdateMethod = &WebhooksOnChannelUpdateMethod
   478  	return params
   479  }
   480  func (params *UpdateServiceParams) SetWebhooksOnMemberAddUrl(WebhooksOnMemberAddUrl string) *UpdateServiceParams {
   481  	params.WebhooksOnMemberAddUrl = &WebhooksOnMemberAddUrl
   482  	return params
   483  }
   484  func (params *UpdateServiceParams) SetWebhooksOnMemberAddMethod(WebhooksOnMemberAddMethod string) *UpdateServiceParams {
   485  	params.WebhooksOnMemberAddMethod = &WebhooksOnMemberAddMethod
   486  	return params
   487  }
   488  func (params *UpdateServiceParams) SetWebhooksOnMemberRemoveUrl(WebhooksOnMemberRemoveUrl string) *UpdateServiceParams {
   489  	params.WebhooksOnMemberRemoveUrl = &WebhooksOnMemberRemoveUrl
   490  	return params
   491  }
   492  func (params *UpdateServiceParams) SetWebhooksOnMemberRemoveMethod(WebhooksOnMemberRemoveMethod string) *UpdateServiceParams {
   493  	params.WebhooksOnMemberRemoveMethod = &WebhooksOnMemberRemoveMethod
   494  	return params
   495  }
   496  func (params *UpdateServiceParams) SetWebhooksOnMessageSentUrl(WebhooksOnMessageSentUrl string) *UpdateServiceParams {
   497  	params.WebhooksOnMessageSentUrl = &WebhooksOnMessageSentUrl
   498  	return params
   499  }
   500  func (params *UpdateServiceParams) SetWebhooksOnMessageSentMethod(WebhooksOnMessageSentMethod string) *UpdateServiceParams {
   501  	params.WebhooksOnMessageSentMethod = &WebhooksOnMessageSentMethod
   502  	return params
   503  }
   504  func (params *UpdateServiceParams) SetWebhooksOnMessageUpdatedUrl(WebhooksOnMessageUpdatedUrl string) *UpdateServiceParams {
   505  	params.WebhooksOnMessageUpdatedUrl = &WebhooksOnMessageUpdatedUrl
   506  	return params
   507  }
   508  func (params *UpdateServiceParams) SetWebhooksOnMessageUpdatedMethod(WebhooksOnMessageUpdatedMethod string) *UpdateServiceParams {
   509  	params.WebhooksOnMessageUpdatedMethod = &WebhooksOnMessageUpdatedMethod
   510  	return params
   511  }
   512  func (params *UpdateServiceParams) SetWebhooksOnMessageRemovedUrl(WebhooksOnMessageRemovedUrl string) *UpdateServiceParams {
   513  	params.WebhooksOnMessageRemovedUrl = &WebhooksOnMessageRemovedUrl
   514  	return params
   515  }
   516  func (params *UpdateServiceParams) SetWebhooksOnMessageRemovedMethod(WebhooksOnMessageRemovedMethod string) *UpdateServiceParams {
   517  	params.WebhooksOnMessageRemovedMethod = &WebhooksOnMessageRemovedMethod
   518  	return params
   519  }
   520  func (params *UpdateServiceParams) SetWebhooksOnChannelAddedUrl(WebhooksOnChannelAddedUrl string) *UpdateServiceParams {
   521  	params.WebhooksOnChannelAddedUrl = &WebhooksOnChannelAddedUrl
   522  	return params
   523  }
   524  func (params *UpdateServiceParams) SetWebhooksOnChannelAddedMethod(WebhooksOnChannelAddedMethod string) *UpdateServiceParams {
   525  	params.WebhooksOnChannelAddedMethod = &WebhooksOnChannelAddedMethod
   526  	return params
   527  }
   528  func (params *UpdateServiceParams) SetWebhooksOnChannelDestroyedUrl(WebhooksOnChannelDestroyedUrl string) *UpdateServiceParams {
   529  	params.WebhooksOnChannelDestroyedUrl = &WebhooksOnChannelDestroyedUrl
   530  	return params
   531  }
   532  func (params *UpdateServiceParams) SetWebhooksOnChannelDestroyedMethod(WebhooksOnChannelDestroyedMethod string) *UpdateServiceParams {
   533  	params.WebhooksOnChannelDestroyedMethod = &WebhooksOnChannelDestroyedMethod
   534  	return params
   535  }
   536  func (params *UpdateServiceParams) SetWebhooksOnChannelUpdatedUrl(WebhooksOnChannelUpdatedUrl string) *UpdateServiceParams {
   537  	params.WebhooksOnChannelUpdatedUrl = &WebhooksOnChannelUpdatedUrl
   538  	return params
   539  }
   540  func (params *UpdateServiceParams) SetWebhooksOnChannelUpdatedMethod(WebhooksOnChannelUpdatedMethod string) *UpdateServiceParams {
   541  	params.WebhooksOnChannelUpdatedMethod = &WebhooksOnChannelUpdatedMethod
   542  	return params
   543  }
   544  func (params *UpdateServiceParams) SetWebhooksOnMemberAddedUrl(WebhooksOnMemberAddedUrl string) *UpdateServiceParams {
   545  	params.WebhooksOnMemberAddedUrl = &WebhooksOnMemberAddedUrl
   546  	return params
   547  }
   548  func (params *UpdateServiceParams) SetWebhooksOnMemberAddedMethod(WebhooksOnMemberAddedMethod string) *UpdateServiceParams {
   549  	params.WebhooksOnMemberAddedMethod = &WebhooksOnMemberAddedMethod
   550  	return params
   551  }
   552  func (params *UpdateServiceParams) SetWebhooksOnMemberRemovedUrl(WebhooksOnMemberRemovedUrl string) *UpdateServiceParams {
   553  	params.WebhooksOnMemberRemovedUrl = &WebhooksOnMemberRemovedUrl
   554  	return params
   555  }
   556  func (params *UpdateServiceParams) SetWebhooksOnMemberRemovedMethod(WebhooksOnMemberRemovedMethod string) *UpdateServiceParams {
   557  	params.WebhooksOnMemberRemovedMethod = &WebhooksOnMemberRemovedMethod
   558  	return params
   559  }
   560  func (params *UpdateServiceParams) SetLimitsChannelMembers(LimitsChannelMembers int) *UpdateServiceParams {
   561  	params.LimitsChannelMembers = &LimitsChannelMembers
   562  	return params
   563  }
   564  func (params *UpdateServiceParams) SetLimitsUserChannels(LimitsUserChannels int) *UpdateServiceParams {
   565  	params.LimitsUserChannels = &LimitsUserChannels
   566  	return params
   567  }
   568  
   569  //
   570  func (c *ApiService) UpdateService(Sid string, params *UpdateServiceParams) (*ChatV1Service, error) {
   571  	path := "/v1/Services/{Sid}"
   572  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   573  
   574  	data := url.Values{}
   575  	headers := make(map[string]interface{})
   576  
   577  	if params != nil && params.FriendlyName != nil {
   578  		data.Set("FriendlyName", *params.FriendlyName)
   579  	}
   580  	if params != nil && params.DefaultServiceRoleSid != nil {
   581  		data.Set("DefaultServiceRoleSid", *params.DefaultServiceRoleSid)
   582  	}
   583  	if params != nil && params.DefaultChannelRoleSid != nil {
   584  		data.Set("DefaultChannelRoleSid", *params.DefaultChannelRoleSid)
   585  	}
   586  	if params != nil && params.DefaultChannelCreatorRoleSid != nil {
   587  		data.Set("DefaultChannelCreatorRoleSid", *params.DefaultChannelCreatorRoleSid)
   588  	}
   589  	if params != nil && params.ReadStatusEnabled != nil {
   590  		data.Set("ReadStatusEnabled", fmt.Sprint(*params.ReadStatusEnabled))
   591  	}
   592  	if params != nil && params.ReachabilityEnabled != nil {
   593  		data.Set("ReachabilityEnabled", fmt.Sprint(*params.ReachabilityEnabled))
   594  	}
   595  	if params != nil && params.TypingIndicatorTimeout != nil {
   596  		data.Set("TypingIndicatorTimeout", fmt.Sprint(*params.TypingIndicatorTimeout))
   597  	}
   598  	if params != nil && params.ConsumptionReportInterval != nil {
   599  		data.Set("ConsumptionReportInterval", fmt.Sprint(*params.ConsumptionReportInterval))
   600  	}
   601  	if params != nil && params.NotificationsNewMessageEnabled != nil {
   602  		data.Set("Notifications.NewMessage.Enabled", fmt.Sprint(*params.NotificationsNewMessageEnabled))
   603  	}
   604  	if params != nil && params.NotificationsNewMessageTemplate != nil {
   605  		data.Set("Notifications.NewMessage.Template", *params.NotificationsNewMessageTemplate)
   606  	}
   607  	if params != nil && params.NotificationsAddedToChannelEnabled != nil {
   608  		data.Set("Notifications.AddedToChannel.Enabled", fmt.Sprint(*params.NotificationsAddedToChannelEnabled))
   609  	}
   610  	if params != nil && params.NotificationsAddedToChannelTemplate != nil {
   611  		data.Set("Notifications.AddedToChannel.Template", *params.NotificationsAddedToChannelTemplate)
   612  	}
   613  	if params != nil && params.NotificationsRemovedFromChannelEnabled != nil {
   614  		data.Set("Notifications.RemovedFromChannel.Enabled", fmt.Sprint(*params.NotificationsRemovedFromChannelEnabled))
   615  	}
   616  	if params != nil && params.NotificationsRemovedFromChannelTemplate != nil {
   617  		data.Set("Notifications.RemovedFromChannel.Template", *params.NotificationsRemovedFromChannelTemplate)
   618  	}
   619  	if params != nil && params.NotificationsInvitedToChannelEnabled != nil {
   620  		data.Set("Notifications.InvitedToChannel.Enabled", fmt.Sprint(*params.NotificationsInvitedToChannelEnabled))
   621  	}
   622  	if params != nil && params.NotificationsInvitedToChannelTemplate != nil {
   623  		data.Set("Notifications.InvitedToChannel.Template", *params.NotificationsInvitedToChannelTemplate)
   624  	}
   625  	if params != nil && params.PreWebhookUrl != nil {
   626  		data.Set("PreWebhookUrl", *params.PreWebhookUrl)
   627  	}
   628  	if params != nil && params.PostWebhookUrl != nil {
   629  		data.Set("PostWebhookUrl", *params.PostWebhookUrl)
   630  	}
   631  	if params != nil && params.WebhookMethod != nil {
   632  		data.Set("WebhookMethod", *params.WebhookMethod)
   633  	}
   634  	if params != nil && params.WebhookFilters != nil {
   635  		for _, item := range *params.WebhookFilters {
   636  			data.Add("WebhookFilters", item)
   637  		}
   638  	}
   639  	if params != nil && params.WebhooksOnMessageSendUrl != nil {
   640  		data.Set("Webhooks.OnMessageSend.Url", *params.WebhooksOnMessageSendUrl)
   641  	}
   642  	if params != nil && params.WebhooksOnMessageSendMethod != nil {
   643  		data.Set("Webhooks.OnMessageSend.Method", *params.WebhooksOnMessageSendMethod)
   644  	}
   645  	if params != nil && params.WebhooksOnMessageUpdateUrl != nil {
   646  		data.Set("Webhooks.OnMessageUpdate.Url", *params.WebhooksOnMessageUpdateUrl)
   647  	}
   648  	if params != nil && params.WebhooksOnMessageUpdateMethod != nil {
   649  		data.Set("Webhooks.OnMessageUpdate.Method", *params.WebhooksOnMessageUpdateMethod)
   650  	}
   651  	if params != nil && params.WebhooksOnMessageRemoveUrl != nil {
   652  		data.Set("Webhooks.OnMessageRemove.Url", *params.WebhooksOnMessageRemoveUrl)
   653  	}
   654  	if params != nil && params.WebhooksOnMessageRemoveMethod != nil {
   655  		data.Set("Webhooks.OnMessageRemove.Method", *params.WebhooksOnMessageRemoveMethod)
   656  	}
   657  	if params != nil && params.WebhooksOnChannelAddUrl != nil {
   658  		data.Set("Webhooks.OnChannelAdd.Url", *params.WebhooksOnChannelAddUrl)
   659  	}
   660  	if params != nil && params.WebhooksOnChannelAddMethod != nil {
   661  		data.Set("Webhooks.OnChannelAdd.Method", *params.WebhooksOnChannelAddMethod)
   662  	}
   663  	if params != nil && params.WebhooksOnChannelDestroyUrl != nil {
   664  		data.Set("Webhooks.OnChannelDestroy.Url", *params.WebhooksOnChannelDestroyUrl)
   665  	}
   666  	if params != nil && params.WebhooksOnChannelDestroyMethod != nil {
   667  		data.Set("Webhooks.OnChannelDestroy.Method", *params.WebhooksOnChannelDestroyMethod)
   668  	}
   669  	if params != nil && params.WebhooksOnChannelUpdateUrl != nil {
   670  		data.Set("Webhooks.OnChannelUpdate.Url", *params.WebhooksOnChannelUpdateUrl)
   671  	}
   672  	if params != nil && params.WebhooksOnChannelUpdateMethod != nil {
   673  		data.Set("Webhooks.OnChannelUpdate.Method", *params.WebhooksOnChannelUpdateMethod)
   674  	}
   675  	if params != nil && params.WebhooksOnMemberAddUrl != nil {
   676  		data.Set("Webhooks.OnMemberAdd.Url", *params.WebhooksOnMemberAddUrl)
   677  	}
   678  	if params != nil && params.WebhooksOnMemberAddMethod != nil {
   679  		data.Set("Webhooks.OnMemberAdd.Method", *params.WebhooksOnMemberAddMethod)
   680  	}
   681  	if params != nil && params.WebhooksOnMemberRemoveUrl != nil {
   682  		data.Set("Webhooks.OnMemberRemove.Url", *params.WebhooksOnMemberRemoveUrl)
   683  	}
   684  	if params != nil && params.WebhooksOnMemberRemoveMethod != nil {
   685  		data.Set("Webhooks.OnMemberRemove.Method", *params.WebhooksOnMemberRemoveMethod)
   686  	}
   687  	if params != nil && params.WebhooksOnMessageSentUrl != nil {
   688  		data.Set("Webhooks.OnMessageSent.Url", *params.WebhooksOnMessageSentUrl)
   689  	}
   690  	if params != nil && params.WebhooksOnMessageSentMethod != nil {
   691  		data.Set("Webhooks.OnMessageSent.Method", *params.WebhooksOnMessageSentMethod)
   692  	}
   693  	if params != nil && params.WebhooksOnMessageUpdatedUrl != nil {
   694  		data.Set("Webhooks.OnMessageUpdated.Url", *params.WebhooksOnMessageUpdatedUrl)
   695  	}
   696  	if params != nil && params.WebhooksOnMessageUpdatedMethod != nil {
   697  		data.Set("Webhooks.OnMessageUpdated.Method", *params.WebhooksOnMessageUpdatedMethod)
   698  	}
   699  	if params != nil && params.WebhooksOnMessageRemovedUrl != nil {
   700  		data.Set("Webhooks.OnMessageRemoved.Url", *params.WebhooksOnMessageRemovedUrl)
   701  	}
   702  	if params != nil && params.WebhooksOnMessageRemovedMethod != nil {
   703  		data.Set("Webhooks.OnMessageRemoved.Method", *params.WebhooksOnMessageRemovedMethod)
   704  	}
   705  	if params != nil && params.WebhooksOnChannelAddedUrl != nil {
   706  		data.Set("Webhooks.OnChannelAdded.Url", *params.WebhooksOnChannelAddedUrl)
   707  	}
   708  	if params != nil && params.WebhooksOnChannelAddedMethod != nil {
   709  		data.Set("Webhooks.OnChannelAdded.Method", *params.WebhooksOnChannelAddedMethod)
   710  	}
   711  	if params != nil && params.WebhooksOnChannelDestroyedUrl != nil {
   712  		data.Set("Webhooks.OnChannelDestroyed.Url", *params.WebhooksOnChannelDestroyedUrl)
   713  	}
   714  	if params != nil && params.WebhooksOnChannelDestroyedMethod != nil {
   715  		data.Set("Webhooks.OnChannelDestroyed.Method", *params.WebhooksOnChannelDestroyedMethod)
   716  	}
   717  	if params != nil && params.WebhooksOnChannelUpdatedUrl != nil {
   718  		data.Set("Webhooks.OnChannelUpdated.Url", *params.WebhooksOnChannelUpdatedUrl)
   719  	}
   720  	if params != nil && params.WebhooksOnChannelUpdatedMethod != nil {
   721  		data.Set("Webhooks.OnChannelUpdated.Method", *params.WebhooksOnChannelUpdatedMethod)
   722  	}
   723  	if params != nil && params.WebhooksOnMemberAddedUrl != nil {
   724  		data.Set("Webhooks.OnMemberAdded.Url", *params.WebhooksOnMemberAddedUrl)
   725  	}
   726  	if params != nil && params.WebhooksOnMemberAddedMethod != nil {
   727  		data.Set("Webhooks.OnMemberAdded.Method", *params.WebhooksOnMemberAddedMethod)
   728  	}
   729  	if params != nil && params.WebhooksOnMemberRemovedUrl != nil {
   730  		data.Set("Webhooks.OnMemberRemoved.Url", *params.WebhooksOnMemberRemovedUrl)
   731  	}
   732  	if params != nil && params.WebhooksOnMemberRemovedMethod != nil {
   733  		data.Set("Webhooks.OnMemberRemoved.Method", *params.WebhooksOnMemberRemovedMethod)
   734  	}
   735  	if params != nil && params.LimitsChannelMembers != nil {
   736  		data.Set("Limits.ChannelMembers", fmt.Sprint(*params.LimitsChannelMembers))
   737  	}
   738  	if params != nil && params.LimitsUserChannels != nil {
   739  		data.Set("Limits.UserChannels", fmt.Sprint(*params.LimitsUserChannels))
   740  	}
   741  
   742  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   743  	if err != nil {
   744  		return nil, err
   745  	}
   746  
   747  	defer resp.Body.Close()
   748  
   749  	ps := &ChatV1Service{}
   750  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   751  		return nil, err
   752  	}
   753  
   754  	return ps, err
   755  }