First, functional requirements:
The corresponding script file is called through the FreeSWITCH IVR key, and Nodejs provides many modules, which can easily communicate with other systems or in any form, my application is to send HTTP POST requests via Nodejs;
Because I'm not familiar with the way freeswitch directly transfers the execution of the Nodejs file, I execute a LUA script that executes a call to the Nodejs file in a LUA script and executes it with the following specific settings:
Second, the specific setting:
①IVR settings:
<entry action= "Menu-exec-app" digits= "1" param= "Lua Testlighton.lua"/>
②testlighton.lua Script content:
Os.execute (' node/usr/local/freeswitch/scripts/lighton.js '); Nodejs File storage location:/usr/local/freeswitch/scripts/lighton.js
③/usr/local/freeswitch/scripts/lighton.js Script content:
var rest = require (' Restler ');
Rest.post (' Http://192.168.11.17:3021/serviceUp/cmd/sendCMDDispatcher ', {
Data: {
cmdcontent:[{
' Deviceentityaid ': ' 03003c00 ',
' Dataid ': ' 03010000 ',
"Value": "FF"
}]
},
}). On (' Complete ', function (data, response) {
Console.log (data);
}). On (' Error ', function (er) {
Console.log (ER);
});
This allows the HTTP POST request to be implemented according to the "1" button in the IVR prompt, where the data area is transmitted in the body.
FreeSWITCH IVR in Lua calls and executes Nodejs code