System information
variable, which is set by the HOTDESK_STATUS() function. This tells us how many rows
were affected in the SQL UPDATE, which we assume to be 1. If the value of ${ODB
CROWS} is less than 1, we assume an error and handle it appropriately:
exten => logout,1,NoOp()
same => n,Set(HOTDESK_STATUS(${E})=0)
same => n,GotoIf($[${ODBCROWS} < 1]?error,1)
same => n,Playback(silence/1&agent-loggedoff)
same => n,Hangup()
exten => login_fail,1,NoOp()
same => n,Playback(silence/1&login-fail)
same => n,Hangup()
exten => error,1,NoOp()
same => n,Playback(silence/1&connection-failed)
same => n,Hangup()
exten => invalid_user,1,NoOp()
same => n,Verbose(1,Hot Desk extension ${E} does not exist)
same => n,Playback(silence/2&invalid)
same => n,Hangup()
We also include the hotdesk_outbound context, which will handle our outgoing calls
after we have logged the agent into the system:
include => hotdesk_outbound
The hotdesk_outbound context utilizes many of the same principles discussed previ-
ously, so we won’t approach it quite so thoroughly; essentially, this context will catch
all numbers dialed from the desk phones. We first set our LOCATION variable using the
CHANNEL variable, then determine which extension (agent) is logged into the system and
assign that value to the WHO variable. If this variable is NULL, we reject the outgoing call.
If it is not NULL, then we get the agent information using the HOTDESK_INFO() function
and assign it to several CHANNEL variables, including the context to handle the call with,
where we perform a Goto() to the context we have been assigned (which controls our
outbound access).
We will make use of the HOTDESK_PHONE_STATUS() dialplan function, which you can
define in func_odbc.conf like so:
[PHONE_STATUS]
prefix=HOTDESK
dsn=asterisk
readsql=SELECT extension FROM ast_hotdesk WHERE status = '1'
readsql+= AND location = '${ARG1}'
If we try to dial a number that is not handled by our context (or one of the transitive
contexts—i.e., international contains long distance, which also contains local), the
built-in extension i is executed, which plays back a message stating that the action
cannot be performed and hangs up the call:
366 | Chapter 16: Relational Database Integration