阿斯特云AI机器人引擎3.0开放平台开发电话营销机器人

2019-04-13 13:16发布

使用阿斯特云的AI机器人引擎编程就简单多了,只写几个函数就可以完成复杂的语音人机交互。呼叫过程就不写了具体最新文档请阅读open.astyun.com 网站的开发文档。阿斯特云通讯平台推送我们的应用服务器处理服务模块代码:
推送格式://url示例:http://localhost/?startservice&appid=qw $ref=$_SERVER['REQUEST_URI'] ; //云通讯回调请求页面的URI if(strpos($ref,'startservice')){//云通讯IVR启动业务的回调请求
    startservice();
}elseif(strpos($ref,'stopservice')){//云通讯IVR结束业务的回调请求
    stopservice();
}elseif(strpos($ref,'enterflow')){  //启动业务进入流程
enterflow(); }elseif(strpos($ref,'fangchanmain')){ //房产电话营销流程和AI交互和ASR交互 fangchanmain(); }//IVR启动业务,在IVR呼入或者IVR外呼后由云通讯平台发起的回调请求
function startservice()
{
   //获取参数
    $appid = $_REQUEST['appid']; //应用id
    $callid = $_REQUEST['callid'];//通话id,由云通讯平台产生的一路通话的唯一标识
    $from = $_REQUEST['from'];//主叫号码,当IVR呼入方式为主叫的号码,当IVR外呼的方式则为空
    $to = $_REQUEST['to'];//被叫号码,当IVR呼入方式为IVR接入号,当IVR外呼的方式则为外呼的号码
    $direction = $_REQUEST['direction']; //呼叫方式,IVR呼入为0,IVR外呼为1
    $userdata = $_REQUEST['userdata']; //自定义参数,只有发起当外呼请求中带有才会返回
      enterflow();}//IVR结束业务,在用户挂机后由云通讯平台发起的回调请求
function stopservice()
{
//获取参数
    $appid = $_REQUEST['appid'];//应用id
    $callid = $_REQUEST['callid'];//通话id,由云通讯平台产生的一路通话的唯一标识
    $starttime = $_REQUEST['starttime']; //主叫通话的开始时间
    $endtime = $_REQUEST['endtime']; //主叫通话的结束时间
    $callduration = $_REQUEST['callduration'];//主叫通话时长
    $sstime = $_REQUEST['sstime']; //被叫通话的开始时间
    $setime = $_REQUEST['setime']; //被叫通话的结束时间
    $seccallduration = $_REQUEST['seccallduration']; //被叫通话时间
    $recordurl = $_REQUEST['recordurl']; //录音文件下载地址
    $recordid = $_REQUEST['recordid']; //录音文件Id
    $errorcode = $_REQUEST['errorcode']; //通话中异常的错误值
    //对云通讯平台回调请求的响应包体,因为不需要后续流程响应空命令
    echo "
   
   
   
";
}
//通过ai引擎3.0的 api 接口把用户说的话提交给机器人,返回结果指令//$userId 用户号码 $userInput 用户输入 $aimibot 机器人引擎脚本名称function get_ai($userId,$userInput,$aimibot) {
$url="http://demo.astgo.net/ai/api.php?requestType=talk&userId=$userId&userInput=$userInput&aimibot=$aimibot";  
     $restext = file_get_contents($url);  
     return  $restext; 
 }#房产流程
 function fangchanmain()
 {
$callid = $_REQUEST['callid'];
$message = $_REQUEST['asr_text'];
$asr_recordfile = $_REQUEST['asr_recordfile'];
$arr = explode(";",$message);
$userInput="";
foreach($arr as $val){
$userInput .= substr(strstr($val,"."),1);
}  

$data = get_ai($callid,$userInput,'rongsheng');
$arrdata = json_decode($data,true);
$asttext = $arrdata['message'];
$asttext = iconv("UTF-8", "GBK//IGNORE", $asttext);
echo "

   enterflow       
";   }
 #主流程
 
  function enterflow()
 {
$maintext = "欢迎进入阿斯特语音AI演示系统,请说 房产进入流程";
$maintext = iconv("UTF-8", "GBK//IGNORE", $maintext);
echo "
 
   enterflow
";
   
 }