Files
fusionpbx/resources/install/scripts/resources/functions/presence_in.lua
Alexey Melnichuk 61d6f0be6c Add. Handler for SUBSCRIBE method for call flow application. (#1701)
* Add. Handler for SUBSCRIBE method for call flow application.

Usage:
1. Run form fs_cli `luarun call_flow_subscribe`
2. Create new call flow extension and set feature code to `flow+<EXTENSION>`(e.g. `flow+401`).
3. Set on the phone BLF key to `flow+401`

This code based on `mod_valet_parking`.

* Add. prevent running 2 copy of script.

Remove some unused vars and simplify implementation.

* Fix. Use correct protocol for send event.

* Fix. Do escape SQL arguments

* Fix. escape `+` sign in call flow extension.
2016-06-24 10:32:19 -06:00

34 lines
897 B
Lua

require "resources.functions.split"
local function turn_lamp(on, user, uuid)
local userid, domain, proto = split_first(user, "@", true)
proto, userid = split_first(userid, "+", true)
if userid then
user = userid .. "@" .. domain
else
proto = "sip"
end
local event = freeswitch.Event("PRESENCE_IN");
event:addHeader("proto", proto);
event:addHeader("event_type", "presence");
event:addHeader("alt_event_type", "dialog");
event:addHeader("Presence-Call-Direction", "outbound");
event:addHeader("from", user);
event:addHeader("login", user);
event:addHeader("unique-id", uuid);
event:addHeader("status", "Active (1 waiting)");
if on then
event:addHeader("answer-state", "confirmed");
event:addHeader("rpid", "unknown");
event:addHeader("event_count", "1");
else
event:addHeader("answer-state", "terminated");
end
event:fire();
end
return {
turn_lamp = turn_lamp;
}