Mod_callcenter modification in order to retrieve sip failure reason when agent no answer the call

Hi,

We have a freeswitch instance that run the mod_callcenter module in order to handle a call queue application.
Callcenter agent are located behind our sip proxy,

Caller <—> OUR SIP PROXY <—> FS <—> OUR SIP PROXY <----> agents.

FS release: FreeSWITCH Version 1.10.11-release-25-f24064f7c9~64bit (-release-25-f24064f7c9 64bit)
OS: linux debian 11 (bullseye)

If the agent is not reachable by our proxy, proxy sent a SIP 603 with a non standard phrase reason. and we have to retrieve the phrase reason in the mod_callcenter module and send this reason to an external application through ESL.

In order to do that I have put a modification in the code of the mod_callcenter module:

diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c
index b035b6d7f9..a56265cd2f 100644
--- a/src/mod/applications/mod_callcenter/mod_callcenter.c
+++ b/src/mod/applications/mod_callcenter/mod_callcenter.c
@@ -1771,7 +1771,7 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa
 
                dialstr = switch_channel_expand_variables(member_channel, h->originate_string);
                switch_channel_set_app_flag_key(CC_APP_KEY, member_channel, CC_APP_AGENT_CONNECTING);
-               status = switch_ivr_originate(NULL, &agent_session, &cause, dialstr, globals.agent_originate_timeout, NULL, cid_name ? cid_name : h->member_cid_name, cid_number ? cid_number : h->member_cid_number, NULL, ovars, SOF_NONE, NULL, NULL);
+               status = switch_ivr_originate(member_session, &agent_session, &cause, dialstr, globals.agent_originate_timeout, NULL, cid_name ? cid_name : h->member_cid_name, cid_number ? cid_number : h->member_cid_number, NULL, ovars, SOF_NONE, NULL, NULL);
 
                /* Search for loopback agent */
                if (status == SWITCH_STATUS_SUCCESS) {
@@ -2126,6 +2126,7 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa
        } else {
                /* Agent didn't answer or originate/bridge failed */
                int delay_next_agent_call = 0;
+               const char* hangup_reason = NULL;
                switch_channel_t *member_channel = switch_core_session_get_channel(member_session);
                switch_channel_clear_app_flag_key(CC_APP_KEY, member_channel, CC_APP_AGENT_CONNECTING);
                sql = switch_mprintf("UPDATE members SET state = case state when '%q' then '%q' else state end, serving_agent = '', serving_system = ''"
@@ -2136,6 +2137,7 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa
                cc_execute_sql(NULL, sql, NULL);
                switch_safe_free(sql);
                bridged = 0;
+               hangup_reason = switch_channel_get_variable(member_channel, "sip_invite_failure_phrase");
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member_session), SWITCH_LOG_DEBUG, "Agent %s Origination Canceled : %s\n", h->agent_name, switch_channel_cause2str(cause));
 
                switch (cause) {
@@ -2201,6 +2203,9 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Queue", h->queue_name);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Action", "bridge-agent-fail");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Hangup-Cause", switch_channel_cause2str(cause));
+                       if (hangup_reason) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CC-Hangup-Reason",hangup_reason);
+                       }

First in the switch_ivr_originate we put the session of the caller (member_session) in the first argument.
if the agent does not anser, the variable “sip_invite_failure_phrase” is put in the member session. The value of this variable is the reason of the failure we have to catch.

Finally we use the event callcenter::info event with the CC-Action=“bridge-agent-fail” to add a header:
CC-Hangup-Reason set to the value of “sip_invite_failure_phrase”.

Do you think that these modifications can be added to the main source branch of the callcenter module?

Regards,

Eric

For some reason, we have to retrieve the sip failure reason corresponding to the SIP 603 answer.
When an agent is called by freeswitch in some case of no answer, our platform