| @ -0,0 +1,58 @@ | |||||
| modparam("htable", "htable", "msg=>size=32;autoexpire=60;") | |||||
| event_route[kazoo:consumer-event-message-route] | |||||
| { | |||||
| $var(uri_username) = ""; | |||||
| kazoo_json($kzE, "Endpoints[0].To-Username", "$var(uri_username)"); | |||||
| $var(x) = $(kzE{kz.json,Endpoints[0].To-Username}); | |||||
| xlog("L_INFO", "received message route for $(kzE{kz.json,Endpoints[0].To-DID})"); | |||||
| if( $var(uri_username) != "" ) { | |||||
| $var(from_uri) = "sip:" + $(kzE{kz.json,Caller-ID-Number}) + "@" + $(kzE{kz.json,Endpoints[0].To-Realm}); | |||||
| $var(to_uri) = "sip:" + $(kzE{kz.json,Endpoints[0].To-Username}) + "@" + $(kzE{kz.json,Endpoints[0].To-Realm}); | |||||
| } else { | |||||
| $var(from_uri) = "sip:" + $(kzE{kz.json,Caller-ID-Number}) + $(kzE{kz.json,Endpoints[0].To-Realm}); | |||||
| $var(to_uri) = $(kzE{kz.json,Endpoints[0].Route}); | |||||
| } | |||||
| $sht(msg=>$(kzE{kz.json,Call-ID})) = $kzE; | |||||
| $uac_req(method)="MESSAGE"; | |||||
| $uac_req(body)= $(kzE{kz.json,Body}); | |||||
| $uac_req(hdrs)="Content-Type: text/plain\r\n"; | |||||
| $uac_req(turi) = $var(to_uri); | |||||
| $uac_req(ruri) = $var(to_uri); | |||||
| $uac_req(furi) = $var(from_uri); | |||||
| $uac_req(ouri) = "sip:MY_IP_ADDRESS:5060"; | |||||
| $uac_req(callid) = $(kzE{kz.json,Call-ID}); | |||||
| xlog("L_INFO", "sending message from $var(from_uri) to $var(to_uri) "); | |||||
| uac_req_send(); | |||||
| } | |||||
| route[MESSAGE_REPLY] | |||||
| { | |||||
| if( $(sht(msg=>$ci)) == $null) { | |||||
| exit(); | |||||
| } | |||||
| if($T_reply_code != 200 && $T_reply_code != 202) { | |||||
| $var(Result) = "Failure"; | |||||
| } else { | |||||
| $var(Result) = "Success"; | |||||
| } | |||||
| $var(Payload) = '{ "Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "' + $(sht(msg=>$ci){kz.json,Call-ID}) + '", "Message-ID" : "' + $(sht(msg=>$ci){kz.json,Message-ID}) +'" , "Delivery-Result-Code" : "sip:" + $T_reply_code + '" , "Msg-ID" : "' + $(sht(msg=>$ci){kz.json,Msg-ID}) + '" , "Status" : "' + $var(Result) + '"}'; | |||||
| $var(RoutingKey) = $(sht(msg=>$ci){kz.json,Server-ID}); | |||||
| $var(exchange) = "targeted"; | |||||
| if($var(RoutingKey) == "") { | |||||
| $var(exchange) = "sms"; | |||||
| $var(RoutingKey) = "message.delivery." + $(sht(msg=>$ci){kz.json,Call-ID}{kz.encode}); | |||||
| } | |||||
| xlog("L_INFO", "sending delivery message for $ci"); | |||||
| kazoo_publish($var(exchange), $var(RoutingKey), $var(Payload)); | |||||
| } | |||||
| # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab | |||||