Interactive Lua via Http#
You can add this script to you configuration and it will run in the background waiting for http-get-request to
The phone uses tokens to verify http-requests from outside the Web-UI. You can generate such tokens in the Web-UI under Access. Use such a token either as value of an http-header named Authorization or pass it as query-parameter. E.g. (if token is abcefg):
curl -k -H "Authorization: Bearer abcdefg" -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua" -d 'system.toast("hello world")'
curl -k -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua?AuthToken=abcdefg" -d 'system.toast("hello world")'
Warning
Be mindful who you give these lua-access uri's or the AuthTokens. The AuthTokens are a replacement for username & password and grant access to all sorts of web-services including the WebUI or ActionUrls. They can be used to read or change passwords or to start calls.
The body of these http-get-request is expected to hold a lua-script or single lua line that you want to execute. Use return in your script if you want get some information back. E.g.:
curl -k -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua?AuthToken=abcdefg" -d 'return sip.calls.get_all()[1]:getState()'
HTTP/1.1 200 OK
...
Content-Type: text/plain
active
Local variables only exist during one http-script execution. They'll be lost when you send the next script. You can create variables in the global namespace, you might want to create a dictionary though, as to not pollute it to much
curl -k -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua?AuthToken=abcdefg" -d '
> local forgetful = 42
> userdata = {}
> userdata.rememberMe = 42
> '
HTTP/1.1 200 OK
...
Content-Type: text/plain
curl -k -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua?AuthToken=abcdefg" -d 'return forgetful'
HTTP/1.1 200 OK
...
Content-Type: text/plain
curl -k -i "https://[yourPhonesIp]/api/v1/exec/interactive.lua?AuthToken=abcdefg" -d 'return userdata.rememberMe'
HTTP/1.1 200 OK
...
Content-Type: text/plain
42