如果你經(jīng)常接到騷擾電話(huà),我們會(huì )不慌不忙的把它標記并拉入黑名單。
但對于企業(yè)的座機來(lái)說(shuō)卻沒(méi)有黑名單功能,如果你恰好使用了FreeSWITCH作為你們的語(yǔ)音平臺,那么一切就變得簡(jiǎn)單了,我們使用lua就可以實(shí)現一個(gè)這樣的功能,所有來(lái)話(huà)都去查詢(xún)下是不是在黑名單中,最后決定是否去接聽(tīng)。
其實(shí)FreeSWITCH自帶了一個(gè)黑名單的功能,但在這里我還是選擇自己寫(xiě)一個(gè)。
首先大家需要知道hash這個(gè)api,例如,增加一個(gè)值,hash inster/realm/k/v這樣就插入到內存中,k就是hello,v就是hello 刪除一個(gè)值,hash delete/realm/hello
freeswitch@2d57b40823a7> hash insert/realm/hello/world
+OK
freeswitch@2d57b40823a7> hash select/realm/hello
world
freeswitch@2d57b40823a7> hash delete/realm/hello
+OK
freeswitch@2d57b40823a7> hash select/realm/hello
-ERR no reply
有了以上的基礎知識就可以開(kāi)始了。
cidnum = session:getVariable("caller_id_number")
dstnum = session:getVariable("destination_number")
session:execute("digit_action_set_realm", "myrealm")
api = freeswitch.API()
ret = api:execute("hash", "select/realm/blacklist")
if cidnum == ret then
session:hangup()
else
session:execute("set","bridge_pre_execute_bleg_app=bind_digit_action")
session:execute("set","bridge_pre_execute_bleg_data=myrealm,9,api:hash," "insert/realm/blacklist/" cidnum)
session:execute("bridge", "user/" dstnum)
end
首先獲取到來(lái)電號碼,存到cidnum,接著(zhù)獲取被叫號碼,如果獲取到ret與主叫號碼相同,就直接掛機,因為那是黑名單中到號碼。
當你接到騷擾電話(huà)默默的按下9,下次他就不能再來(lái)和你“開(kāi)心”的聊天了。
但是因人而異,不是每一個(gè)電話(huà)都被認為是騷擾電話(huà),所以要做每個(gè)人定義的黑名單。當然也很簡(jiǎn)單,上面的腳本改一下兩個(gè)位置就可以了。
ret = api:execute("hash", "select/realm/" dstnum)
session:execute("set","bridge_pre_execute_bleg_data=myrealm,9,api:hash," "insert/realm/" dstnum "/" cidnum)
針對每一個(gè)dstnum,人手一個(gè)黑名單。A的黑名單并不會(huì )影響到B。
當然這樣也是有風(fēng)險的,比如你不小心把內部號碼加入了黑名單,你還得刪掉他,要不領(lǐng)導接不通你的號碼。
當然也可以連接數據庫,把黑名單號碼寫(xiě)入數據庫,這樣就可以在FreeSWITCH重啟后依舊可以使用。
具體操作可以參考《FreeSWITCH權威指南》417頁(yè)連接數據庫。