Skip to content

Commit 2a34390

Browse files
committed
add conv search sentiment api connect
1 parent a3b64e4 commit 2a34390

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

dist/addsearch-js-client.min.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
const axios = require('axios').default;
44
const apiInstance = axios.create();
55
const statsInstance = axios.create();
6+
const conversationalSearchInteractionsInstance = axios.create();
7+
8+
const RESPONSE_BAD_REQUEST = 400;
9+
const RESPONSE_SERVER_ERROR = 500;
610

711
const setRequestInterceptor = (callback, requestType) => {
812
const axiosInstance = requestType === 'searchApi' ? apiInstance : statsInstance;
@@ -24,5 +28,8 @@ const setRequestInterceptor = (callback, requestType) => {
2428
module.exports = {
2529
apiInstance,
2630
statsInstance,
27-
setRequestInterceptor
31+
conversationalSearchInteractionsInstance,
32+
setRequestInterceptor,
33+
RESPONSE_BAD_REQUEST,
34+
RESPONSE_SERVER_ERROR
2835
};

src/apifetch.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22
require('es6-promise').polyfill();
33
const apiInstance = require('./api').apiInstance;
4+
const RESPONSE_BAD_REQUEST = require('./api').RESPONSE_BAD_REQUEST;
5+
const RESPONSE_SERVER_ERROR = require('./api').RESPONSE_SERVER_ERROR;
46

57
/**
68
* Fetch search results of search suggestions from the Addsearch API
@@ -15,9 +17,6 @@ var executeApiFetch = function (
1517
customFilterObject,
1618
recommendOptions
1719
) {
18-
const RESPONSE_BAD_REQUEST = 400;
19-
const RESPONSE_SERVER_ERROR = 500;
20-
2120
var settingToQueryParam = function (setting, key) {
2221
if (setting || setting === false) {
2322
return '&' + key + '=' + setting;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const RESPONSE_SERVER_ERROR = require('./api').RESPONSE_SERVER_ERROR;
3+
require('es6-promise').polyfill();
4+
5+
const conversationalSearchInteractionsInstance =
6+
require('./api').conversationalSearchInteractionsInstance;
7+
8+
var putSentimentClick = function (apiHostname, sitekey, conversationId, sentimentValue) {
9+
return new Promise((resolve, reject) => {
10+
conversationalSearchInteractionsInstance
11+
.put(`https://${apiHostname}/v2/indices/${sitekey}/conversations/${conversationId}/rating`, {
12+
value: sentimentValue === 'positive' ? 1 : sentimentValue === 'negative' ? -1 : 0
13+
})
14+
.then(function (response) {
15+
if (response.status === 200) {
16+
resolve(true);
17+
} else {
18+
reject({
19+
type: RESPONSE_SERVER_ERROR,
20+
message: 'Unable to put sentiment click value.'
21+
});
22+
}
23+
})
24+
.catch(function (error) {
25+
console.error(error);
26+
reject({
27+
type: RESPONSE_SERVER_ERROR,
28+
message: 'Unable to put sentiment click value.'
29+
});
30+
});
31+
});
32+
};
33+
34+
module.exports = { putSentimentClick };

src/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var executeApiFetch = require('./apifetch');
44
var indexingapi = require('./indexingapi');
55
var sendStats = require('./stats');
6+
var putSentimentClick = require('./conversational-search-interactions-api').putSentimentClick;
7+
68
var Settings = require('./settings');
79
var util = require('./util');
810
var throttle = require('./throttle');
@@ -95,6 +97,27 @@ var client = function (sitekey, privatekey) {
9597
);
9698
};
9799

100+
/**
101+
* Put a sentiment click value to the conversational search interactions API
102+
*
103+
* @param {string} conversationId Argument 1: Conversation ID
104+
* @param {('positive'|'negative'|'neutral')} sentimentValue Argument 2: Sentiment value (positive, negative, neutral)
105+
* @returns {Promise<boolean|Object>} Resolves to true if successful, rejects with an error object if unsuccessful
106+
*/
107+
this.putSentimentClick = function (conversationId, sentimentValue) {
108+
return putSentimentClick(this.apiHostname, this.sitekey, conversationId, sentimentValue);
109+
};
110+
111+
/**
112+
* Post a copy click value to the conversational search interactions API
113+
*
114+
* @param {string} conversationId Argument 1: Conversation ID
115+
* @returns {Promise<boolean|Object>} Resolves to true if successful, rejects with an error object if unsuccessful
116+
*/
117+
this.putCopyClick = function (conversationId) {
118+
return putCopyClick(this.apiHostname, this.sitekey, conversationId);
119+
};
120+
98121
/**
99122
* Fetch search suggestions
100123
*

0 commit comments

Comments
 (0)