tSIP: "on programmable button" Lua event
With tSIP 0.1.66 new script event type was added - "on programmable button". This event allows to handle button pressing with script for any button type (not only for "Script" type button). Most obvious usage would be combining BLF type button with script.
Along with new event type three Lua functions were added:
- SetHandle(value)
- allows to decide if normal button action should be executed after script finishes (value == 0) or not (if value != 0)
- type = GetButtonType(btnId)
- get configured button type
- number = GetButtonNumber(btnId)
- get number/URI configured for button
Example script for BLF buttons that generated either blind or attended transfer depending of Ctrl button state:
-- determine trigger of script execution local execSourceType = GetExecSourceType() -- 0 = button if execSourceType ~= 0 then print("Unexpected context for 'on programmable button' script!\n") return end local callState = GetCallState() if callState ~= 6 then -- 6 = CALL_STATE_ESTABLISHED (connected) SetHandled(0) -- use default button action return end local btnId = GetExecSourceId() local btnType = GetButtonType(btnId) if btnType ~= 2 then -- 2 = BLF button (position on button types list indexed from 0) SetHandled(0) return end local btnNumber = GetButtonNumber(btnId) function testflag(set, flag) return set % (2*flag) >= flag end local winapi = require("tsip_winapi") -- https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes -- VK_SHIFT = 0x10 = 16 -- VK_CONTROL = 0x11 = 17 -- VK_MENU (Alt) = 0x12 = 18 -- etc. keyState = winapi.GetAsyncKeyState(17) if testflag(keyState, 32768) then -- print("CONTROL is down\n") SendDtmf("*2" .. btnNumber) -- "*2" = default attented transfer feature code for asterisk else -- print("CONTROL is up\n") SendDtmf("#1" .. btnNumber) -- "#1" = default blind transfer feature code for asterisk -- or: -- BlindTransfer(number) end SetHandled(1) -- skip default action
Back to howto list.