-
Notifications
You must be signed in to change notification settings - Fork 5
/
fax_response.go
46 lines (38 loc) · 1.21 KB
/
fax_response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package fax
import (
"encoding/xml"
"github.com/RJPearson94/twilio-sdk-go/twiml/fax/verbs"
"github.com/RJPearson94/twilio-sdk-go/utils"
)
// FaxResponse provides the structure and functions for generation TwiML that can be used
// on Programmable Fax. See https://www.twilio.com/docs/fax/twiml more details
type FaxResponse struct {
XMLName xml.Name `xml:"Response"`
Children []interface{}
}
// New create a new instance of FaxResponse
func New() *FaxResponse {
return &FaxResponse{
Children: make([]interface{}, 0),
}
}
func (m *FaxResponse) ReceiveWithAttributes(attributes verbs.ReceiveAttributes) {
m.Children = append(m.Children, &verbs.Receive{
ReceiveAttributes: attributes,
})
}
func (m *FaxResponse) Reject() {
m.Children = append(m.Children, &verbs.Reject{})
}
// ToTwiML generates the TwiML string or returns an error if the response cannot be marshalled
func (m *FaxResponse) ToTwiML() (*string, error) {
return m.ToString()
}
// ToString generates the TwiML string or returns an error if the response cannot be marshalled
func (m *FaxResponse) ToString() (*string, error) {
output, err := xml.Marshal(m)
if err != nil {
return nil, err
}
return utils.String(xml.Header + string(output)), nil
}