Clients can find the same agent that speak on a previous call

Hello all,

I’m using a freepbx v15 asterisk 16 and i was wondering if a call answered by an agent… and after 1 hour or so the callee do another call is it possible to find the same agent that answered the previous call if he’s available?

If you could create a single SQL query that pulls up the most recent call and determine which extension they talked to, you could do this with Dynamic Routes. It not a simple query, you need to find the most recent CEL event with eventtype = ANSWER, determine the uniqueid of that record and then find any associated records with a matching linkedid which also have eventtype = ANSWER, and figure out the extension number from there. Otherwise an AGI file that does a series of queries and adds some logic about how far back to look etc etc. A nice rainy weekend project.

Dear Lorne,

Thanks for your responce… i’m trying to figure out with the sql query…

MariaDB [asteriskcdrdb]> SELECT * FROM cel WHERE eventtime BETWEEN DATE_ADD(now(), interval -1 hour) AND NOW() AND cid_num like 'CLID_NUM' AND eventtype like 'BRIDGE_ENTER';
+----------+--------------+---------------------+-----------------+------------+------------+-----------+------------+-------+----------------+---------------------------------+---------+----------------------------------------------------------------------------------------------------------------------------+----------+-------------+-------------------+-------------------+---------------------------------+-------------+------------------------------------------------------------------------------------------+
| id       | eventtype    | eventtime           | cid_name        | cid_num    | cid_ani    | cid_rdnis | cid_dnid   | exten | context        | channame                        | appname | appdata                                                                                                                    | amaflags | accountcode | uniqueid          | linkedid          | peer                            | userdeftype | extra                                                                                    |
+----------+--------------+---------------------+-----------------+------------+------------+-----------+------------+-------+----------------+---------------------------------+---------+----------------------------------------------------------------------------------------------------------------------------+----------+-------------+-------------------+-------------------+---------------------------------+-------------+------------------------------------------------------------------------------------------+
| 20469700 | BRIDGE_ENTER | 2021-02-26 13:30:23 | test:CLID_NUM | CLID_NUM | CLID_NUM |           |            | s     | macro-dial-one | Local/[email protected];2 | Dial    | PJSIP/519/sip:[email protected]:39547&PJSIP/519/sip:[email protected]:5060,,HhtrM(auto-blkvm)Ib(func-apply-sipheaders^s^1) |        3 |             | 1614339020.114878 | 1614339020.114876 | PJSIP/519-00009f3f              |             | {"bridge_id":"7fc59ae7-4466-4066-b392-ae4468f606f9","bridge_technology":"simple_bridge"} |
| 20469708 | BRIDGE_ENTER | 2021-02-26 13:30:23 | test:CLID_NUM | CLID_NUM | CLID_NUM |           | DID_NUM | 499   | ext-queues     | PJSIP/-offices-00009f3b  | Queue   | 499,tc,,,10,,,,,                                                                                                           |        3 |             | 1614339020.114876 | 1614339020.114876 | Local/[email protected];1 |             | {"bridge_id":"c998834e-f79d-4185-a9e7-ae39ec69443d","bridge_technology":"simple_bridge"} |
| 20469848 | BRIDGE_ENTER | 2021-02-26 13:30:49 | test:CLID_NUM | CLID_NUM | CLID_NUM |           |            | s     | macro-dial-one | Local/[email protected];2 | Dial    | PJSIP/527/sip:[email protected]:1025&PJSIP/527/sip:[email protected]:5060,,HhtrM(auto-blkvm)Ib(func-apply-sipheaders^s^1)  |        3 |             | 1614339046.114913 | 1614339046.114909 | PJSIP/527-00009f4c              |             | {"bridge_id":"306fd556-c300-414d-8433-16ed48b778e0","bridge_technology":"simple_bridge"} |
| 20469855 | BRIDGE_ENTER | 2021-02-26 13:30:49 | test:CLID_NUM | CLID_NUM | CLID_NUM |           | DID_NUM | 499   | ext-queues     | PJSIP/-offices-00009f4a  | Queue   | 499,tc,,,10,,,,,                                                                                                           |        3 |             | 1614339046.114909 | 1614339046.114909 | Local/[email protected];1 |             | {"bridge_id":"86a9463e-ad81-4b29-b8c7-5d1352e3ae55","bridge_technology":"simple_bridge"} |
| 20469894 | BRIDGE_ENTER | 2021-02-26 13:31:17 | test:CLID_NUM | CLID_NUM | CLID_NUM |           |            | s     | macro-dial-one | Local/[email protected];2 | Dial    | PJSIP/527/sip:[email protected]:1025&PJSIP/527/sip:[email protected]:5060,,HhtrM(auto-blkvm)Ib(func-apply-sipheaders^s^1)  |        3 |             | 1614339074.114922 | 1614339074.114918 | PJSIP/527-00009f53              |             | {"bridge_id":"69e08b4d-56a8-4d42-8f84-e0ee0d13dacc","bridge_technology":"simple_bridge"} |
| 20469901 | BRIDGE_ENTER | 2021-02-26 13:31:17 | test:CLID_NUM | CLID_NUM | CLID_NUM |           | DID_NUM | 499   | ext-queues     | PJSIP/-offices-00009f4f  | Queue   | 499,tc,,,10,,,,,                                                                                                           |        3 |             | 1614339074.114918 | 1614339074.114918 | Local/[email protected];1 |             | {"bridge_id":"ed14adc0-1150-4762-b49d-d3f17f2c2bb0","bridge_technology":"simple_bridge"} |
| 20470754 | BRIDGE_ENTER | 2021-02-26 13:58:22 | test:CLID_NUM | CLID_NUM | CLID_NUM |           |            | s     | macro-dial-one | Local/[email protected];2 | Dial    | PJSIP/527/sip:[email protected]:1025&PJSIP/527/sip:[email protected]:5060,,HhtrM(auto-blkvm)Ib(func-apply-sipheaders^s^1)  |        3 |             | 1614340696.115083 | 1614340695.115079 | PJSIP/527-00009fa9              |             | {"bridge_id":"3c9f6811-4591-43a1-a485-91e7611d113c","bridge_technology":"simple_bridge"} |
| 20470757 | BRIDGE_ENTER | 2021-02-26 13:58:22 | test:CLID_NUM | CLID_NUM | CLID_NUM |           | DID_NUM | 499   | ext-queues     | PJSIP/-offices-00009fa5  | Queue   | 499,tc,,,10,,,,,                                                                                                           |        3 |             | 1614340695.115079 | 1614340695.115079 | Local/[email protected];1 |             | {"bridge_id":"b9b64a4a-cde6-43f1-af63-262e29f51172","bridge_technology":"simple_bridge"} |
+----------+--------------+---------------------+-----------------+------------+------------+-----------+------------+-------+----------------+---------------------------------+---------+----------------------------------------------------------------------------------------------------------------------------+----------+-------------+-------------------+-------------------+---------------------------------+-------------+------------------------------------------------------------------------------------------+
8 rows in set (0.01 sec)

Any thoughts how i can get the extensions that have been answered the call?

/etc/asterisk/func_odbc.conf

[CHCKAGNT]
prefix=ODBC
dsn=asteriskcdrdb
readsql=SELECT SUBSTRING_INDEX(SUBSTRING_INDEX( channame, '@' , 1 ),'/', -1) FROM cel WHERE eventtime BETWEEN DATE_ADD(now(), interval -1 hour) AND NOW() AND cid_num like '${ARG1}' AND eventtype = 'ANSWER' AND context like 'macro%' ORDER BY id DESC limit 1

/etc/asterisk/extensions_custom.conf

[check-agent-avail]
include => unpause_agnt
exten => s,1,NoOp(***Start to custom app***)
;check if the callid have been speaked with an agent
same => n,Set(agent_check=${ODBC_CHCKAGNT(${CALLERID(number)})})
same => n,NoOp(the agent is ${agent_check}})
same => n,GotoIF($['${agent_check}' = '']?noagent:agentfound)

;the callid haven't speaked with an agent
same => n(noagent),noop(***no agent found you will go to queue***)
same => n,Goto(ext-queues,650,1)

;check if the agent status is NOT_INUSE
same => n(agentfound),NoOp((The DEVICE_STATE of ${agent_check} is ${DEVICE_STATE(PJSIP/${agent_check})})
same => n,GotoIF($[ '${DEVICE_STATE(PJSIP/${agent_check})}' = 'NOT_INUSE' ]?godial)
same => n,Goto(ext-queues,650,1)
same => n,Hangup()

same => n(godial),noop()
same => n,System(/usr/sbin/asterisk -rx "queue pause member Local/${agent_check}@from-queue/n queue 650 reason available_for_inboundcall")
same => n,Set(CHANNEL(hangup_handler_push)=unpause_agnt,s,1)
same => n,Dial(PJSIP/${agent_check},300)
same => n,Hangup()

[unpause_agnt]
exten => s,1,System(/usr/sbin/asterisk -rx "queue unpause member Local/${agent_check}@from-queue/n queue 650")
same => n,Hangup()

I was managed to resolve it. so i share the context~

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.