Skip to content

Commit 9e37501

Browse files
committed
fixed transcription object. fixed callflow record step object
1 parent 6215e0d commit 9e37501

File tree

4 files changed

+71
-16
lines changed

4 files changed

+71
-16
lines changed

voice/callflow.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ type CallFlowRecordStep struct {
434434
// Values allowed are: "any", "#", "*", "none" (default).
435435
FinishOnKey string
436436

437+
//If you want to have a transcription of a recording, after the recording has finished.
438+
// It is used when steps[].action is record and it is optional with the default value being false.
439+
Transcribe bool
440+
437441
// Set this to get a transcription of a recording in the specified language
438442
// after the recording has finished.
439443
//
@@ -448,6 +452,7 @@ type jsonCallFlowRecordStep struct {
448452
MaxLength int `json:"maxLength"`
449453
Timeout int `json:"timeout"`
450454
FinishOnKey string `json:"finishOnKey"`
455+
Transcribe bool `json:"transcribe"`
451456
TranscribeLanguage string `json:"transcribeLanguage"`
452457
} `json:"options"`
453458
}
@@ -457,9 +462,10 @@ func (step *CallFlowRecordStep) MarshalJSON() ([]byte, error) {
457462
data := jsonCallFlowRecordStep{}
458463
data.CallFlowStepBase = step.CallFlowStepBase
459464
data.Action = "record"
460-
data.Options.MaxLength = int(step.MaxLength / time.Second)
461-
data.Options.Timeout = int(step.Timeout / time.Second)
465+
data.Options.MaxLength = int(step.MaxLength.Nanoseconds())
466+
data.Options.Timeout = int(step.Timeout.Nanoseconds())
462467
data.Options.FinishOnKey = step.FinishOnKey
468+
data.Options.Transcribe = step.Transcribe
463469
data.Options.TranscribeLanguage = step.TranscribeLanguage
464470
return json.Marshal(data)
465471
}
@@ -472,9 +478,10 @@ func (step *CallFlowRecordStep) UnmarshalJSON(data []byte) error {
472478
}
473479
*step = CallFlowRecordStep{
474480
CallFlowStepBase: raw.CallFlowStepBase,
475-
MaxLength: time.Duration(raw.Options.MaxLength) * time.Second,
476-
Timeout: time.Duration(raw.Options.Timeout) * time.Second,
481+
MaxLength: time.Duration(raw.Options.MaxLength),
482+
Timeout: time.Duration(raw.Options.Timeout),
477483
FinishOnKey: raw.Options.FinishOnKey,
484+
Transcribe: raw.Options.Transcribe,
478485
TranscribeLanguage: raw.Options.TranscribeLanguage,
479486
}
480487
return nil

voice/callflow_test.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ func ExampleCallFlow() {
2222
&CallFlowTransferStep{
2323
Destination: "31600000000",
2424
},
25+
&CallFlowRecordStep{
26+
CallFlowStepBase: CallFlowStepBase{},
27+
MaxLength: 10,
28+
Timeout: 5,
29+
FinishOnKey: "#",
30+
Transcribe: true,
31+
TranscribeLanguage: "en-US",
32+
},
2533
},
2634
}
2735
_ = callflow
@@ -48,6 +56,16 @@ func TestCallFlowJSONMarshal(t *testing.T) {
4856
},
4957
Length: time.Second * 10,
5058
},
59+
&CallFlowRecordStep{
60+
CallFlowStepBase: CallFlowStepBase{
61+
ID: "3",
62+
},
63+
MaxLength: 10,
64+
Timeout: 5,
65+
FinishOnKey: "#",
66+
Transcribe: true,
67+
TranscribeLanguage: "en-US",
68+
},
5169
},
5270
CreatedAt: refCreatedAt,
5371
UpdatedAt: refUpdatedAt,
@@ -88,6 +106,17 @@ func TestCallFlowJSONUnmarshal(t *testing.T) {
88106
"options": {
89107
"length": 10
90108
}
109+
},
110+
{
111+
"id": "3",
112+
"action": "record",
113+
"options": {
114+
"maxLength": 10,
115+
"timeout": 5,
116+
"finishOnKey": "#",
117+
"transcribe": true,
118+
"transcribeLanguage": "en-US"
119+
}
91120
}
92121
],
93122
"createdAt": "2018-01-29T13:46:06Z",
@@ -113,6 +142,16 @@ func TestCallFlowJSONUnmarshal(t *testing.T) {
113142
},
114143
Length: time.Second * 10,
115144
},
145+
&CallFlowRecordStep{
146+
CallFlowStepBase: CallFlowStepBase{
147+
ID: "3",
148+
},
149+
MaxLength: 10,
150+
Timeout: 5,
151+
FinishOnKey: "#",
152+
Transcribe: true,
153+
TranscribeLanguage: "en-US",
154+
},
116155
},
117156
CreatedAt: refCreatedAt,
118157
UpdatedAt: refUpdatedAt,
@@ -146,6 +185,16 @@ func TestCreateCallFlow(t *testing.T) {
146185
&CallFlowPauseStep{
147186
Length: time.Second,
148187
},
188+
&CallFlowRecordStep{
189+
CallFlowStepBase: CallFlowStepBase{
190+
ID: "3",
191+
},
192+
MaxLength: 10,
193+
Timeout: 5,
194+
FinishOnKey: "#",
195+
Transcribe: true,
196+
TranscribeLanguage: "en-US",
197+
},
149198
},
150199
}
151200
if err := newCf.Create(mbClient); err != nil {
@@ -154,8 +203,8 @@ func TestCreateCallFlow(t *testing.T) {
154203
if newCf.Title != "the-title" {
155204
t.Fatalf("Unexpected Title: %q", newCf.Title)
156205
}
157-
if len(newCf.Steps) != 2 {
158-
t.Fatalf("Unexpected Title: %q", newCf.Title)
206+
if len(newCf.Steps) != 3 {
207+
t.Fatalf("Unexpected number of steps: %q", len(newCf.Steps))
159208
}
160209
}
161210

voice/recording.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func (rec *Recording) UnmarshalJSON(data []byte) error {
9494
}
9595

9696
// Transcriptions returns a paginator for retrieving all Transcription objects.
97-
func (rec *Recording) Transcriptions(client *messagebird.Client) *Paginator {
98-
path := rec.links["self"] + "/transcriptions"
97+
func (rec *Recording) Transcriptions(client *messagebird.Client, callID string) *Paginator {
98+
path := apiRoot+rec.links["self"]+"/transcriptions"
9999
return newPaginator(client, path, reflect.TypeOf(Transcription{}))
100100
}
101101

voice/transcription.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ type Transcription struct {
2020
ID string
2121
// The ID of the recording that the transcription belongs to.
2222
RecordingID string
23-
// In case that an error was occurred while executing the transcription
24-
// request, it appears here.
25-
Error string
23+
// The status of the transcription. Possible values: created, transcribing, done, failed.
24+
Status string
2625
// The date-time the transcription was created/requested.
2726
CreatedAt time.Time
2827
// The date-time the transcription was last updated.
@@ -37,7 +36,7 @@ type Transcription struct {
3736
type jsonTranscription struct {
3837
ID string `json:"id"`
3938
RecordingID string `json:"recordingID"`
40-
Error string `json:"error"`
39+
Status string `json:"status"`
4140
CreatedAt string `json:"createdAt"`
4241
UpdatedAt string `json:"updatedAt"`
4342
Links map[string]string `json:"_links"`
@@ -51,16 +50,16 @@ func (trans *Transcription) UnmarshalJSON(data []byte) error {
5150
}
5251
createdAt, err := time.Parse(time.RFC3339, raw.CreatedAt)
5352
if err != nil {
54-
return fmt.Errorf("unable to parse Recording CreatedAt: %v", err)
53+
return fmt.Errorf("unable to parse Transcription CreatedAt: %v", err)
5554
}
5655
updatedAt, err := time.Parse(time.RFC3339, raw.UpdatedAt)
5756
if err != nil {
58-
return fmt.Errorf("unable to parse Recording UpdatedAt: %v", err)
57+
return fmt.Errorf("unable to parse Transcription UpdatedAt: %v", err)
5958
}
6059
*trans = Transcription{
6160
ID: raw.ID,
6261
RecordingID: raw.RecordingID,
63-
Error: raw.Error,
62+
Status: raw.Status,
6463
CreatedAt: createdAt,
6564
UpdatedAt: updatedAt,
6665
links: raw.Links,
@@ -104,7 +103,7 @@ func CreateTranscription(client *messagebird.Client, callID string, legID string
104103
return nil, err
105104
}
106105
if len(resp.Data) == 0 {
107-
return nil, fmt.Errorf("Empty response")
106+
return nil, fmt.Errorf("empty response")
108107
}
109108

110109
return &resp.Data[0], nil

0 commit comments

Comments
 (0)