quickblox 2.17.0-beta.1 → 2.17.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,6 @@ function AIProxy(service) {
12
12
  * @namespace QB.ai
13
13
  **/
14
14
  AIProxy.prototype = {
15
-
16
15
  /**
17
16
  * Provides answer assistant functionality that helps users effortlessly send various answers considering({@link https://docs.quickblox.com/docs/js-sdk-ai-features#ai-assist-answer read more}).
18
17
  * @memberof QB.ai
@@ -24,8 +23,8 @@ AIProxy.prototype = {
24
23
  * var history = [
25
24
  * {role: "user", message: "Hello"},
26
25
  * {role: "assistant", message: "Hi"}
27
- * ];
28
- * var messageToAssist = 'Where is my order?';
26
+ * ];
27
+ * var messageToAssist = 'Where is my order?';
29
28
  * QB.ai.answerAssist(smartChatAssistantId, messageToAssist, history, callback);
30
29
  * // or third parameters can be null
31
30
  * QB.ai.answerAssist(smartChatAssistantId, messageToAssist, null, callback);
@@ -38,61 +37,36 @@ AIProxy.prototype = {
38
37
  * @param {String} [response.answer] - assist answer for message
39
38
  * @callback answerAssistCallback
40
39
  * */
40
+ if (!callback || typeof callback !== 'function') {
41
+ throw new Error('Callback function is required and must be a function');
42
+ }
41
43
  function validateHistory(history) {
42
44
  var AIRole = {
43
45
  user: 'user',
44
46
  assistant: 'assistant'
45
47
  };
46
- // throw new Error('The QB.addressbook.get accept callback function is required.');
47
- // isArray, isCallback
48
48
  if (history !== null && history !== undefined) {
49
49
  if (!Array.isArray(history)) {
50
- Utils.safeCallbackCall(callback, {
51
- code: 400,
52
- message: 'History must be an array'
53
- });
54
- return false;
50
+ throw new Error('History must be an array');
55
51
  }
56
-
57
52
  for (var i = 0; i < history.length; i++) {
58
53
  var item = history[i];
59
54
  if (typeof item !== 'object' || item === null || Array.isArray(item)) {
60
- Utils.safeCallbackCall(callback, {
61
- code: 400,
62
- message: 'Each element of history must be an object'
63
- });
64
- return false;
55
+ throw new Error('Each element of history must be an object');
65
56
  }
66
-
67
57
  if (!('role' in item) || !('message' in item)) {
68
- Utils.safeCallbackCall(callback, {
69
- code: 400,
70
- message: 'Each element of history must have an role and message fields'
71
- });
72
- return false;
58
+ throw new Error('Each element of history must have an role and message fields');
73
59
  }
74
-
75
60
  if (!(item.role === AIRole.user || item.role === AIRole.assistant)) {
76
- Utils.safeCallbackCall(callback, {
77
- code: 400,
78
- message: 'Invalid role in history item'
79
- });
80
- return false;
61
+ throw new Error('Invalid role in history item');
81
62
  }
82
-
83
63
  if (typeof item.message !== 'string') {
84
- Utils.safeCallbackCall(callback, {
85
- code: 400,
86
- message: 'Message of history item must be a string'
87
- });
88
- return false;
64
+ throw new Error('Message of history item must be a string');
89
65
  }
90
66
  }
91
67
  }
92
-
93
68
  return true;
94
69
  }
95
-
96
70
  if (!validateHistory(history)) {
97
71
  return;
98
72
  }
@@ -120,10 +94,11 @@ AIProxy.prototype = {
120
94
  * @memberof QB.ai
121
95
  * @param {String} smartChatAssistantId - Smart Chat Assistant id.
122
96
  * @param {String} text - Text to translate.
123
- * @param {String} languageCode - Translation language code.
97
+ * @param {String} languageCode - Translation language code. All list see on page: {@link https://docs.quickblox.com/docs/js-sdk-ai-features#ai-translate }
124
98
  * @param {translateCallback} callback - The callback function.
99
+ *
125
100
  * */
126
- //should add validation for callback as answerAssist + list of codes
101
+
127
102
  translate: function(smartChatAssistantId, text, languageCode, callback) {
128
103
  /**
129
104
  * Callback for QB.ai.translate().
@@ -131,7 +106,14 @@ AIProxy.prototype = {
131
106
  * @param {Object} response - The server response object.
132
107
  * @param {String} [response.answer] - translated message
133
108
  * @callback translateCallback
109
+ * @example
110
+ * var textToTranslate = 'Hola!';
111
+ * var languageCode = 'en';
112
+ * QB.ai.translate(smartChatAssistantId, textToTranslate, languageCode, callback);
134
113
  * */
114
+ if (!callback || typeof callback !== 'function') {
115
+ throw new Error('Callback function is required and must be a function');
116
+ }
135
117
  var data = {
136
118
  smart_chat_assistant_id: smartChatAssistantId,
137
119
  text: text,