github.com/twilio/twilio-go@v1.20.1/rest/flex/v1/interactions.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Flex 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 // Optional parameters for the method 'CreateInteraction' 24 type CreateInteractionParams struct { 25 // The Interaction's channel. 26 Channel *interface{} `json:"Channel,omitempty"` 27 // The Interaction's routing logic. 28 Routing *interface{} `json:"Routing,omitempty"` 29 // The Interaction context sid is used for adding a context lookup sid 30 InteractionContextSid *string `json:"InteractionContextSid,omitempty"` 31 } 32 33 func (params *CreateInteractionParams) SetChannel(Channel interface{}) *CreateInteractionParams { 34 params.Channel = &Channel 35 return params 36 } 37 func (params *CreateInteractionParams) SetRouting(Routing interface{}) *CreateInteractionParams { 38 params.Routing = &Routing 39 return params 40 } 41 func (params *CreateInteractionParams) SetInteractionContextSid(InteractionContextSid string) *CreateInteractionParams { 42 params.InteractionContextSid = &InteractionContextSid 43 return params 44 } 45 46 // Create a new Interaction. 47 func (c *ApiService) CreateInteraction(params *CreateInteractionParams) (*FlexV1Interaction, error) { 48 path := "/v1/Interactions" 49 50 data := url.Values{} 51 headers := make(map[string]interface{}) 52 53 if params != nil && params.Channel != nil { 54 v, err := json.Marshal(params.Channel) 55 56 if err != nil { 57 return nil, err 58 } 59 60 data.Set("Channel", string(v)) 61 } 62 if params != nil && params.Routing != nil { 63 v, err := json.Marshal(params.Routing) 64 65 if err != nil { 66 return nil, err 67 } 68 69 data.Set("Routing", string(v)) 70 } 71 if params != nil && params.InteractionContextSid != nil { 72 data.Set("InteractionContextSid", *params.InteractionContextSid) 73 } 74 75 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 76 if err != nil { 77 return nil, err 78 } 79 80 defer resp.Body.Close() 81 82 ps := &FlexV1Interaction{} 83 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 84 return nil, err 85 } 86 87 return ps, err 88 } 89 90 // 91 func (c *ApiService) FetchInteraction(Sid string) (*FlexV1Interaction, error) { 92 path := "/v1/Interactions/{Sid}" 93 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 94 95 data := url.Values{} 96 headers := make(map[string]interface{}) 97 98 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 99 if err != nil { 100 return nil, err 101 } 102 103 defer resp.Body.Close() 104 105 ps := &FlexV1Interaction{} 106 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 107 return nil, err 108 } 109 110 return ps, err 111 }