ragged-chat-sdk 1.0.11 → 1.0.12

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.
Files changed (2) hide show
  1. package/index.js +14 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -53,17 +53,27 @@ export function init(config = {}) {
53
53
  // Send message to chatbot
54
54
  async function sendMessage(message) {
55
55
  try {
56
+ // Only send the last 20 messages as history to avoid payload size and validation limits
57
+ const historyToSend = messages.slice(-20);
58
+
56
59
  const response = await fetch(`${API_URL}/chat/${subdomain}`, {
57
60
  method: 'POST',
58
61
  headers: { 'Content-Type': 'application/json' },
59
- body: JSON.stringify({ message, history: messages })
62
+ body: JSON.stringify({ message, history: historyToSend })
60
63
  });
61
64
 
62
65
  const data = await response.json().catch(() => ({ error: 'Unknown Server Error' }));
63
66
 
64
67
  if (!response.ok) {
65
- console.error('[Ragged SDK] Chat Error:', response.status, data.error || response.statusText);
66
- return data.details || data.error || "Sorry, I'm having trouble processing that right now. Please try again later.";
68
+ console.error('[Ragged SDK] Chat Error:', response.status, data.error || data.message || response.statusText);
69
+
70
+ // Handle validation errors specifically to give better feedback
71
+ if (data.errors && Array.isArray(data.errors)) {
72
+ const validationMsg = data.errors.map(err => `${err.path}: ${err.message}`).join(', ');
73
+ return `Validation Error: ${validationMsg}`;
74
+ }
75
+
76
+ return data.details || data.error || data.message || "Sorry, I'm having trouble processing that right now. Please try again later.";
67
77
  }
68
78
 
69
79
  return data.response;
@@ -74,6 +84,7 @@ export function init(config = {}) {
74
84
  }
75
85
 
76
86
 
87
+
77
88
  // Switch between tabs
78
89
  function switchTab(tabId) {
79
90
  activeTab = tabId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ragged-chat-sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Official SDK for integrating Ragged Chatbots into your website.",
5
5
  "type": "module",
6
6
  "main": "index.js",