github.com/twilio/twilio-go@v1.20.1/rest/conversations/v1/services_configuration_notifications.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 push notification service settings 25 func (c *ApiService) FetchServiceNotification(ChatServiceSid string) (*ConversationsV1ServiceNotification, error) { 26 path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" 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 := &ConversationsV1ServiceNotification{} 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 'UpdateServiceNotification' 48 type UpdateServiceNotificationParams struct { 49 // Weather the notification logging is enabled. 50 LogEnabled *bool `json:"LogEnabled,omitempty"` 51 // Whether to send a notification when a new message is added to a conversation. The default is `false`. 52 NewMessageEnabled *bool `json:"NewMessage.Enabled,omitempty"` 53 // The template to use to create the notification text displayed when a new message is added to a conversation and `new_message.enabled` is `true`. 54 NewMessageTemplate *string `json:"NewMessage.Template,omitempty"` 55 // The name of the sound to play when a new message is added to a conversation and `new_message.enabled` is `true`. 56 NewMessageSound *string `json:"NewMessage.Sound,omitempty"` 57 // Whether the new message badge is enabled. The default is `false`. 58 NewMessageBadgeCountEnabled *bool `json:"NewMessage.BadgeCountEnabled,omitempty"` 59 // Whether to send a notification when a participant is added to a conversation. The default is `false`. 60 AddedToConversationEnabled *bool `json:"AddedToConversation.Enabled,omitempty"` 61 // The template to use to create the notification text displayed when a participant is added to a conversation and `added_to_conversation.enabled` is `true`. 62 AddedToConversationTemplate *string `json:"AddedToConversation.Template,omitempty"` 63 // The name of the sound to play when a participant is added to a conversation and `added_to_conversation.enabled` is `true`. 64 AddedToConversationSound *string `json:"AddedToConversation.Sound,omitempty"` 65 // Whether to send a notification to a user when they are removed from a conversation. The default is `false`. 66 RemovedFromConversationEnabled *bool `json:"RemovedFromConversation.Enabled,omitempty"` 67 // The template to use to create the notification text displayed to a user when they are removed from a conversation and `removed_from_conversation.enabled` is `true`. 68 RemovedFromConversationTemplate *string `json:"RemovedFromConversation.Template,omitempty"` 69 // The name of the sound to play to a user when they are removed from a conversation and `removed_from_conversation.enabled` is `true`. 70 RemovedFromConversationSound *string `json:"RemovedFromConversation.Sound,omitempty"` 71 // Whether to send a notification when a new message with media/file attachments is added to a conversation. The default is `false`. 72 NewMessageWithMediaEnabled *bool `json:"NewMessage.WithMedia.Enabled,omitempty"` 73 // The template to use to create the notification text displayed when a new message with media/file attachments is added to a conversation and `new_message.attachments.enabled` is `true`. 74 NewMessageWithMediaTemplate *string `json:"NewMessage.WithMedia.Template,omitempty"` 75 } 76 77 func (params *UpdateServiceNotificationParams) SetLogEnabled(LogEnabled bool) *UpdateServiceNotificationParams { 78 params.LogEnabled = &LogEnabled 79 return params 80 } 81 func (params *UpdateServiceNotificationParams) SetNewMessageEnabled(NewMessageEnabled bool) *UpdateServiceNotificationParams { 82 params.NewMessageEnabled = &NewMessageEnabled 83 return params 84 } 85 func (params *UpdateServiceNotificationParams) SetNewMessageTemplate(NewMessageTemplate string) *UpdateServiceNotificationParams { 86 params.NewMessageTemplate = &NewMessageTemplate 87 return params 88 } 89 func (params *UpdateServiceNotificationParams) SetNewMessageSound(NewMessageSound string) *UpdateServiceNotificationParams { 90 params.NewMessageSound = &NewMessageSound 91 return params 92 } 93 func (params *UpdateServiceNotificationParams) SetNewMessageBadgeCountEnabled(NewMessageBadgeCountEnabled bool) *UpdateServiceNotificationParams { 94 params.NewMessageBadgeCountEnabled = &NewMessageBadgeCountEnabled 95 return params 96 } 97 func (params *UpdateServiceNotificationParams) SetAddedToConversationEnabled(AddedToConversationEnabled bool) *UpdateServiceNotificationParams { 98 params.AddedToConversationEnabled = &AddedToConversationEnabled 99 return params 100 } 101 func (params *UpdateServiceNotificationParams) SetAddedToConversationTemplate(AddedToConversationTemplate string) *UpdateServiceNotificationParams { 102 params.AddedToConversationTemplate = &AddedToConversationTemplate 103 return params 104 } 105 func (params *UpdateServiceNotificationParams) SetAddedToConversationSound(AddedToConversationSound string) *UpdateServiceNotificationParams { 106 params.AddedToConversationSound = &AddedToConversationSound 107 return params 108 } 109 func (params *UpdateServiceNotificationParams) SetRemovedFromConversationEnabled(RemovedFromConversationEnabled bool) *UpdateServiceNotificationParams { 110 params.RemovedFromConversationEnabled = &RemovedFromConversationEnabled 111 return params 112 } 113 func (params *UpdateServiceNotificationParams) SetRemovedFromConversationTemplate(RemovedFromConversationTemplate string) *UpdateServiceNotificationParams { 114 params.RemovedFromConversationTemplate = &RemovedFromConversationTemplate 115 return params 116 } 117 func (params *UpdateServiceNotificationParams) SetRemovedFromConversationSound(RemovedFromConversationSound string) *UpdateServiceNotificationParams { 118 params.RemovedFromConversationSound = &RemovedFromConversationSound 119 return params 120 } 121 func (params *UpdateServiceNotificationParams) SetNewMessageWithMediaEnabled(NewMessageWithMediaEnabled bool) *UpdateServiceNotificationParams { 122 params.NewMessageWithMediaEnabled = &NewMessageWithMediaEnabled 123 return params 124 } 125 func (params *UpdateServiceNotificationParams) SetNewMessageWithMediaTemplate(NewMessageWithMediaTemplate string) *UpdateServiceNotificationParams { 126 params.NewMessageWithMediaTemplate = &NewMessageWithMediaTemplate 127 return params 128 } 129 130 // Update push notification service settings 131 func (c *ApiService) UpdateServiceNotification(ChatServiceSid string, params *UpdateServiceNotificationParams) (*ConversationsV1ServiceNotification, error) { 132 path := "/v1/Services/{ChatServiceSid}/Configuration/Notifications" 133 path = strings.Replace(path, "{"+"ChatServiceSid"+"}", ChatServiceSid, -1) 134 135 data := url.Values{} 136 headers := make(map[string]interface{}) 137 138 if params != nil && params.LogEnabled != nil { 139 data.Set("LogEnabled", fmt.Sprint(*params.LogEnabled)) 140 } 141 if params != nil && params.NewMessageEnabled != nil { 142 data.Set("NewMessage.Enabled", fmt.Sprint(*params.NewMessageEnabled)) 143 } 144 if params != nil && params.NewMessageTemplate != nil { 145 data.Set("NewMessage.Template", *params.NewMessageTemplate) 146 } 147 if params != nil && params.NewMessageSound != nil { 148 data.Set("NewMessage.Sound", *params.NewMessageSound) 149 } 150 if params != nil && params.NewMessageBadgeCountEnabled != nil { 151 data.Set("NewMessage.BadgeCountEnabled", fmt.Sprint(*params.NewMessageBadgeCountEnabled)) 152 } 153 if params != nil && params.AddedToConversationEnabled != nil { 154 data.Set("AddedToConversation.Enabled", fmt.Sprint(*params.AddedToConversationEnabled)) 155 } 156 if params != nil && params.AddedToConversationTemplate != nil { 157 data.Set("AddedToConversation.Template", *params.AddedToConversationTemplate) 158 } 159 if params != nil && params.AddedToConversationSound != nil { 160 data.Set("AddedToConversation.Sound", *params.AddedToConversationSound) 161 } 162 if params != nil && params.RemovedFromConversationEnabled != nil { 163 data.Set("RemovedFromConversation.Enabled", fmt.Sprint(*params.RemovedFromConversationEnabled)) 164 } 165 if params != nil && params.RemovedFromConversationTemplate != nil { 166 data.Set("RemovedFromConversation.Template", *params.RemovedFromConversationTemplate) 167 } 168 if params != nil && params.RemovedFromConversationSound != nil { 169 data.Set("RemovedFromConversation.Sound", *params.RemovedFromConversationSound) 170 } 171 if params != nil && params.NewMessageWithMediaEnabled != nil { 172 data.Set("NewMessage.WithMedia.Enabled", fmt.Sprint(*params.NewMessageWithMediaEnabled)) 173 } 174 if params != nil && params.NewMessageWithMediaTemplate != nil { 175 data.Set("NewMessage.WithMedia.Template", *params.NewMessageWithMediaTemplate) 176 } 177 178 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 179 if err != nil { 180 return nil, err 181 } 182 183 defer resp.Body.Close() 184 185 ps := &ConversationsV1ServiceNotification{} 186 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 187 return nil, err 188 } 189 190 return ps, err 191 }