Browse Source

message role changes for im services

master
lazedo 6 years ago
parent
commit
0316ef4fda
1 changed files with 18 additions and 23 deletions
  1. +18
    -23
      kamailio/message-role.cfg

+ 18
- 23
kamailio/message-role.cfg View File

@ -24,11 +24,12 @@ route[HANDLE_MESSAGE]
route[MESSAGE_INBOUND] route[MESSAGE_INBOUND]
{ {
$var(key) = "kamailio@MY_HOSTNAME";
route(AUTH_HEADERS_JSON); route(AUTH_HEADERS_JSON);
$var(Payload) = $_s({"Event-Category" : "message", "Event-Name" : "inbound", "Call-ID" : "$ci", "Message-ID" : "$ci", "Route-Type" : "onnet", "Route-ID" : "sip", "From" : "$fU@$fd", "To" : "$tU@$td", "Request" : "$rU@$rd", "Caller-ID-Number" : "$fU", "Callee-ID-Number" : "$tU", "Body" : "$rb", "Custom-SIP-Headers" : $var(headers_json), "Msg-ID" : "$uuid(g)"});
$var(Payload) = $_s({"Event-Category" : "sms", "Event-Name" : "inbound", "Call-ID" : "$ci", "Message-ID" : "$ci", "Route-Type" : "onnet", "Route-ID" : "$(var(key){kz.encode})", "From" : "$fU", "To" : "$tU", "Body" : "$rb", "Custom-SIP-Headers" : $var(headers_json), "Msg-ID" : "$uuid(g)"});
$var(exchange) = "sms";
$var(RoutingKey) = $_s(message.inbound.sip.$(ci{kz.encode}));
$var(exchange) = "im";
$var(RoutingKey) = $_s(sms.inbound.onnet.$(ci{kz.encode}));
xlog("L_INFO", "$ci|msg|sending inbound message $var(RoutingKey) => $var(Payload)\n"); xlog("L_INFO", "$ci|msg|sending inbound message $var(RoutingKey) => $var(Payload)\n");
kazoo_publish($var(exchange), $var(RoutingKey), $var(Payload)); kazoo_publish($var(exchange), $var(RoutingKey), $var(Payload));
sl_send_reply("200", "OK"); sl_send_reply("200", "OK");
@ -36,19 +37,11 @@ route[MESSAGE_INBOUND]
} }
event_route[kazoo:consumer-event-message-route]
event_route[kazoo:consumer-event-sms-outbound]
{ {
$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", "$(kzE{kz.json,Call-ID})|log|received message route for $(kzE{kz.json,Endpoints[0].To-DID})\n");
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});
}
xlog("L_INFO", "$(kzE{kz.json,Message-ID})|log|received message outbound for $(kzE{kz.json,Endpoints[0].To-DID})\n");
$var(from_uri) = $_s(sip:$(kzE{kz.json,From})@$(kzE{kz.json,Custom-Vars.Realm}));
$var(to_uri) = $_s(sip:$(kzE{kz.json,Endpoints[0].To-Username})@$(kzE{kz.json,Endpoints[0].To-Realm}));
$uac_req(method)="MESSAGE"; $uac_req(method)="MESSAGE";
$uac_req(body)= $kzE; $uac_req(body)= $kzE;
$uac_req(hdrs)="X-TM-Local: MESSAGE_ROUTE\r\nX-KAZOO-AOR: " + $var(to_uri)+ "\r\nContent-Type: text/plain\r\n"; $uac_req(hdrs)="X-TM-Local: MESSAGE_ROUTE\r\nX-KAZOO-AOR: " + $var(to_uri)+ "\r\nContent-Type: text/plain\r\n";
@ -56,7 +49,7 @@ event_route[kazoo:consumer-event-message-route]
$uac_req(ruri) = $var(to_uri); $uac_req(ruri) = $var(to_uri);
$uac_req(furi) = $var(from_uri); $uac_req(furi) = $var(from_uri);
$uac_req(ouri) = "sip:127.0.0.1:5090;transport=tcp"; $uac_req(ouri) = "sip:127.0.0.1:5090;transport=tcp";
$uac_req(callid) = $(kzE{kz.json,Call-ID});
$uac_req(callid) = $(kzE{kz.json,Message-ID});
xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|sending message from $var(from_uri) to $var(to_uri) \n"); xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|sending message from $var(from_uri) to $var(to_uri) \n");
uac_req_send(); uac_req_send();
} }
@ -80,17 +73,19 @@ route[MESSAGE_ROUTE]
onreply_route[MESSAGE_REPLY] onreply_route[MESSAGE_REPLY]
{ {
xlog("L_INFO", "$ci|log|sending success delivery message to $avp(server_id)\n");
$var(Payload) = $_s({"Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "$ci", "Message-ID" : "$avp(message_id)" , "Delivery-Result-Code" : "sip:$T_reply_code", "Msg-ID" : "$avp(msg_id)" , "Status" : "Success"});
$var(exchange) = "targeted";
$var(RK) = $avp(server_id);
kazoo_publish($var(exchange), $var(RK), $var(Payload));
if($T_reply_code < 300) {
xlog("L_INFO", "$ci|log|sending success delivery message to $avp(server_id)\n");
$var(Payload) = $_s({"Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "$ci", "Message-ID" : "$avp(message_id)" , "Delivery-Result-Code" : "sip:$T_reply_code", "Msg-ID" : "$avp(msg_id)" , "Status" : "delivered"});
$var(exchange) = "targeted";
$var(RK) = $avp(server_id);
kazoo_publish($var(exchange), $var(RK), $var(Payload));
}
} }
failure_route[MESSAGE_FAULT] failure_route[MESSAGE_FAULT]
{ {
xlog("L_INFO", "$ci|log|sending failure delivery message to $avp(server_id)\n"); xlog("L_INFO", "$ci|log|sending failure delivery message to $avp(server_id)\n");
$var(Payload) = $_s({"Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "$ci", "Message-ID" : "$avp(message_id)" , "Delivery-Result-Code" : "sip:$T_reply_code", "Msg-ID" : "$avp(msg_id)" , "Status" : "Failure"});
$var(Payload) = $_s({"Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "$ci", "Message-ID" : "$avp(message_id)" , "Delivery-Result-Code" : "sip:$T_reply_code", "Msg-ID" : "$avp(msg_id)" , "Status" : "failure"});
$var(exchange) = "targeted"; $var(exchange) = "targeted";
$var(RK) = $avp(server_id); $var(RK) = $avp(server_id);
kazoo_publish($var(exchange), $var(RK), $var(Payload)); kazoo_publish($var(exchange), $var(RK), $var(Payload));
@ -99,7 +94,7 @@ failure_route[MESSAGE_FAULT]
route[MESSAGE_BINDINGS] route[MESSAGE_BINDINGS]
{ {
$var(key) = "kamailio@MY_HOSTNAME"; $var(key) = "kamailio@MY_HOSTNAME";
$var(payload) = $_s({"name": "sms", "exchange": "sms", "type": "topic", "queue": "MSG-QUEUE-MY_HOSTNAME", "routing": "message.route.$(var(key){kz.encode}).*", "no_ack": false, "federate": true });
$var(payload) = $_s({"name": "sms", "exchange": "im", "type": "topic", "queue": "MSG-QUEUE-MY_HOSTNAME", "routing": "sms.outbound.$(var(key){kz.encode}).*", "no_ack": false, "federate": true });
kazoo_subscribe("$var(payload)"); kazoo_subscribe("$var(payload)");
} }


Loading…
Cancel
Save