From fc96e3ae77a84c52ab6ade9e8846293364896f9d Mon Sep 17 00:00:00 2001 From: Luis Daniel Lucio Quiroz Date: Tue, 16 Mar 2021 15:43:21 -0400 Subject: [PATCH 1/3] DTMF handling this will give the dtmf_history (similar to the transfer_history variable) the use cases of this are only limited to the imagination --- .../resources/scripts/dtmf_handler.lua | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/scripts/resources/scripts/dtmf_handler.lua diff --git a/app/scripts/resources/scripts/dtmf_handler.lua b/app/scripts/resources/scripts/dtmf_handler.lua new file mode 100644 index 0000000000..d286c9690a --- /dev/null +++ b/app/scripts/resources/scripts/dtmf_handler.lua @@ -0,0 +1,37 @@ +require "resources.functions.split"; +require "resources.functions.trim"; + +local s = event:serialize("xml") +local name = event:getHeader("Event-Name") +--freeswitch.consoleLog("NOTICE", "Got event! " .. name) + +--freeswitch.consoleLog("NOTICE", "Serial!\n" .. s) + + +local name = event:getHeader("Event-Name"); +local channel_state = event:getHeader("Channel-State") or '[nil]'; +local original_channel_state = event:getHeader("Original-Channel-Call-State") or '[nil]'; +local channel_name = event:getHeader("Channel-Name") or '[nil]'; +local channel_call_uuid = event:getHeader("Channel-Call-UUID"); +local channel_timestamp = event:getHeader("Event-Date-Timestamp"); +local body = event:getBody(); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] event-name " .. name); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] original-channel-state " .. original_channel_state); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-state " .. channel_state); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-name " .. channel_name); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-call-uuid " .. channel_call_uuid); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel_timestamp " .. channel_timestamp); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] body " .. body); + +session = freeswitch.Session(channel_call_uuid); +local v = split(body,"\n",true); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] type: " .. v[1]); +--freeswitch.consoleLog("NOTICE", "[dtmf_handler] type: " .. v[2]); +local vv = split(v[1],'=',true); +local dtmf_value = trim(vv[2]); +freeswitch.consoleLog("NOTICE", "[dtmf_handler] DTMF value: " .. dtmf_value); +local history = channel_timestamp .. ':' .. dtmf_value .. "\n"; +session:execute("push", "dtmf_history="..history); + +-- lua.conf.xml +-- From 908e7f67d61251ec22419a1595df162f70c7aede Mon Sep 17 00:00:00 2001 From: Luis Daniel Lucio Quiroz Date: Wed, 17 Mar 2021 12:02:54 -0400 Subject: [PATCH 2/3] Update dtmf_handler.lua --- .../resources/scripts/dtmf_handler.lua | 34 ++++--------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/app/scripts/resources/scripts/dtmf_handler.lua b/app/scripts/resources/scripts/dtmf_handler.lua index d286c9690a..5b73665471 100644 --- a/app/scripts/resources/scripts/dtmf_handler.lua +++ b/app/scripts/resources/scripts/dtmf_handler.lua @@ -1,37 +1,15 @@ -require "resources.functions.split"; -require "resources.functions.trim"; - -local s = event:serialize("xml") -local name = event:getHeader("Event-Name") +--local s = event:serialize("xml") +--local name = event:getHeader("Event-Name") --freeswitch.consoleLog("NOTICE", "Got event! " .. name) - --freeswitch.consoleLog("NOTICE", "Serial!\n" .. s) - -local name = event:getHeader("Event-Name"); -local channel_state = event:getHeader("Channel-State") or '[nil]'; -local original_channel_state = event:getHeader("Original-Channel-Call-State") or '[nil]'; -local channel_name = event:getHeader("Channel-Name") or '[nil]'; -local channel_call_uuid = event:getHeader("Channel-Call-UUID"); +local call_uuid = event:getHeader("Caller-Unique-ID"); local channel_timestamp = event:getHeader("Event-Date-Timestamp"); -local body = event:getBody(); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] event-name " .. name); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] original-channel-state " .. original_channel_state); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-state " .. channel_state); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-name " .. channel_name); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel-call-uuid " .. channel_call_uuid); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] channel_timestamp " .. channel_timestamp); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] body " .. body); +local dtmf_value = event:getHeader("DTMF-Digit"); -session = freeswitch.Session(channel_call_uuid); -local v = split(body,"\n",true); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] type: " .. v[1]); ---freeswitch.consoleLog("NOTICE", "[dtmf_handler] type: " .. v[2]); -local vv = split(v[1],'=',true); -local dtmf_value = trim(vv[2]); -freeswitch.consoleLog("NOTICE", "[dtmf_handler] DTMF value: " .. dtmf_value); +local session = freeswitch.Session(call_uuid); local history = channel_timestamp .. ':' .. dtmf_value .. "\n"; session:execute("push", "dtmf_history="..history); -- lua.conf.xml --- +-- From fa12c4daea1c689c907c0f627a8a2f3e35455143 Mon Sep 17 00:00:00 2001 From: Luis Daniel Lucio Quiroz Date: Wed, 17 Mar 2021 19:19:55 -0400 Subject: [PATCH 3/3] Update dtmf_handler.lua Event-Date-Timestamp resolution is in microseconds, transfer_history is only seconds. We need have the same key. --- app/scripts/resources/scripts/dtmf_handler.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/scripts/resources/scripts/dtmf_handler.lua b/app/scripts/resources/scripts/dtmf_handler.lua index 5b73665471..89f4faa786 100644 --- a/app/scripts/resources/scripts/dtmf_handler.lua +++ b/app/scripts/resources/scripts/dtmf_handler.lua @@ -4,7 +4,8 @@ --freeswitch.consoleLog("NOTICE", "Serial!\n" .. s) local call_uuid = event:getHeader("Caller-Unique-ID"); -local channel_timestamp = event:getHeader("Event-Date-Timestamp"); +--local channel_timestamp = event:getHeader("Event-Date-Timestamp"); +local channel_timestamp = os.time(); local dtmf_value = event:getHeader("DTMF-Digit"); local session = freeswitch.Session(call_uuid);