You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从函数返回Twilio Studio时出现Status 400错误求助

问题分析与解决方案

你的问题出在**组件的url参数上下文里,不能直接将gather的action指向Studio Flow的return URL**。Twilio的在使用url参数时,这个URL返回的TwiML是用于处理坐席端的交互,此时Twilio处于Dial会话中,期望接收的是符合Dial子TwiML规则的响应,而不是直接跳回Studio Flow的请求——后者的请求格式不符合Studio的要求,导致HTTP 400错误(ErrorCode 11200)。

修正步骤

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 23:05:02