Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨🐛 use utterances as top level param #439

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/tone_analyzer.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tone_analyzer.tone({ text: 'Greetings from Watson Developer Cloud!' }, function(
}
});

const utterances = {
const params = {
utterances: [
{ text: 'My charger isn’t working.', user: 'customer' },
{ text: 'Thanks for reaching out. Can you give me some more detail about the issue?', user: 'agent' },
Expand All @@ -29,7 +29,7 @@ const utterances = {
]
};

tone_analyzer.tone_chat({ utterances: utterances }, function(err, tone) {
tone_analyzer.tone_chat(params, function(err, tone) {
if (err) {
console.log(err);
} else {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/test.tone_analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ describe('tone_analyzer_integration', function() {
const mobydick = fs.readFileSync(path.join(__dirname, '../resources/mobydick.txt'), 'utf8');
tone_analyzer.tone({ text: mobydick }, done);
});

it('tone_chat()', function(done) {
const utterances = {
utterances: [
{ text: 'My charger isn’t working.', user: 'customer' },
{ text: 'Thanks for reaching out. Can you give me some more detail about the issue?', user: 'agent' },
{
text: "I put my charger in my phone last night to charge and it isn't working. Which is ridiculous, it's a new charger, I bought it yesterday.",
user: 'customer'
},
{ text: 'I’m sorry you’re having issues with charging. What kind of charger do you have?', user: 'agent' }
]
};
tone_analyzer.tone_chat(utterances, done);
});
});
2 changes: 1 addition & 1 deletion test/unit/test.tone_analyzer.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('tone_analyzer.v3', function() {
tree: {}
};

const expectation = nock(service.url).post('/v3/tone_chat' + '?version=2016-05-19', tone_chat_request.utterances).reply(200, tone_chat_response);
const expectation = nock(service.url).post('/v3/tone_chat' + '?version=2016-05-19', tone_chat_request).reply(200, tone_chat_response);

// run tests
const req = tone_analyzer.tone_chat(tone_chat_request, function(err, res) {
Expand Down
13 changes: 7 additions & 6 deletions tone-analyzer/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,24 @@ ToneAnalyzerV3.prototype.tone = function(params, callback) {

/**
* @param {Object} params The parameters to call the service
* @param {Object} [params.headers] - The header parameters.
* @param {string} [params.headers.accept-language=en] - The desired language of the response.
* @param {string} [params.headers.content-type=application/json] - The content type of the request: application/json (the default).
* @param {string} [params.headers.content-language=en] - The language of the input text for the request: en (English) (the default)
* @param {string} [params.headers.accept=application/json] - The desired content type of the response: application/json (the default)
* @param {string} [params.utterances] - The utterances to analyze. Utterances must be a JSON object.
*
* @param callback The callback.
*/
ToneAnalyzerV3.prototype.tone_chat = function(params, callback) {
// For backward compatibility
if (params && params.utterances && params.utterances.utterances) {
params.utterances = params.utterances.utterances;
}

const parameters = {
requiredParams: ['utterances'],
originalParams: params,
options: {
url: '/v3/tone_chat',
method: 'POST',
body: JSON.stringify(params.utterances)
json: true,
body: pick(params, ['utterances'])
},
defaultOptions: extend(true, this._options, {
headers: {
Expand Down