使用Africans Talking SDK Laravel开发呼叫中心时getDigits报错:数组转字符串转换
解决Africans Talking PHP Laravel SDK中getDigits方法的"Array to string conversion"错误
错误原因
你调用getDigits()方法时参数传递不符合SDK要求:该方法第一个参数需要是提示音字符串(支持文本内容或音频文件URL),第二个参数才是配置选项数组。而你直接将配置数组传给了第一个参数,导致SDK尝试将数组转换为字符串时抛出错误。
修正方案
调整getDigits()的参数顺序,先传递提示音(如果已通过play()播放过提示音,可传空字符串),再传递配置选项数组。同时修复代码中URL的格式错误(缺少斜杠):
$welcome = 'https://call_center2/welcome_note.mp3'; $categoryselect = 'https://call_center2/helpcategoryselect.mp3'; // 补全https:// $noresponse = 'https://call_center2/noresponse.mp3'; $callbackurl = 'https://api/call_center/helpcategory/'.$user->id; // 补全https:// $options = [ 'numDigits' => 2, 'timeout' => 45, 'finishOnKey' => '#', 'callbackUrl' => $callbackurl, ]; $voiceActions = $this->voice->messageBuilder(); $xmlresponse = $voiceActions->play($welcome) ->play($categoryselect) ->getDigits('', $options) // 第一个参数传空字符串,第二个传配置数组 ->play($noresponse) ->build(); return $xmlresponse;
补充说明
如果希望通过getDigits()直接指定提示音(无需提前用play()播放),可以将音频URL或文本作为第一个参数传入:
// 用音频URL作为提示音 ->getDigits($categoryselect, $options) // 用文本作为提示音(SDK会自动转为语音播报) ->getDigits('请选择您需要的帮助类别,按#号结束', $options)
内容的提问来源于stack exchange,提问作者Regan Manzi
相关产品推荐
相关产品推荐

