FreeSWITCH中文网,电话机器人开发网 ,微信订阅号:

FreeSWITCH及VOIP,Openser,电话机器人等产品中文技术资讯、交流、沟通、培训、咨询、服务一体化网络。QQ群:293697898

如何使用Nway-Power实现语音呼叫机器人


tags:FreeSwitch Nway-Power 语音 机器人 外呼 呼入客服 创建时间:2018-01-15 06:59:04

外呼接口:

Job_uuid 源主叫uuid get_uuid获得

Callernum 主叫号码

Calleenum 机器人路由号码

A_gatewayname 如果a是外线,则要指定a的出局网关

A_effective_caller_id_num a路显示的号码

A_external false,true,标记a是不是外线

Cdr_url 标记推送Cdr至哪个url

Event_url 标记推送来电事件等至哪个url

Record_file 完整通话录音路径

curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32","Callernum":"18621575908", "Calleenum":"2300","A_gatewayname":"nway1","A_effective_caller_id_num":"02168686868", "A_external":"true","Cdr_url":"http://111.1.1.1/fs/cdr","Event_url":"http://111.1.1.1/fs/callstate","Record_file":"mytest.wav"}' -H "Authorization:Nway token" http://127.0.0.1:8085/api/originate_i

处理接口:

func AsrServer(w http.ResponseWriter, req *http.Request) {
    con, _ := ioutil.ReadAll(req.Body)
    if req != nil {
        defer req.Body.Close()
    }
    var dat map[string]interface{}
    err := json.Unmarshal(con, &dat)
    if err == nil {
        if dat["notify"] != nil && dat["calleeid"] != nil && dat["callerid"] != nil && dat["callid"] != nil {
            notify := dat["notify"].(string)
            errorcode := 0
            if dat["errorcode"] != nil {
                errorcode = int(dat["errorcode"].(float64))
            }
            message := ""
            if dat["message"] != nil {
                message = dat["message"].(string)
            }
            prompt := "您好,有什么能帮您的吗?!"
            if notify == "enter" {
                jsonStr := `{"action":"asr","flowdata":"","params":{"prompt":"欢迎致电上海宁卫,请说测试命令,比如查房,退房,清洁,续住,预订,叫餐,退押金,不能上网,人工服务!","max_waiting_ms":5000,"retry":0,"mode":1}}`
                w.Write([]byte(jsonStr))
            } else if notify == "asr_result" {

                if errorcode == 0 {

                    if message == "" {
                        prompt = " 请再说一遍? "
                    } else if strings.Contains(message, "查房") {
                        prompt = "你以为你是警察啊,说查房就查房!"
                    } else if strings.Contains(message, "退房") {
                        prompt = "能不能不退房,我们可是霸王房!"
                    } else if strings.Contains(message, "清洁") {
                        prompt = "用不着清洁吧,我们的房间很干净,请您自己扫扫!"
                    } else if strings.Contains(message, "续住") {
                        prompt = "我们将免费为您续住365天!"
                    } else if strings.Contains(message, "预订") || strings.Contains(message, "订房") {
                        prompt = "请登录http://www.nway.com.cn进行预计!"
                    } else if strings.Contains(message, "叫餐") {
                        prompt = "您是喜欢吃川菜?鲁菜?淮扬菜?湘菜?粤菜?本帮菜?西餐?"
                    } else if strings.Contains(message, "退押金") {
                        prompt = "押金已退回到您手里,请抽空看看手!"
                    } else if strings.Contains(message, "不能上网") {
                        prompt = "不是有4G吗?上网很容易,流量不用愁!"
                    } else if strings.Contains(message, "人工服务") {
                        prompt = "您是找特殊的还是找酒店服务员?"
                    } else if strings.Contains(message, "挂断") || strings.Contains(message, "挂机") {
                        jsonStr := `{"action":"hangup","flowdata":"","params":{"cause":0,"usermsg":"caller request"}}`

                        w.Write([]byte(jsonStr))
                    } else {
                        fmt.Println(message)
                    }
                } else if errorcode == -1 {
                    prompt = "未检测到声音,请说命令!"
                } else if errorcode == -2 {
                    prompt = "创建文件失败请联系管理员!"
                }

                if prompt != "" {
                    jsonStr := `{"action":"asr","params":{"prompt":"` + prompt + `","max_waiting_ms":5000,"retry":0,"mode":0}}`
                    w.Write([]byte(jsonStr))
                }
            }
        }
    } else {
        fmt.Println("unmarshal event message error:", err, "  &&&    message:", string(con))
    }
}


上海老李,QQ:1354608370,FreeSWITCH QQ群: