github.com/twilio/twilio-go@v1.20.1/rest/conversations/v1/configuration.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  // Fetch the global configuration of conversations on your account
    23  func (c *ApiService) FetchConfiguration() (*ConversationsV1Configuration, error) {
    24  	path := "/v1/Configuration"
    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 := &ConversationsV1Configuration{}
    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 'UpdateConfiguration'
    45  type UpdateConfigurationParams struct {
    46  	// The SID of the default [Conversation Service](https://www.twilio.com/docs/conversations/api/service-resource) to use when creating a conversation.
    47  	DefaultChatServiceSid *string `json:"DefaultChatServiceSid,omitempty"`
    48  	// The SID of the default [Messaging Service](https://www.twilio.com/docs/messaging/api/service-resource) to use when creating a conversation.
    49  	DefaultMessagingServiceSid *string `json:"DefaultMessagingServiceSid,omitempty"`
    50  	// Default ISO8601 duration when conversation will be switched to `inactive` state. Minimum value for this timer is 1 minute.
    51  	DefaultInactiveTimer *string `json:"DefaultInactiveTimer,omitempty"`
    52  	// Default ISO8601 duration when conversation will be switched to `closed` state. Minimum value for this timer is 10 minutes.
    53  	DefaultClosedTimer *string `json:"DefaultClosedTimer,omitempty"`
    54  }
    55  
    56  func (params *UpdateConfigurationParams) SetDefaultChatServiceSid(DefaultChatServiceSid string) *UpdateConfigurationParams {
    57  	params.DefaultChatServiceSid = &DefaultChatServiceSid
    58  	return params
    59  }
    60  func (params *UpdateConfigurationParams) SetDefaultMessagingServiceSid(DefaultMessagingServiceSid string) *UpdateConfigurationParams {
    61  	params.DefaultMessagingServiceSid = &DefaultMessagingServiceSid
    62  	return params
    63  }
    64  func (params *UpdateConfigurationParams) SetDefaultInactiveTimer(DefaultInactiveTimer string) *UpdateConfigurationParams {
    65  	params.DefaultInactiveTimer = &DefaultInactiveTimer
    66  	return params
    67  }
    68  func (params *UpdateConfigurationParams) SetDefaultClosedTimer(DefaultClosedTimer string) *UpdateConfigurationParams {
    69  	params.DefaultClosedTimer = &DefaultClosedTimer
    70  	return params
    71  }
    72  
    73  // Update the global configuration of conversations on your account
    74  func (c *ApiService) UpdateConfiguration(params *UpdateConfigurationParams) (*ConversationsV1Configuration, error) {
    75  	path := "/v1/Configuration"
    76  
    77  	data := url.Values{}
    78  	headers := make(map[string]interface{})
    79  
    80  	if params != nil && params.DefaultChatServiceSid != nil {
    81  		data.Set("DefaultChatServiceSid", *params.DefaultChatServiceSid)
    82  	}
    83  	if params != nil && params.DefaultMessagingServiceSid != nil {
    84  		data.Set("DefaultMessagingServiceSid", *params.DefaultMessagingServiceSid)
    85  	}
    86  	if params != nil && params.DefaultInactiveTimer != nil {
    87  		data.Set("DefaultInactiveTimer", *params.DefaultInactiveTimer)
    88  	}
    89  	if params != nil && params.DefaultClosedTimer != nil {
    90  		data.Set("DefaultClosedTimer", *params.DefaultClosedTimer)
    91  	}
    92  
    93  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  
    98  	defer resp.Body.Close()
    99  
   100  	ps := &ConversationsV1Configuration{}
   101  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   102  		return nil, err
   103  	}
   104  
   105  	return ps, err
   106  }