From ee008bd8d69deb6abb1a9312fac2aaee9733f46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Silva?= Date: Wed, 8 Jun 2022 11:18:11 +0100 Subject: [PATCH] mod_sms: add originate event to send a message directly to dialplan --- src/mod/applications/mod_sms/mod_sms.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/mod/applications/mod_sms/mod_sms.c b/src/mod/applications/mod_sms/mod_sms.c index 68ad7d7ccc..858d62b953 100644 --- a/src/mod/applications/mod_sms/mod_sms.c +++ b/src/mod/applications/mod_sms/mod_sms.c @@ -33,6 +33,7 @@ #define SMS_CHAT_PROTO "GLOBAL_SMS" #define MY_EVENT_SEND_MESSAGE "SMS::SEND_MESSAGE" #define MY_EVENT_DELIVERY_REPORT "SMS::DELIVERY_REPORT" +#define MY_EVENT_ORIGINATE_MESSAGE "SMS::ORIGINATE_MESSAGE" /* Prototypes */ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sms_shutdown); @@ -481,6 +482,18 @@ static switch_status_t chat_send(switch_event_t *message_event) } +static void event_originate_handler(switch_event_t *event) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SMS Originate event\n"); + + if (switch_true(switch_event_get_header(event, "dump_event"))) { + DUMP_EVENT(event); + } + + chat_send(event); +} + + SWITCH_STANDARD_CHAT_APP(info_function) { char *buf; @@ -625,6 +638,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sms_load) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); return SWITCH_STATUS_GENERR; } + if (switch_event_bind(modname, SWITCH_EVENT_CUSTOM, MY_EVENT_ORIGINATE_MESSAGE, event_originate_handler, NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); + return SWITCH_STATUS_GENERR; + } + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -651,6 +669,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sms_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sms_shutdown) { switch_event_unbind_callback(event_handler); + switch_event_unbind_callback(event_originate_handler); switch_event_free_subclass(MY_EVENT_DELIVERY_REPORT);