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

queue
Tags: #<Tag:0x00007f7031f35bd0>

(Paperakis) #1

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?


(Lorne Gaetz) #2

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.


(Paperakis) #3

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/519@from-queue-00008f9e;2 | Dial    | PJSIP/519/sip:519@172.17.129.84:39547&PJSIP/519/sip:519@172.17.129.84: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/519@from-queue-00008f9e;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/527@from-queue-00008fa8;2 | Dial    | PJSIP/527/sip:527@172.17.129.73:1025&PJSIP/527/sip:527@172.17.173.20: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/527@from-queue-00008fa8;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/527@from-queue-00008faa;2 | Dial    | PJSIP/527/sip:527@172.17.129.73:1025&PJSIP/527/sip:527@172.17.173.20: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/527@from-queue-00008faa;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/527@from-queue-00008fce;2 | Dial    | PJSIP/527/sip:527@172.17.129.73:1025&PJSIP/527/sip:527@172.17.173.20: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/527@from-queue-00008fce;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?