github.com/twilio/twilio-go@v1.20.1/rest/conversations/v1/services_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  	"fmt"
    20  	"net/url"
    21  	"strings"
    22  )
    23  
    24  // Fetch the configuration of a conversation service
    25  func (c *ApiService) FetchServiceConfiguration(ChatServiceSid string) (*ConversationsV1ServiceConfiguration, error) {
    26  	path := "/v1/Services/{ChatServiceSid}/Configuration"
    27  	path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1)
    28  
    29  	data := url.Values{}
    30  	headers := make(map[string]interface{})
    31  
    32  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	defer resp.Body.Close()
    38  
    39  	ps := &ConversationsV1ServiceConfiguration{}
    40  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	return ps, err
    45  }
    46  
    47  // Optional parameters for the method 'UpdateServiceConfiguration'
    48  type UpdateServiceConfigurationParams struct {
    49  	// The conversation-level role assigned to a conversation creator when they join a new conversation. See [Conversation Role](https://www.twilio.com/docs/conversations/api/role-resource) for more info about roles.
    50  	DefaultConversationCreatorRoleSid *string `json:"DefaultConversationCreatorRoleSid,omitempty"`
    51  	// The conversation-level role assigned to users when they are added to a conversation. See [Conversation Role](https://www.twilio.com/docs/conversations/api/role-resource) for more info about roles.
    52  	DefaultConversationRoleSid *string `json:"DefaultConversationRoleSid,omitempty"`
    53  	// The service-level role assigned to users when they are added to the service. See [Conversation Role](https://www.twilio.com/docs/conversations/api/role-resource) for more info about roles.
    54  	DefaultChatServiceRoleSid *string `json:"DefaultChatServiceRoleSid,omitempty"`
    55  	// Whether the [Reachability Indicator](https://www.twilio.com/docs/conversations/reachability) is enabled for this Conversations Service. The default is `false`.
    56  	ReachabilityEnabled *bool `json:"ReachabilityEnabled,omitempty"`
    57  }
    58  
    59  func (params *UpdateServiceConfigurationParams) SetDefaultConversationCreatorRoleSid(DefaultConversationCreatorRoleSid string) *UpdateServiceConfigurationParams {
    60  	params.DefaultConversationCreatorRoleSid = &DefaultConversationCreatorRoleSid
    61  	return params
    62  }
    63  func (params *UpdateServiceConfigurationParams) SetDefaultConversationRoleSid(DefaultConversationRoleSid string) *UpdateServiceConfigurationParams {
    64  	params.DefaultConversationRoleSid = &DefaultConversationRoleSid
    65  	return params
    66  }
    67  func (params *UpdateServiceConfigurationParams) SetDefaultChatServiceRoleSid(DefaultChatServiceRoleSid string) *UpdateServiceConfigurationParams {
    68  	params.DefaultChatServiceRoleSid = &DefaultChatServiceRoleSid
    69  	return params
    70  }
    71  func (params *UpdateServiceConfigurationParams) SetReachabilityEnabled(ReachabilityEnabled bool) *UpdateServiceConfigurationParams {
    72  	params.ReachabilityEnabled = &ReachabilityEnabled
    73  	return params
    74  }
    75  
    76  // Update configuration settings of a conversation service
    77  func (c *ApiService) UpdateServiceConfiguration(ChatServiceSid string, params *UpdateServiceConfigurationParams) (*ConversationsV1ServiceConfiguration, error) {
    78  	path := "/v1/Services/{ChatServiceSid}/Configuration"
    79  	path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1)
    80  
    81  	data := url.Values{}
    82  	headers := make(map[string]interface{})
    83  
    84  	if params != nil && params.DefaultConversationCreatorRoleSid != nil {
    85  		data.Set("DefaultConversationCreatorRoleSid", *params.DefaultConversationCreatorRoleSid)
    86  	}
    87  	if params != nil && params.DefaultConversationRoleSid != nil {
    88  		data.Set("DefaultConversationRoleSid", *params.DefaultConversationRoleSid)
    89  	}
    90  	if params != nil && params.DefaultChatServiceRoleSid != nil {
    91  		data.Set("DefaultChatServiceRoleSid", *params.DefaultChatServiceRoleSid)
    92  	}
    93  	if params != nil && params.ReachabilityEnabled != nil {
    94  		data.Set("ReachabilityEnabled", fmt.Sprint(*params.ReachabilityEnabled))
    95  	}
    96  
    97  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  
   102  	defer resp.Body.Close()
   103  
   104  	ps := &ConversationsV1ServiceConfiguration{}
   105  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   106  		return nil, err
   107  	}
   108  
   109  	return ps, err
   110  }