diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 3312ebd497..70eed55e22 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -125,6 +125,7 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_CURRENT_APPLICATION_VARIABLE "current_application" #define SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE "proto_specific_hangup_cause" #define SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE "execute_on_answer" +#define SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE "api_on_answer" #define SWITCH_CHANNEL_EXECUTE_ON_RING_VARIABLE "execute_on_ring" #define SWITCH_CALL_TIMEOUT_VARIABLE "call_timeout" #define SWITCH_HOLDING_UUID_VARIABLE "holding_uuid" diff --git a/src/switch_channel.c b/src/switch_channel.c index 1e2af783d4..9f07185404 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -2143,6 +2143,23 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan } } + if ((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_API_ON_ANSWER_VARIABLE)) && !switch_strlen_zero(var)) { + switch_stream_handle_t stream = { 0 }; + char *arg = NULL; + + app = switch_core_session_strdup(channel->session, var); + if ((arg = strchr(app, ' '))) { + *arg++ = '\0'; + } + + SWITCH_STANDARD_STREAM(stream); + switch_api_execute(app, arg, NULL, &stream); + + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s api on answer: %s(%s)\n%s\n", + channel->name, app, switch_str_nil(arg), (char *)stream.data); + free(stream.data); + } + switch_channel_audio_sync(channel); return SWITCH_STATUS_SUCCESS;