Esempio n. 1
0
func printChannelAnswer(eventStr string) {
	// Format the event from string into Go's map type
	// 应答时的几种状况
	eventMap := fsock.FSEventStrToMap(eventStr, []string{})
	uuid := eventMap["Channel-Call-UUID"]
	caller := eventMap["Caller-Caller-ID-Number"]
	cname := eventMap["Caller-Caller-ID-Name"]
	destination := eventMap["Caller-Destination-Number"]
	direction := eventMap["variable_direction"]
	// callee := eventMap["Caller-Callee-ID-Number"]
	if len(cname) == 4 && len(destination) > 7 && direction == "inbound" {
		// if callee == "" {
		//	callee = destination
		// }
		fmt.Println("Channel-Call-UUID:" + uuid)
		fmt.Println(caller + " --> " + destination + " answered")
		fmt.Println("answered")
		// fmt.Printf("%v", eventMap)

		anwser := time.Now().Format("2006-01-02 15:04:05")
		// var cuuid int
		// db.QueryRow("select count(id) from haosoo_call where uuid=? ", uuid).Scan(&cuuid)

		stmt, err := db.Prepare("update haosoo_call set answer_stamp=? where uuid=?")
		if err != nil {
			log.Fatal(err)
		}
		res, err := stmt.Exec(anwser, uuid)
		if err != nil {
			log.Fatal(err)
		}
		lastId, err := res.LastInsertId()
		if err != nil {
			log.Fatal(err)
		}
		rowCnt, err := res.RowsAffected()
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("ID = %d, affected = %d\n", lastId, rowCnt)

		c := pool.Get()
		// 连接完关闭,其实没有关闭,是放回池里,也就是队列里面,等待下一个重用
		defer c.Close()
		redis.Bool(c.Do("PUBLISH", fmt.Sprintf("channel:%s", cname), "anwsered"))

	}
}
Esempio n. 2
0
func printChannelHungup(eventStr string) {
	// Format the event from string into Go's map type
	eventMap := fsock.FSEventStrToMap(eventStr, []string{})
	caller := eventMap["Caller-Caller-ID-Number"]
	uuid := eventMap["Channel-Call-UUID"]
	cname := eventMap["Caller-Caller-ID-Name"]
	// destination := eventMap["Caller-Destination-Number"]
	callee := eventMap["Caller-Callee-ID-Number"]
	direction := eventMap["variable_direction"]
	if len(cname) == 4 && direction == "inbound" {
		fmt.Println("Channel-Call-UUID:" + uuid)
		fmt.Println(caller + " --> " + callee + " hangup")
		fmt.Println(" hungup ")

		end := time.Now().Format("2006-01-02 15:04:05")
		year := time.Now().Format("2006")
		month := time.Now().Format("01")
		day := time.Now().Format("02")
		stmt, err := db.Prepare("update haosoo_call set end_stamp=?, billsec=TIMESTAMPDIFF(SECOND,answer_stamp,end_stamp), url= CONCAT('http://rec.haosoo.cn/static/rec2/',?,'/',?,'/',?,'/',?,'_',destination_number,'_',uuid,'.wav' ) where answer_stamp is not null and uuid=?")
		if err != nil {
			log.Fatal(err)
		}
		res, err := stmt.Exec(end, year, month, day, caller, uuid)
		if err != nil {
			log.Fatal(err)
		}
		lastId, err := res.LastInsertId()
		if err != nil {
			log.Fatal(err)
		}
		rowCnt, err := res.RowsAffected()
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("ID = %d, affected = %d\n", lastId, rowCnt)

		c := pool.Get()
		// 连接完关闭,其实没有关闭,是放回池里,也就是队列里面,等待下一个重用
		defer c.Close()
		redis.Bool(c.Do("PUBLISH", fmt.Sprintf("channel:%s", cname), "hangup"))
	}

	// fmt.Printf("%v", eventMap)
}
Esempio n. 3
0
// Formats the event as map and prints it out
func printChannelCreate(eventStr string) {
	// Format the event from string into Go's map type
	eventMap := fsock.FSEventStrToMap(eventStr, []string{})
	uuid := eventMap["Channel-Call-UUID"]
	caller := eventMap["Caller-Caller-ID-Number"] // 主叫号码,内部固话号码 office_number
	cname := eventMap["Caller-Caller-ID-Name"]
	destination := eventMap["Caller-Destination-Number"]
	// user := eventMap["Caller-Username"]
	direction := eventMap["variable_direction"]
	// callee := eventMap["Caller-Callee-ID-Number"]
	// 发起呼叫时的几种状况。 (呼入:转发,总台,分机,二次呼叫。 呼出:销售(提示客户,非提示客户),客服(客户评价),其他部门)
	if len(cname) == 4 && direction == "inbound" { //外呼
		fmt.Println("Channel-Call-UUID:" + uuid)
		fmt.Println(cname + " / " + caller + " --> " + destination)
		// fmt.Println("Caller-Caller-ID-Number:" + caller)
		fmt.Println("created ")
		start := time.Now().Format("2006-01-02 15:04:05")

		stmt, err := db.Prepare("INSERT INTO haosoo_call(subnum,caller_id_number,destination_number,start_stamp,uuid) VALUES(?,?,?,?,?)")
		if err != nil {
			log.Fatal(err)
		}
		res, err := stmt.Exec(cname, caller, destination, start, uuid)
		if err != nil {
			log.Fatal(err)
		}
		lastId, err := res.LastInsertId()
		if err != nil {
			log.Fatal(err)
		}
		rowCnt, err := res.RowsAffected()
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("ID = %d, affected = %d\n", lastId, rowCnt)

		c := pool.Get()
		// 连接完关闭,其实没有关闭,是放回池里,也就是队列里面,等待下一个重用
		defer c.Close()
		ring := fmt.Sprintf("ring:out,%s,%s,%s", caller, destination, uuid)
		redis.Bool(c.Do("PUBLISH", fmt.Sprintf("channel:%s", cname), ring))
	}
}
Esempio n. 4
0
// Loads the new event data from a body of text containing the key value proprieties.
// It stores the parsed proprieties in the internal map.
func (fsev FSEvent) AsEvent(body string) engine.Event {
	fsev = fsock.FSEventStrToMap(body, nil)
	return fsev
}
Esempio n. 5
0
// Loads the new event data from a body of text containing the key value proprieties.
// It stores the parsed proprieties in the internal map.
func (fsev FSEvent) New(body string) Event {
	fsev = fsock.FSEventStrToMap(body, nil)
	return fsev
}