Use stored OpenAI key for translations
This commit is contained in:
@@ -781,7 +781,7 @@ async function translateStoredMessage(conversationId, messageId, senderType, bod
|
||||
const conversation = findConversationById(conversationId);
|
||||
const settings = getTranslationSettings();
|
||||
if (!settings.enabled) return markMessageTranslation(messageId, null, null, null, "disabled");
|
||||
if (!OPENAI_API_KEY) return markMessageTranslation(messageId, null, null, null, "missing_key");
|
||||
if (!settings.openaiApiKey) return markMessageTranslation(messageId, null, null, null, "missing_key");
|
||||
|
||||
const targetLanguage = senderType === "visitor"
|
||||
? settings.operatorLanguage
|
||||
@@ -844,7 +844,10 @@ async function translateText(text, targetLanguage, model, apiKey) {
|
||||
]
|
||||
})
|
||||
});
|
||||
if (!response.ok) throw new Error(`OpenAI HTTP ${response.status}`);
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.text().catch(() => "");
|
||||
throw new Error(`OpenAI HTTP ${response.status}${errorBody ? `: ${errorBody.slice(0, 300)}` : ""}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return parseTranslationJson(outputTextFromResponse(data));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user