911 Alert message to a yealink T46S Sip Phone

Status
Not open for further replies.

Doug Dassow

New Member
Dec 20, 2020
12
0
1
52
Hi All,
I am trying to see how to program my Fusion PBX, so that when an extension Dials 911 it sends a pop up message to another given phone on the PBX. I have already figured out with the help of another member here on this forum to get my 911 dial plan to send an email to an email account with the extension that Dialed 911. That was my first battle. Now I have to battle the alerts problem displaying on the front desk phone.
The phone that would be receiving the alert is a Yealink T46S if this helps (extension 501). and lets say room 1 (ext 101) is the phone dialing 911 for this example. What would be the code to enter in the PBX? and where would I enter it? I am kind of new at programming the PBX, so more detailed answers will help me greatly. So Thanks in advance Doug
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,415
376
83
Doug,
I have just roughed this out for you, so it is not properly tested and may be buggy but it should give you an idea of a way you can do what you need.

This is an lua script called yealink_alert_911.lua, this lives in /usr/share/freeswitch/scipts

Code:
--
--    FusionPBX
--    Version: MPL 1.1
--
--    The contents of this file are subject to the Mozilla Public License Version
--    1.1 (the "License"); you may not use this file except in compliance with
--    the License. You may obtain a copy of the License at
--    http://www.mozilla.org/MPL/
--
--    Software distributed under the License is distributed on an "AS IS" basis,
--    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
--    for the specific language governing rights and limitations under the
--    License.
--
--    This is an unofficial FusionPBX application, its purpose is to provide an
--    indication to members of a call group when an extension within the
--    call group is ringing.
--
--    The code presented here is inspired by the original code at FusionPBX and
--    credit must be given to: Mark J Crane <markjcrane@fusionpbx.com>
--    for that original work.
--
--    Contributor(s):
--    Adrian Fretwell <adrian@a2es.co.uk>
--

--usage
--    yealink_message.lua <profile> <extension> <beep> <duration>
--    yealink_message.lua internal 201 yes 5

--set the args as variables
    dst_profile = argv[1];
    dst_extn = argv[2];
    dst_beep = argv[3];
    dst_timeout = argv[4];

-- set debugging
    --debug["user"] = true;

--set default variables
    min_digits = "1";

--define the trim function
    require "resources.functions.trim";

--define the explode function
    require "resources.functions.explode";

--define the yealink xml and event functions
    require "resources.functions.yealink_notify_xml";

--create the api object
--    api = freeswitch.API();

--include config.lua
--    require "resources.functions.config";

--    local blf = require "resources.functions.blf"
--    local cache = require "resources.functions.cache"
    local Settings = require "resources.functions.lazy_settings"
--    local notify = require "app.feature_event.resources.functions.feature_event_notify"

--get the variables
    if (session:ready()) then
        sounds_dir = session:getVariable("sounds_dir");
        domain_uuid = session:getVariable("domain_uuid");
        domain_name = session:getVariable("domain_name");
        destination_number = session:getVariable("destination_number");
        sip_from_user = session:getVariable("sip_from_user");
    end

    if (debug["user"]) then
        freeswitch.consoleLog("notice", "[yealink_message] " .. dst_extn .. "@" .. domain_name .. "\n");
    end

--create the event notify object
    local event = freeswitch.Event('NOTIFY');
    local evbody = build_yealink_xml_body(dst_beep, dst_timeout, "911 Alert!", " Call From: " .. sip_from_user .. "\n To: " .. destination_number);
    build_yealink_xml_event(event, dst_profile, dst_extn, domain_name, evbody);

--send the event
    event:fire();


Then in the dialplan, create an entry that looks something like this:

Screenshot from 2021-06-24 07-47-22.png
 

Doug Dassow

New Member
Dec 20, 2020
12
0
1
52
One other thing... Where in the script do I place the extension number of the phone that I want the alert to pop up on? in this case its 501. TIA
 

ad5ou

Active Member
Jun 12, 2018
884
197
43
His example is using "201" as the alert destination.
yealink_message.lua <profile> <extension> <beep> <duration>
also note in his example "internal" is assuming "201" is registered on the default internal sip profile. If you have multiple sip profiles users register to, this field would also need to change.
 

flagman

Member
Dec 1, 2020
30
2
8
40
Doug,
I have just roughed this out for you, so it is not properly tested and may be buggy but it should give you an idea of a way you can do what you need.

This is an lua script called yealink_alert_911.lua, this lives in /usr/share/freeswitch/scipts

Code:
--
--    FusionPBX
--    Version: MPL 1.1
--
--    The contents of this file are subject to the Mozilla Public License Version
--    1.1 (the "License"); you may not use this file except in compliance with
--    the License. You may obtain a copy of the License at
--    http://www.mozilla.org/MPL/
--
--    Software distributed under the License is distributed on an "AS IS" basis,
--    WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
--    for the specific language governing rights and limitations under the
--    License.
--
--    This is an unofficial FusionPBX application, its purpose is to provide an
--    indication to members of a call group when an extension within the
--    call group is ringing.
--
--    The code presented here is inspired by the original code at FusionPBX and
--    credit must be given to: Mark J Crane <markjcrane@fusionpbx.com>
--    for that original work.
--
--    Contributor(s):
--    Adrian Fretwell <adrian@a2es.co.uk>
--

--usage
--    yealink_message.lua <profile> <extension> <beep> <duration>
--    yealink_message.lua internal 201 yes 5

--set the args as variables
    dst_profile = argv[1];
    dst_extn = argv[2];
    dst_beep = argv[3];
    dst_timeout = argv[4];

-- set debugging
    --debug["user"] = true;

--set default variables
    min_digits = "1";

--define the trim function
    require "resources.functions.trim";

--define the explode function
    require "resources.functions.explode";

--define the yealink xml and event functions
    require "resources.functions.yealink_notify_xml";

--create the api object
--    api = freeswitch.API();

--include config.lua
--    require "resources.functions.config";

--    local blf = require "resources.functions.blf"
--    local cache = require "resources.functions.cache"
    local Settings = require "resources.functions.lazy_settings"
--    local notify = require "app.feature_event.resources.functions.feature_event_notify"

--get the variables
    if (session:ready()) then
        sounds_dir = session:getVariable("sounds_dir");
        domain_uuid = session:getVariable("domain_uuid");
        domain_name = session:getVariable("domain_name");
        destination_number = session:getVariable("destination_number");
        sip_from_user = session:getVariable("sip_from_user");
    end

    if (debug["user"]) then
        freeswitch.consoleLog("notice", "[yealink_message] " .. dst_extn .. "@" .. domain_name .. "\n");
    end

--create the event notify object
    local event = freeswitch.Event('NOTIFY');
    local evbody = build_yealink_xml_body(dst_beep, dst_timeout, "911 Alert!", " Call From: " .. sip_from_user .. "\n To: " .. destination_number);
    build_yealink_xml_event(event, dst_profile, dst_extn, domain_name, evbody);

--send the event
    event:fire();


Then in the dialplan, create an entry that looks something like this:

View attachment 2392

Hello Adrian,
Thank you so much for your help, but I'm getting issue with the "resources.functions.yealink_notify_xml"
My freeswitch log says "module resources.functions.yealink_notify_xml not found"
Can you please tell me how can I add this module to my FusionPBX?
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,415
376
83
Hello Adrian,
Thank you so much for your help, but I'm getting issue with the "resources.functions.yealink_notify_xml"
My freeswitch log says "module resources.functions.yealink_notify_xml not found"
Can you please tell me how can I add this module to my FusionPBX?

It is not a FreeSWITCH module it is an .lua script include. Unless things have changed in more recent installations it would normally be located in the:
/usr/share/freeswitch/scripts/resources/functions
directory.

The "require" is a relative path from the script location. I.E. /usr/share/freeswitch/scripts/yealink_911_alert.lua
 

markjcrane

Active Member
Staff member
Jul 22, 2018
450
162
43
49
The yealink_notify_xml file is not part of FusionPBX by default. So this require will cause the script to fail.

require "resources.functions.yealink_notify_xml";

Also don't see a pull request for it.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,415
376
83
The yealink_notify_xml file is not part of FusionPBX by default. So this require will cause the script to fail.

require "resources.functions.yealink_notify_xml";

Also don't see a pull request for it.
Just something that I think we wrote to help someone out, no big deal.

Happy New Year!
 

markjcrane

Active Member
Staff member
Jul 22, 2018
450
162
43
49
Well as other people come and read this just know without the additional file this will not work.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,415
376
83
Well as other people come and read this just know without the additional file this will not work.
Sorry Mark, I misunderstood what you were saying.

The code I have for yealink_notify_xml.lua is given below. I don't remember writing it, but that doesn't mean I didn't! The file on my dev box is dated Sep 11 2020.

Code:
--add the build_yealink_xml_body function
    function build_yealink_xml_body(beep, timeout, title, text)
        local evbody = "?xml version=\"1.0\" encoding=\"ISO-8859-1\">\n";
        evbody = evbody .. "<YealinkIPPhoneTextScreen\n";
        evbody = evbody .. "   Beep=\"" .. beep  .. "\"\n";
        evbody = evbody .. "   Timeout=\"" .. timeout .. "\"\n";
        evbody = evbody .. "   LockIn=\"no\">\n"
        evbody = evbody .. "<Title wrap=\"yes\">" .. title .. "</Title>\n";
        evbody = evbody .. "<Text>" .. text .. "</Text>\n";
        evbody = evbody .. "</YealinkIPPhoneTextScreen>\n";
        return evbody;
    end

--add the build_yealink_xml_event function
    function build_yealink_xml_event(event, profile, user, host, evbody)
        --add the headers
        event:addHeader('profile', profile);
        event:addHeader('user', user);
        event:addHeader('host', host);
        event:addHeader('event-string', 'Yealink-xml');
        event:addHeader('content-type', 'application/xml');
        --add the body
        event:addBody(evbody);
    end
 
Status
Not open for further replies.