-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample.lua
More file actions
54 lines (44 loc) · 1.49 KB
/
example.lua
File metadata and controls
54 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--------------------------------------------------------------------------------
-- interactive-test.lua: interactive test
-- This file is a part of Lua-AMI library
-- Copyright (c) Lua-AMI authors (see file `COPYRIGHT` for the license)
--------------------------------------------------------------------------------
-- Little tool, to accsess "live" asterisk: send originate command
-- @script interactive-test.lua
--------------------------------------------------------------------------------
local ami = require "ami/init"
local inspect = require 'inspect'
local config =
{
host = "127.0.0.1";
port = 5038;
tls = false;
username = "ami";
secret = "";
timeout = 60*1000;
auth = 'md5';
logger = print;
}
local AMI = ami.new(config)
-- execute some commands
print('-- get info for 303101')
local res, err = AMI:execute('PJSIPShowEndpoint', {Endpoint='3030101'} )
assert(res, 'unable to execute request')
print(res.EndpointDetail.Callerid)
print('-- pjsip reload')
local res, err = AMI:execute('Command', {Command='pjsip reload'} )
assert(res, 'unable to execute request')
print(res)
print('-- get all endpoints')
local res, err = AMI:execute('PJSIPShowEndpoints')
assert(res, 'unable to execute request')
print('total ' .. #res .. ' endpoints')
-- listen for events
print('--subscribe for all events')
AMI:subscribe('*', function(e)
print('unknown event received!')
print(inspect(e))
coroutine.yield()
end)
local res, err = AMI:events('call')
assert(res, 'unable to execute request')