如何在Nexmo用户验证API中禁用文本转语音功能?
How to Disable Text-to-Speech for Nexmo Verify API
Hey there! To turn off the text-to-speech (TTS) fallback in your Nexmo Verify API request, you just need to specify a workflow ID that limits verification to SMS only. Let's adjust your code to make that happen:
Modified Code
const nexmo = require("./nexmo"); let requestId = null; // Switched to let since we're reassigning this value module.exports = function sendVerificationCode( recipient ) { return new Promise((resolve, reject) => { nexmo.verify.request({ number: recipient, brand: 'Verification', workflow_id: 1 // This forces SMS-only verification, disabling TTS entirely }, function(err, result) { if (err) { return reject(err); // Properly reject the Promise when an error occurs } if (result.status === 0) { requestId = result.request_id; resolve(requestId); // Resolve with the request ID on success } else { reject(new Error(`Verification request failed: ${result.error_text}`)); } }); }); };
Key Changes Explained
workflow_id: 1: This parameter tells the Nexmo Verify API to use the SMS-only workflow. By default, the API might fall back to TTS if SMS delivery hits issues, but setting this ID ensures only SMS is used—completely disabling the text-to-speech mechanism.- Fixed Promise Handling: I updated your Promise logic to properly
resolveon success andrejectwhen errors occur or the request returns a non-zero status code. Your original code wasn't triggering these, which could lead to unhandled Promise states.
Quick Workflow ID Reference (For Future Use)
If you ever need to switch verification methods later, here are the common workflow IDs:
1: SMS only (what you need now)2: TTS only3: SMS first, then TTS after a delay4: TTS first, then SMS after a delay
内容的提问来源于stack exchange,提问作者Caren Divinagracia
相关产品推荐
相关产品推荐

