Some times ago i need to login agent from external program (1C, Axapta etc) - no a legal path to prepare this function. I found only one powerful function Originate (this example for C# and Asterisk.NET library but pricipal are common))
OriginateAction o = new OriginateAction(); o.Channel = "Local/agent_logoff@manager_tools"; o.Timeout = timeout; o.Variable = "AGENT_NUMBER=" + localAgent; o.Application = "noop"; ManagerResponse r = manager.SendAction(o, timeout);
and add to extensions.conf next context (this example for AGent Login/Logoff/Pause/Unpause). All other function can be added in this context. Only one remark - at the end of context you must use Answer() not a Hangup()
[manager_tools] ; ; Agent login ; $AGENT_NUMBER agent number ; $AGENT_EXTEN extension number ; exten => agent_login, 1, Set(UserEventType=Agent) exten => agent_login, n, Set(Result=Error) exten => agent_login, n, Set(CURRENT_AGENT=${DB(AGENT/Exten/${AGENT_EXTEN})}) ; Current agent on extension exten => agent_login, n, GotoIf($["${CURRENT_AGENT}" = ""]?ext_free) ; extension free exten => agent_login, n, GotoIf($["${CURRENT_AGENT}" = "${AGENT_NUMBER}"]?already_login) exten => agent_login, n, Noop(${DB_DELETE(AGENT/Exten/${AGENT_EXTEN})}) exten => agent_login, n, Noop(${DB_DELETE(AGENT/${CURRENT_AGENT}/onExten)}) exten => agent_login, n, UserEvent(Agent|Agent: ${CURRENT_AGENT}|Status: Logoff|Port: ${AGENT_EXTEN}|Channel: ${LDP${AGENT_EXTEN}}) exten => agent_login, n, Gosub(queues-manip-custom,O${CURRENT_AGENT},1) exten => agent_login, n(ext_free), Set(CURRENT_EXTEN=${DB(AGENT/${AGENT_NUMBER}/onExten)}) ; Current extension for agent exten => agent_login, n, GotoIf($["${CURRENT_EXTEN}" = ""]?agent_free) ; agent free exten => agent_login, n, GotoIf($["${CURRENT_EXTEN}" = "${AGENT_EXTEN}"]?already_login) exten => agent_login, n, Noop(${DB_DELETE(AGENT/Exten/${CURRENT_EXTEN})}) exten => agent_login, n, Noop(${DB_DELETE(AGENT/${AGENT_NUMBER}/onExten)}) exten => agent_login, n, UserEvent(Agent|Agent: ${AGENT_NUMBER}|Status: Logoff|Port: ${CURRENT_EXTEN}|Channel: ${LDP${CURRENT_EXTEN}}) exten => agent_login, n, Gosub(queues-manip-custom,O${AGENT_NUMBER},1) exten => agent_login, n(agent_free), NoOp(Agent login) exten => agent_login, n, Set(DB(AGENT/Exten/${AGENT_EXTEN})=${AGENT_NUMBER}) exten => agent_login, n, Set(DB(AGENT/${AGENT_NUMBER}/onExten)=${AGENT_EXTEN}) exten => agent_login, n, Set(UNIQCLID=${AGENT_EXTEN}) exten => agent_login, n, Gosub(queues-manip-custom,I${AGENT_NUMBER},1) exten => agent_login, n(already_login), Set(Result=Login) exten => agent_login, n, Answer() ; ; Agent logoff ; $AGENT_NUMBER ; exten => agent_logoff, 1, Set(UserEventType=Agent) exten => agent_logoff, n, Set(Result=Error) exten => agent_logoff, n, Set(AGENT_EXTEN=${DB(AGENT/${AGENT_NUMBER}/onExten)}) exten => agent_logoff, n, GotoIf($["${AGENT_EXTEN}" = ""]?already_logoff) exten => agent_logoff, n, Gosub(queues-manip-custom,O${AGENT_NUMBER},1) exten => agent_logoff, n, Noop(${DB_DELETE(AGENT/Exten/${AGENT_EXTEN})}) exten => agent_logoff, n, Noop(${DB_DELETE(AGENT/${AGENT_NUMBER}/onExten)}) exten => agent_logoff, n(already_logoff), Set(Result=Logoff) exten => agent_logoff, n, Answer() ; ; Agent pause ; exten => agent_pause, 1, Set(UserEventType=Agent) exten => agent_pause, n, Set(Result=Error) exten => agent_pause, n, Set(AGENT_EXTEN=${DB(AGENT/${AGENT_NUMBER}/onExten)}) exten => agent_pause, n, GotoIf($["${AGENT_EXTEN}" = ""]?ext_free) exten => agent_pause, n, PauseQueueMember(|${LDP${AGENT_EXTEN}}); exten => agent_pause, n, Set(Result=Pause) exten => agent_pause, n(ext_free), Answer() ; ; Agent unpause ; exten => agent_unpause, 1, Set(UserEventType=Agent) exten => agent_unpause, n, Set(Result=Error) exten => agent_unpause, n, Set(AGENT_EXTEN=${DB(AGENT/${AGENT_NUMBER}/onExten)}) exten => agent_unpause, n, GotoIf($["${AGENT_EXTEN}" = ""]?ext_free) exten => agent_unpause, n, UnpauseQueueMember(|${LDP${AGENT_EXTEN}}); exten => agent_unpause, n, Set(Result=Unpause) exten => agent_unpause, n(ext_free), Answer() ; ; User event to all above ; exten => h, 1, GotoIf($["${UserEventType}" = "Agent"]?agent) exten => h, n, Goto(unknown) exten => h, n(agent), UserEvent(Agent|Agent: ${AGENT_NUMBER}|Status: ${Result}|Port: ${AGENT_EXTEN}|Channel: ${LDP${AGENT_EXTEN}}) exten => h, n(unknown), NoOp(${UserEventType}) [queues-manip-custom] exten => _[IO]XX., 1, Noop(${EXTEN}) exten => _[IO]XX., n, Set(AGENT_NUMBER=${EXTEN:1}) exten => _[IO]XX., n, Set(AGENT_EXTEN=${DB(AGENT/${AGENT_NUMBER}/onExten)}) exten => _[IO]XX., n, Set(agentvar=${AGENT${AGENT_NUMBER}}) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "I"]|Set|DB(AGENT/${AGENT_NUMBER}/Queues)=${AGENT${AGENT_NUMBER}}) exten => _[IO]XX., n, GotoIf($["${EXTEN:0:1}" = "I"]?continue) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "O"]|Set|agentvar=${DB_DELETE(AGENT/${AGENT_NUMBER}/Queues)}) exten => _[IO]XX., n(continue), Set(i=0) exten => _[IO]XX., n(repeat), Set(i=$[${i}+1]) exten => _[IO]XX., n, Set(q=${CUT(agentvar,:,${i})}) exten => _[IO]XX., n, GotoIf($[${LEN(${q})} = 0]?endrepeat); exten => _[IO]XX., n, Noop(${q}) exten => _[IO]XX., n, Set(queuename=${CUT(q,-,1)}) exten => _[IO]XX., n, Set(penalty=${CUT(q,-,2)}) exten => _[IO]XX., n, GotoIf($[${LEN(${penalty})} > 0]?$[${PRIORITY}+2]) exten => _[IO]XX., n, Set(penalty=0) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "I"]|AddQueueMember|${queuename}|${LDP${AGENT_EXTEN}}|${penalty}||Agent/${AGENT_NUMBER}) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "O"]|RemoveQueueMember|${queuename}|${LDP${AGENT_EXTEN}}) exten => _[IO]XX., n, Goto(repeat) exten => _[IO]XX., n(endrepeat), Noop(End of cycle) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "I"]|System|echo "${EPOCH}|${UNIQUEID}|NONE|Agent/${AGENT_NUMBER}|AGENTCALLBACKLOGIN|${AGENT_EXTEN}" >> /var/log/asterisk/queue_log) exten => _[IO]XX., n, ExecIf($["${EXTEN:0:1}" = "O"]|System|echo "${EPOCH}|${UNIQUEID}|NONE|Agent/${AGENT_NUMBER}|AGENTCALLBACKLOGOFF|${AGENT_EXTEN}" >> /var/log/asterisk/queue_log) exten => _[IO]XX., n, Return
0 comment(s) so far