Freeswitch lua API events

API Events

Данный метод применяется для создания событий.

event:addBody применяется для создания пользовательских событий.
 --Create Custom event
 custom_msg =    "dial_record_id: " .. dial_record_id .. "\n" .. 
         "call_disposition: " .. Disposition .. "\n" ..
         "campaign_number: "  .. Campaign .. "\n" ..
         "called_number: "    .. dial_num .."\n"  ;  
         local e = freeswitch.Event("custom", "dial::dial-result");
 
         e:addBody(custom_msg);
         e:fire();
 

| Множество пользовательских событий могут быть добавлены в заголовок Body. В примере добавлены 4 события:

 [Content-Length] => 555
     [Content-Type] => text/event-plain
     [Body] => Array
         (
             [Event-Subclass] => dial::dial-result
             [Event-Name] => CUSTOM
             [Core-UUID] => 2dc7cc50-b157-4868-ae16-04e5f4b95dae
             [FreeSWITCH-Hostname] => pp6.noble.co.uk
             [FreeSWITCH-IPv4] => 192.168.0.106
             [FreeSWITCH-IPv6] => ::1
             [Event-Date-Local] => 2009-02-17 23:15:49
             [Event-Date-GMT] => Tue, 17 Feb 2009 23:15:49 GMT
             [Event-Date-Timestamp] => 1234912549610060
             [Event-Calling-File] => switch_cpp.cpp
             [Event-Calling-Function] => fire
             [Event-Calling-Line-Number] => 297
             [Content-Length] => 85
             [Body] => Array
                 (
                     [dial_record_id] => 1234
                     [call_disposition] => AA
                     [campaign_number] => 20
                     [called_number] => 7777777
                 )
         )
 )
 

Using luarun to execute this code you can toggle the MWI on a registered phone on and off.

 local event = freeswitch.Event("message_waiting");                                                                                                              
 event:addHeader("MWI-Messages-Waiting", "no");                                                                                                                 
 event:addHeader("MWI-Message-Account", "sip:1002@10.0.1.100");                                                                                                 
 event:fire();

This is a generic API call.

 event:getHeader("Caller-Caller-ID-Name")

Or, This can be used inside of a dialplan.lua to get certain information

 params:getHeader("variable_sip_req_uri")

Возвращает тип события, например CUSTOM для пользовательскго события или одно из списка встроенных событий

Используйте, например, чтобы отобразить все доступные Заголовки в консоли:

 -- Print as text
 io.write(params:serialize());
 io.write(params:serialize("text"));
 
 -- Print as JSON
 io.write(params:serialize("json"));

Или отобразите как сообщение cli:

 freeswitch.consoleLog("info",params:serialize())

Sets the priority for the event, but requires a value of type ''switch_priority_t'' which doesn't seem to be available in the Lua binding.


Lua API Reference

  • freeswitch/interfaces/lua_api_reference/api_events.txt
  • Последние изменения: 2020/04/29