@@ -2,6 +2,8 @@ package twilio
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
6
+ "time"
5
7
)
6
8
7
9
// CallResource holds the details of a call resouce
@@ -12,8 +14,8 @@ type CallResource struct {
12
14
AnsweredBy string `json:"answered_by,omitempty"`
13
15
APIVersion string `json:"api_version,omitempty"`
14
16
CallerName string `json:"caller_name,omitempty"`
15
- DateCreated string `json:"date_created,omitempty"`
16
- DateUpdated string `json:"date_updated,omitempty"`
17
+ DateCreated TwilioTime `json:"date_created,omitempty"`
18
+ DateUpdated TwilioTime `json:"date_updated,omitempty"`
17
19
Direction string `json:"direction,omitempty"`
18
20
Duration string `json:"duration,omitempty"`
19
21
EndTime string `json:"end_time,omitempty"`
@@ -44,7 +46,7 @@ type SubresourceUris struct {
44
46
Payments string `json:"payments,omitempty"`
45
47
}
46
48
47
- // Call describes a outgoing call settings
49
+ // Call describes outgoing call settings
48
50
type Call struct {
49
51
AccountSid string `url:"AccountSid,omitempty"`
50
52
ApplicationSid string `url:"ApplicationSid,omitempty"`
@@ -81,13 +83,74 @@ type Call struct {
81
83
URL string `url:"Url,omitempty"`
82
84
}
83
85
86
+ // ConferenceResource holds the details of a conference
87
+ type ConferenceResource struct {
88
+ AccountSid string `json:"account_sid,omitempty"`
89
+ DateCreated TwilioTime `json:"date_created,omitempty"`
90
+ DateUpdated TwilioTime `json:"date_updated,omitempty"`
91
+ ApiVersion string `json:"api_version,omitempty"`
92
+ FriendlyName string `json:"friendly_name,omitempty"`
93
+ Region string `json:"region,omitempty"`
94
+ Sid string `json:"sid,omitempty"`
95
+ Status string `json:"status,omitempty"` // init, in-progress, or completed.
96
+ Uri string `json:"uri,omitempty"`
97
+ SubresourceUris map [string ]string `json:"subresource_uris,omitempty"`
98
+ ReasonConferenceEnded string `json:"reason_conference_ended,omitempty"` // conference-ended-via-api, participant-with-end-conference-on-exit-left, participant-with-end-conference-on-exit-kicked, last-participant-kicked, or last-participant-left.
99
+ CallSidEndingConference string `json:"call_sid_ending_conference,omitempty"`
100
+ }
101
+
102
+ // ParticipantResource holds the details of a participant
103
+ type ParticipantResource struct {
104
+ AccountSid string `json:"account_sid,omitempty"`
105
+ CallSid string `json:"call_sid,omitempty"`
106
+ CallSidToCoach string `json:"call_sid_to_coach,omitempty"`
107
+ Coaching bool `json:"coaching,omitempty"`
108
+ ConferenceSid string `json:"conference_sid,omitempty"`
109
+ DateCreated TwilioTime `json:"date_created,omitempty"`
110
+ DateUpdated TwilioTime `json:"date_updated,omitempty"`
111
+ EndConferenceOnExit bool `json:"end_conference_on_exit,omitempty"`
112
+ Muted bool `json:"muted,omitempty"`
113
+ Hold bool `json:"hold,omitempty"`
114
+ StartConferenceOnEnter bool `json:"start_conference_on_enter,omitempty"`
115
+ Status string `json:"status,omitempty"` // queued, connecting, ringing, connected, complete, or failed
116
+ Uri string `json:"uri,omitempty"`
117
+ }
118
+
119
+ // APIError holds the details of errors returned from twilio
84
120
type APIError struct {
85
121
Code int `json:"code"`
86
122
Message string `json:"message"`
87
123
MoreInfo string `json:"more_info"`
88
124
Status int `json:"status"`
89
125
}
90
126
127
+ // Error returns string representation of the error
91
128
func (a * APIError ) Error () string {
92
129
return fmt .Sprintf ("APIError: %s: more_info: %s" , a .Message , a .MoreInfo )
93
130
}
131
+
132
+ // TwilioTime implements interfaces for json Marshalling and Unmarshalling
133
+ type TwilioTime struct {
134
+ time.Time
135
+ }
136
+
137
+ const ttLayout = "Mon, 02 Jan 2006 15:04:05 -0700" // 2006/01/02|15:04:05
138
+
139
+ // UnmarshalJSON implements the Unmarshaler interface
140
+ func (tt * TwilioTime ) UnmarshalJSON (b []byte ) (err error ) {
141
+ s := strings .Trim (string (b ), "\" " )
142
+ if s == "null" {
143
+ tt .Time = time.Time {}
144
+ return
145
+ }
146
+ tt .Time , err = time .Parse (ttLayout , s )
147
+ return
148
+ }
149
+
150
+ // MarshslJSON implements the Marshaler interface
151
+ func (tt * TwilioTime ) MarshalJSON () ([]byte , error ) {
152
+ if tt .Time .IsZero () {
153
+ return []byte ("null" ), nil
154
+ }
155
+ return []byte (fmt .Sprintf ("\" %s\" " , tt .Time .Format (ttLayout ))), nil
156
+ }
0 commit comments