Skip to main content

Cause Code Substitution Example

About

Emmanuel Schmidbauer created a simple Lua script that sends a replacement cause code to Leg A instead of the cause code received from Leg B.

Click here to expand Table of Contents

Cause Code Substitution Script

Invoke the following Lua script in a parameter to a bridge command similar to the following example line:

<action application="set" data="execute_on_post_originate=lua process_480.lua ${uuid}"/>  
<action application="bridge" data="sofia/internal/sip:nummer@pbx.host.com:5060"/>

process_480.lua

-- process_480.lua
-- check for response code and send different one back
--
uuid = argv[1];
api = freeswitch.API();
sip_invite_failure_status = api:executeString("uuid_getvar "..uuid.." sip_invite_failure_status");
if sip_invite_failure_status == "480" then
reply = api:executeString("uuid_setvar "..uuid.." last_bridge_proto_specific_hangup_cause sip:503");
end

This example demonstrates how to send cause code 503 to the Leg A after Leg B returns a cause code 480. You can expand on this for more cause codes or even look up the translation in a database.