Skip to content

Commit bfb6199

Browse files
authored
Merge pull request #66 from ali-sattari/grow-1091_create-transcript
GROW 1091: Create Transcript
2 parents f1a991f + c1e8611 commit bfb6199

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

voice/testdata/transcriptObject.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"data": [
3+
{
4+
"id": "00000000-1111-2222-3333-444444444444",
5+
"recordingId": "55555555-6666-7777-8888-999999999999",
6+
"error": null,
7+
"createdAt": "2011-01-01T02:03:04Z",
8+
"updatedAt": "2011-01-02T03:04:05Z"
9+
}
10+
]
11+
}

voice/transcription.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,20 @@ func (trans *Transcription) Contents(client *messagebird.Client) (string, error)
9292
b, err := ioutil.ReadAll(resp.Body)
9393
return string(b), err
9494
}
95+
96+
// CreateTranscription creates a transcription request for an existing recording
97+
func CreateTranscription(client *messagebird.Client, callID string, legID string, recordingID string) (trans *Transcription, err error) {
98+
var body struct{}
99+
path := fmt.Sprintf("/calls/%s/legs/%s/recordings/%s/transcriptions", callID, legID, recordingID)
100+
var resp struct {
101+
Data []Transcription `json:"data"`
102+
}
103+
if err := client.Request(&resp, http.MethodPost, apiRoot+path, body); err != nil {
104+
return nil, err
105+
}
106+
if len(resp.Data) == 0 {
107+
return nil, fmt.Errorf("Empty response")
108+
}
109+
110+
return &resp.Data[0], nil
111+
}

voice/transcription_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package voice
22

33
import (
4+
"fmt"
45
"net/http"
56
"testing"
7+
8+
"github.com/messagebird/go-rest-api/internal/mbtest"
69
)
710

11+
func TestMain(m *testing.M) {
12+
mbtest.EnableServer(m)
13+
}
14+
815
func TestTranscriptionGetContents(t *testing.T) {
916
text := "the quick brown fox jumps over the lazy dog"
1017
mbClient, stop := testRequest(http.StatusOK, []byte(text))
@@ -26,3 +33,16 @@ func TestTranscriptionGetContents(t *testing.T) {
2633
t.Fatalf("mismatched downloaded contents")
2734
}
2835
}
36+
37+
func TestCreateTranscription(t *testing.T) {
38+
mbtest.WillReturnTestdata(t, "transcriptObject.json", http.StatusOK)
39+
client := mbtest.Client(t)
40+
41+
callID, legID, recordingID := "7777777", "88888888", "999999999"
42+
_, err := CreateTranscription(client, callID, legID, recordingID)
43+
if err != nil {
44+
t.Fatal(err)
45+
}
46+
47+
mbtest.AssertEndpointCalled(t, http.MethodPost, fmt.Sprintf("/calls/%s/legs/%s/recordings/%s/transcriptions", callID, legID, recordingID))
48+
}

0 commit comments

Comments
 (0)