从函数返回Twilio Studio时出现Status 400错误求助
问题分析与解决方案
你的问题出在**
修正步骤
1. 修改agent_screen_call函数的action目标
将gather的action指向一个新的Twilio Function(比如handle_agent_selection),而不是直接跳回Studio:
exports.handler = function(context, event, callback) { const twiml = new Twilio.twiml.VoiceResponse(); const gather = twiml.gather({ input: 'dtmf', numDigits: 1, method: 'POST', action: '/handle_agent_selection', actionOnEmptyResult: 'true' }); gather.say("You have a call on the business line!"); gather.say('Press 1 to talk with the caller or 2 to send caller to voicemail or 3 to redirect caller to the National Call Centre'); // 超时无输入的处理 twiml.say("No input received. Redirecting caller to voicemail."); twiml.hangup(); return callback(null, twiml); };
2. 创建handle_agent_selection函数处理坐席按键
这个函数根据坐席按下的数字,生成对应的TwiML指令:
exports.handler = function(context, event, callback) { const twiml = new Twilio.twiml.VoiceResponse(); const digits = event.Digits; switch(digits) { case '1': // 允许通话连接,返回空TwiML即可 break; case '2': // 挂断坐席,将来电者转语音信箱(可跳回Studio对应分支) twiml.say("Sending caller to voicemail."); twiml.redirect({ method: 'POST' }, 'https://webhooks.twilio.com/v1/Accounts/[你的账户SID]/Flows/[你的Flow SID]?FlowEvent=return&action=voicemail'); // 也可以直接生成语音信箱TwiML,无需跳回Studio: // const vm = twiml.record({ maxLength: 30, action: '/save_voicemail', finishOnKey: '#' }); break; case '3': // 挂断坐席,转接到National Call Centre twiml.say("Redirecting caller to the National Call Centre."); twiml.dial('[National Call Centre号码]'); break; default: // 无效按键,重新收集输入 const gather = twiml.gather({ input: 'dtmf', numDigits: 1, method: 'POST', action: '/handle_agent_selection' }); gather.say("Invalid input. Press 1 to talk, 2 for voicemail, or 3 to redirect."); } return callback(null, twiml); };
关键注意点
return (<Dial>的url参数对应的TwiML会话是独立的,所有交互逻辑需要在Function内完成,或通过Redirect指向符合Twilio要求的端点。 )- 如果需要跳回Studio Flow,确保Redirect的URL包含正确的账户SID、Flow SID,并且Flow内有对应的逻辑处理传入的参数(比如
action=voicemail)。 - ErrorCode 11200本质是Twilio无法解析请求的响应,所以务必保证所有Function返回的都是格式正确的TwiML。
内容的提问来源于stack exchange,提问作者G-J
相关产品推荐
相关产品推荐

