README 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. mohqueue Module
  2. Robert Boisvert
  3. Copyright © 2013 Robert Boisvert, [email protected]
  4. __________________________________________________________________
  5. Table of Contents
  6. 1. Admin Guide
  7. 1. Overview
  8. 2. Dependencies
  9. 2.1. Kamailio Modules
  10. 2.2. External Libraries or Applications
  11. 3. Parameters
  12. 3.1. db_url (str)
  13. 3.2. db_qtable and db_ctable (str)
  14. 3.3. mohdir (str)
  15. 3.4. moh_maxcalls (integer)
  16. 4. Functions
  17. 4.1. mohq_process ()
  18. 4.2. mohq_send (queue_name)
  19. 4.3. mohq_retrieve (queue_name, URI)
  20. 4.4. mohq_count (queue_name, pvar)
  21. 5. Database Schema
  22. 5.1. MOHQUEUES Table
  23. 5.2. MOHQCALLS Table
  24. 6. Audio Files
  25. List of Examples
  26. 1.1. Set db_url:
  27. 1.2. Set table names:
  28. 1.3. Set default directory for audio files:
  29. 1.4. Set default directory for audio files:
  30. 1.5. mohq_process usage:
  31. 1.6. mohq_send usage:
  32. 1.7. mohq_retrieve usage:
  33. 1.8. mohq_count usage:
  34. Chapter 1. Admin Guide
  35. Table of Contents
  36. 1. Overview
  37. 2. Dependencies
  38. 2.1. Kamailio Modules
  39. 2.2. External Libraries or Applications
  40. 3. Parameters
  41. 3.1. db_url (str)
  42. 3.2. db_qtable and db_ctable (str)
  43. 3.3. mohdir (str)
  44. 3.4. moh_maxcalls (integer)
  45. 4. Functions
  46. 4.1. mohq_process ()
  47. 4.2. mohq_send (queue_name)
  48. 4.3. mohq_retrieve (queue_name, URI)
  49. 4.4. mohq_count (queue_name, pvar)
  50. 5. Database Schema
  51. 5.1. MOHQUEUES Table
  52. 5.2. MOHQCALLS Table
  53. 6. Audio Files
  54. 1. Overview
  55. The mohqueue module diverts INVITE requests into a Music On Hold (MOH)
  56. queue where the caller can listen to recorded audio until an operator
  57. is available to take the call. When an operator is available, a
  58. function can be used to transfer the oldest call in a queue to an
  59. operator using an unattended transfer (REFER) to a specified URI. If
  60. successful, the call is removed from the queue.
  61. While in queue, recorded audio is streamed to the caller in an endless
  62. loop using the rtpproxy module and application. Each queue can be
  63. configured to use different audio files.
  64. The queues are defined in the database which allows for dynamic
  65. configuration of the queues. Each queue is assigned a specific URI to
  66. respond to and a location for the audio files.
  67. As each call arrives the database is updated to show the call status
  68. which allows outside processes to inspect the queue. It can also be
  69. inspected using a function to see how many calls are currently in
  70. queue.
  71. While in queue, all SIP messages for a call must pass through the
  72. mohqueue module so that it can accurately detect the call status.
  73. 2. Dependencies
  74. 2.1. Kamailio Modules
  75. 2.2. External Libraries or Applications
  76. 2.1. Kamailio Modules
  77. The following modules must be loaded before this module:
  78. * a database module
  79. * sl module
  80. * tm module
  81. * rtpproxy module
  82. 2.2. External Libraries or Applications
  83. The rtpproxy applications supported by the rtpproxy module (e.g.
  84. http://www.b2bua.org/wiki/RTPproxy).
  85. 3. Parameters
  86. 3.1. db_url (str)
  87. 3.2. db_qtable and db_ctable (str)
  88. 3.3. mohdir (str)
  89. 3.4. moh_maxcalls (integer)
  90. 3.1. db_url (str)
  91. The URL to connect to the database for the mohqueue tables.
  92. Default value for Kamailio.
  93. Example 1.1. Set db_url:
  94. ...
  95. modparam ("mohqueue", "db_url", "mysql://kamailio:kamailiorw@localhost/kamailio
  96. ")
  97. ...
  98. 3.2. db_qtable and db_ctable (str)
  99. db_qtable is the name of the table that defines the queues and
  100. db_ctable is the table that maintains the call status.
  101. "MOHQUEUES" for db_qtable and "MOHQCALLS" for db_ctable.
  102. Example 1.2. Set table names:
  103. ...
  104. modparam ("mohqueue", "db_qtable", "mqueues")
  105. modparam ("mohqueue", "db_ctable", "mcalls")
  106. ...
  107. 3.3. mohdir (str)
  108. Path to the directory where the audio files are stored. Audio files are
  109. usually relative to this directory although the value can be overridden
  110. by a directory specified in the queues table.
  111. None. If not set by the module it must be defined in the queues table.
  112. Example 1.3. Set default directory for audio files:
  113. ...
  114. modparam ("mohqueue", "mohdir", "/var/kamailio/MOH")
  115. ...
  116. 3.4. moh_maxcalls (integer)
  117. Defines the maximum number of calls that can be placed in queue. It is
  118. the sum of all calls in all queues. It must be in the range of 1 to
  119. 5000. NOTE: it may be limited by the processing power of the server or
  120. the number of available rtpproxy ports.
  121. None. If not set by the module it must be defined in the queues table.
  122. Example 1.4. Set default directory for audio files:
  123. ...
  124. modparam ("mohqueue", "mohdir", "/var/kamailio/MOH")
  125. ...
  126. 4. Functions
  127. 4.1. mohq_process ()
  128. 4.2. mohq_send (queue_name)
  129. 4.3. mohq_retrieve (queue_name, URI)
  130. 4.4. mohq_count (queue_name, pvar)
  131. 4.1. mohq_process ()
  132. Checks to see if the current SIP message involves a queue. If it does
  133. it will process the message and return a TRUE value.
  134. In order for mohqueue to detect changes in the call it is necessary
  135. that all messages involving the call be processed through this
  136. function. The easiest way is to accomplish this is to place it at the
  137. beginning of the main route of the script.
  138. mohqueue calls are identified by an RURI that matches a queue URI. Once
  139. a call is placed in queue it checks the To header field along with the
  140. RURI to find a match, except in the case of a CANCEL which matches only
  141. on the RURI.
  142. This function has no parameters and must be called from a request
  143. route.
  144. Return code:
  145. * TRUE=successful and call in queue
  146. * FALSE=failed, unrecognized URI or unable to place in queue
  147. Example 1.5. mohq_process usage:
  148. ...
  149. request_route {
  150. # main route with limited processing
  151. ...
  152. # MOH queue?
  153. if (mohq_process ()) {
  154. xlog ("L_DBG", "Handled by mohqueue");
  155. exit;
  156. }
  157. # An error or not a MOH queue message; continue processing
  158. ...
  159. }
  160. ...
  161. 4.2. mohq_send (queue_name)
  162. Normally calls enter the queue with an initial INVITE message that 1)
  163. has a RURI that matches a queue URI and 2) is passed through mohq_proc
  164. (), which is the preferred method.
  165. This function is used when you wish to send a call into a queue that
  166. does not match the queue URI.
  167. It has only one parameter, the name of the queue, and must be called
  168. from the request route with an initial INVITE message. The queue name
  169. can be passed as a literal or pseudo-variable.
  170. Return code:
  171. * TRUE=successful and call in queue
  172. * FALSE=failed, unable to place in queue
  173. Example 1.6. mohq_send usage:
  174. ...
  175. # call is initial INVITE and ready for queue?
  176. if (some test) {
  177. if (mohq_send ("main")) {
  178. xlog ("L_DBG", "Sent call to main mohqueue");
  179. exit;
  180. }
  181. # failed to enter queue!
  182. ...
  183. }
  184. ...
  185. 4.3. mohq_retrieve (queue_name, URI)
  186. Retrieves the oldest call in a queue and redirects it to a URI.
  187. Although the function returns, the transfer of the call may not have
  188. completed since the new URI (operator) must answer the call.
  189. It has two parameters, the queue name and the URI to REFER the call to,
  190. both which can be passed as literals or pseudo-variables. It can be
  191. called from any route.
  192. Return code:
  193. * TRUE=successful, transfer started
  194. * FALSE=failed, parameters are incorrect or there are no calls in
  195. queue
  196. Example 1.7. mohq_retrieve usage:
  197. ...
  198. #!define MOHQNAME "operators"
  199. #!define CGROUP "sip:[email protected]"
  200. ...
  201. # redirect oldest call to operator call group
  202. if (mohq_retrieve (MOHQNAME, CGROUP)) {
  203. xlog ("L_DBG", "Retrieved call from mohqueue");
  204. exit;
  205. }
  206. # queue is empty or something went wrong
  207. }
  208. ...
  209. 4.4. mohq_count (queue_name, pvar)
  210. Finds the number of calls that are in a queue. It will not count calls
  211. that are in the process of entering or exiting the queue.
  212. The function has two parameters, the name of the queue and the
  213. pseudo-variable which receives the count. The queue name can be passed
  214. as a literal or a pseudo-variable. It can be called from any route.
  215. Return code:
  216. * TRUE=successful, pseudo-variable contains count
  217. * FALSE=failed, parameters are incorrect
  218. Example 1.8. mohq_count usage:
  219. ...
  220. $var(mohq) = "operators";
  221. ...
  222. # more than 10 calls?
  223. mohq_count ("$var(mohq)", "$var(mohqcnt)");
  224. if ($var(mohqcnt) > 10) {
  225. xlog ("L_WARN", "$var(mohq) queue has $var(mohqcnt) calls!");
  226. }
  227. ...
  228. 5. Database Schema
  229. 5.1. MOHQUEUES Table
  230. 5.2. MOHQCALLS Table
  231. mohqueue uses two external database tables to manage the queues and
  232. provide status information to outside processes. Internally, it keeps a
  233. volatile database in memory of call status. If the module is restarted
  234. it loses the internal database and clears the external one.
  235. On a reqular basis it checks the external table that defines the queues
  236. to see if the definition has changed. It makes this check under the
  237. following conditions: the queue has not been checked in the last 60
  238. seconds AND no call is currently in queue or transitioning in or out.
  239. The last condition prevents existing calls from being adversely
  240. affected by queue redefinitions.
  241. 5.1. MOHQUEUES Table
  242. This table controls the definition of the queue. The name is set by the
  243. db_qtable parameter. There is no internal function to modify the table
  244. so it must be configured externally. It contains the following fields:
  245. * id (integer): unique identifier that is created automatically. Do
  246. not attempt to change this value.
  247. * name (25-character string, required): the queue name. Duplicate
  248. names are not allowed.
  249. * uri (100-character string, required): the URI of the queue. It
  250. should not include any parameters or headers (e.g.
  251. "sip:user@host;maddr=239.255.255.1" or
  252. "sip:user@host?subject=project") although it will match any RURI
  253. that contains this URI even if the RURI has parameters or headers.
  254. Duplicates are not allowed.
  255. * mohdir (100-character string, optional): path to the directory
  256. where the audio files for the queue are stored. This path overrides
  257. the one provided by the mohdir parameter. If the directory is not
  258. accessible by the module the queue is not activated.
  259. * mohfile (100-character string, required): the base name of the
  260. audio file. See the section about audio files for more information
  261. about file names. If no files matching this name are found in the
  262. directory the queue is not activated.
  263. * debug (integer, required): enables debugging messages for the
  264. queue. If non-zero, it will send debugging messages to the log for
  265. conditions that involve the queue, whether or not Kamailio has
  266. logging enabled for debugging. If zero, it depends on Kamailio's
  267. log level.
  268. 5.2. MOHQCALLS Table
  269. This table contains the status of calls that are in queue, or
  270. transitioning in or out of a queue. The name is set by the db_ctable
  271. parameter. This table is read-only for external processes and its
  272. contents should not be modified. It contains the following fields:
  273. * id (integer): unique identifier that is created automatically.
  274. * mohq_id (integer, required): the id value of the queue.
  275. * call_status (integer, required): the status of the call.
  276. 1=entering; 2=in queue (listening to MOH); 3=leaving
  277. * call_from (100-character string, required): the contents of the
  278. From header field.
  279. * call_id (100-character string, required): the contents of the
  280. Call-ID header field.
  281. * call_contact (100-character string, optional): the contents of the
  282. Contact header field, if it exists.
  283. * call_time (datetime, required): time the call entered the queue. If
  284. a retrieve fails this time is not changed.
  285. 6. Audio Files
  286. When rtpproxy negotiates to determine which media to use in the audio
  287. stream it uses the files in the MOH directory as defined by the
  288. MOHQUEUES table. The table defines the location of the files and the
  289. base name used to identify each. The actual stream type depends on the
  290. RTP payload number that is part of the name. The complete file name for
  291. each stream is composed of mohdir/mohfile.type. For example,
  292. /var/kamailio/MOH/HeWillCall.8 would be the file for payload type 8
  293. (PCMA/8000).
  294. The supported types and their order of preference are:
  295. * 9: G722/8000
  296. * 0: PCMU/8000
  297. * 8: PCMA/8000
  298. * 18: G729/8000
  299. * 3: GSM/8000
  300. * 4: G723/8000
  301. * 15: G728/8000
  302. * 5: DVI4/8000
  303. * 7: LPC/8000
  304. * 12: QCELP/8000
  305. * 13: CN/8000
  306. * 16: DVI4/11025
  307. * 6: DVI4/16000
  308. * 17: DVI4/22050
  309. * 10: L16/44100
  310. * 11: L16/44100
  311. * 14: MPA/90000
  312. See RTP Audio Video Profile for more information about RTP payload
  313. types.