Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit c67aa16

Browse files
authored
Merge pull request #40 from Millasdur/update/dialog
Update sdk
2 parents 2292965 + 1a13f4b commit c67aa16

File tree

5 files changed

+24
-84
lines changed

5 files changed

+24
-84
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Learn more about:
9090

9191
## License
9292

93-
Copyright (c) [2016] [Recast.AI](https://recast.ai)
93+
Copyright (c) [2018] [Recast.AI](https://recast.ai)
9494

9595
Permission is hereby granted, free of charge, to any person obtaining a copy
9696
of this software and associated documentation files (the "Software"), to deal

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "recastai",
3-
"version": "3.7.0",
3+
"version": "4.0.0",
44
"description": "Recast.AI official SDK in NodeJs",
55
"main": "lib/index.js",
66
"types": "index.d.ts",

spec/test.js

-38
Original file line numberDiff line numberDiff line change
@@ -120,44 +120,6 @@ describe('Client class', () => {
120120
})
121121
})
122122
})
123-
124-
describe('fileRequest', () => {
125-
nock('https://api.recast.ai')
126-
.post('/v2/request')
127-
.once()
128-
.reply(200, json)
129-
130-
nock('https://api.recast.ai')
131-
.post('/v2/request')
132-
.once()
133-
.reply(404, 'invalid parameter')
134-
135-
it('should perform a voice request', function (done) {
136-
this.timeout(15000)
137-
client.request.analyseFile(path.join(__dirname, '/resource/test.wav'))
138-
.then(res => {
139-
assert.equal(res.status, 200)
140-
done()
141-
})
142-
})
143-
144-
it('should return an error on 404', done => {
145-
client.request.analyseFile('spec/resource/test.wav')
146-
.catch(() => {
147-
done()
148-
})
149-
})
150-
151-
it('should throw an error on missing token', (done) => {
152-
const clientWithoutToken = new Client()
153-
clientWithoutToken.request.analyseFile(path.resolve(__dirname, '/resource/test.wav'))
154-
.catch(err => {
155-
expect(err).to.be.an.instanceof(Error)
156-
assert.equal(err.message, 'Parameter token is missing')
157-
done()
158-
})
159-
})
160-
})
161123
})
162124

163125
describe('Response class', () => {

src/apis/build/index.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,55 @@ export default class Build {
1313
this.language = language
1414
}
1515

16-
dialog = (message, options = {}) => {
16+
dialog = (message, options = {}, memory = null, log_level = 'info') => {
1717
const token = options.token || this.token
18+
const proxy = options.proxy
1819
const data = {
1920
message,
2021
conversation_id: options.conversationId,
2122
language: options.language || this.language,
23+
log_level: log_level,
2224
}
25+
if (memory)
26+
data['memory'] = memory
2327

24-
return agent('POST', `${constants.DIALOG_ENDPOINT}/dialog`)
28+
const request = agent('POST', `${constants.DIALOG_ENDPOINT}/dialog`)
2529
.set('Authorization', `Token ${token}`)
26-
.send(data)
27-
.then(res => res.body.results)
30+
if (proxy) { request.proxy(proxy) }
31+
return request.send(data).then(res => res.body.results)
2832
}
2933

3034
getConversation = (user, bot, conversationId, options = {}) => {
3135
const token = options.token || this.token
32-
return agent('GET', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
36+
const proxy = options.proxy
37+
38+
const request = agent('GET', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
3339
.set('Authorization', `Token ${token}`)
34-
.send()
40+
if (proxy) { request.proxy(proxy) }
41+
return request.send()
3542
}
3643

3744
updateConversation = (user, bot, conversationId, data = {}, options = {}) => {
3845
const token = options.token || this.token
46+
const proxy = options.proxy
3947
if (data.memory && data.memory.constructor !== Object) {
4048
return Promise.reject('Invalid memory parameter')
4149
}
4250

43-
return agent('PUT', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
51+
const request = agent('PUT', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
4452
.set('Authorization', `Token ${token}`)
45-
.send(data)
53+
if (proxy) { request.proxy(proxy) }
54+
return request.send(data)
4655
}
4756

4857
deleteConversation = (user, bot, conversationId, options = {}) => {
4958
const token = options.token || this.token
50-
return agent('DELETE', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
59+
const proxy = options.proxy
60+
61+
const request = agent('DELETE', `${constants.DIALOG_ENDPOINT}/users/${user}/bots/${bot}/builders/v1/conversation_states/${conversationId}`)
5162
.set('Authorization', `Token ${token}`)
52-
.send()
63+
if (proxy) { request.proxy(proxy) }
64+
return request.send()
5365
}
5466

5567
}

src/apis/request/index.js

-34
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ export default class Request {
3131
return new Response(res.body.results)
3232
}
3333

34-
/*
35-
* /request (with audio file)
36-
*/
37-
analyseFile = async (file, options = {}) => {
38-
const token = options.token || this.token
39-
const proxy = options.proxy
40-
if (!token) { throw new RecastError('Parameter token is missing') }
41-
42-
const request = agent('POST', constants.REQUEST_ENDPOINT)
43-
.set('Authorization', `Token ${token}`)
44-
if (proxy) { request.proxy(proxy) }
45-
46-
const res = await request.attach('voice', file).send()
47-
return new Response(res.body.results)
48-
}
49-
5034
/*
5135
* /converse
5236
*/
@@ -69,22 +53,4 @@ export default class Request {
6953
return new Conversation({ ...res.body.results, recastToken: this.token })
7054
}
7155

72-
converseFile = async (file, options = {}) => {
73-
const token = options.token || this.token
74-
const proxy = options.proxy
75-
const data = {
76-
language: options.language || this.language,
77-
conversation_token: options.conversationToken,
78-
}
79-
80-
if (!token) { throw new RecastError('Parameter token is missing') }
81-
82-
const request = agent('POST', constants.CONVERSE_ENDPOINT)
83-
.set('Authorization', `Token ${token}`)
84-
if (proxy) { request.proxy(proxy) }
85-
86-
const res = await request.attach('voice', file).send(data)
87-
return new Conversation({ ...res.body.results, recastToken: this.token })
88-
}
89-
9056
}

0 commit comments

Comments
 (0)