View difference between Paste ID: sP3Gdq2g and kT0nmZX2
SHOW: | | - or go back to the newest paste.
1
-- Initialization of variables
2
api = freeswitch.API()
3
-- First argument is caller uuid.
4
caller_uuid = argv[1]
5
if caller_uuid==nil then return end
6
-- Second argument is callcenter name.
7
queue_name = argv[2]
8
if queue_name==nil then return end
9
-- Third argument is repeating interval in miliseconds.
10
mseconds = argv[3]
11
if mseconds==nil then return end
12
13
times_announced = 0
14
15
16
while (true) do
17
	freeswitch.msleep(mseconds) -- Pause before announcing position
18
	members = api:executeString("callcenter_config queue list members "..queue_name)
19
	pos=1 -- Variable to count position 
20
	exists=false -- Variable to allow script termination when member leaves queue 
21
	for line in members:gmatch("[^\r\n]+") do
22
		if (string.find(line,"Trying")~=nil or string.find(line,"Waiting")~=nil) then
23
		    -- Members have a position when their state is Waiting or Trying
24
			if string.find(line,caller_uuid,1,true)~=nil then
25
				exists=true -- Member still in queue so script must continue 
26
				--api:executeString("uuid_broadcast "..caller_uuid.." ivr/ivr-you_are_number.wav aleg")
27
				--api:executeString("uuid_broadcast "..caller_uuid.." digits/"..pos..".wav aleg")
28
				if pos == 1 then
29
					if times_accounced == 0 then
30
						api:executeString("uuid_broadcast "..caller_uuid.." say:'Please hold. You will be connected to a representative shortly.' aleg")
31
					else
32
						api:executeString("uuid_broadcast "..caller_uuid.." say:'We are sorry to keep you waiting. You will be connected to a representative shortly.' aleg")
33
					end
34
				elseif pos == 2 then
35
					if times_accounced == 0 then
36
						api:executeString("uuid_broadcast "..caller_uuid.." say:'There is 1 caller ahead of you. We will be with you shortly.' aleg")
37
					else
38
						api:executeString("uuid_broadcast "..caller_uuid.." say:'We are sorry to keep you waiting. There is 1 caller ahead of you. We will be with you shortly.' aleg")
39
					end
40
				else
41
					if times_accounced == 0 then
42
						api:executeString("uuid_broadcast "..caller_uuid.." say:'There are "..(pos-1).." callers ahead of you. We will be with you shortly.' aleg")
43
					else
44
						api:executeString("uuid_broadcast "..caller_uuid.." say:'We are sorry to keep you waiting. There are "..(pos-1).." callers ahead of you. We will be with you shortly.' aleg")
45
					end
46
				end
47
				times_announced = times_announced + 1
48
			end
49
			pos=pos+1
50
		end
51
	end
52
	if exists==false then return end -- If member was not found in queue, or it's status is Aborted - terminate script
53
end