mohqueue_admin.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module Admin Guide -->
  9. <chapter xmlns:xi="http://www.w3.org/2001/XInclude">
  10. <title>&adminguide;</title>
  11. <section id="overview">
  12. <title>Overview</title>
  13. <para>
  14. The mohqueue module diverts INVITE requests into a
  15. <ulink url="http://en.wikipedia.org/wiki/Music_on_hold">Music On
  16. Hold (MOH)</ulink> queue where the caller can listen to recorded
  17. audio until an operator is available to take the call. When an
  18. operator is available, a function can be used to transfer the oldest
  19. call in a queue to an operator using an unattended transfer (REFER)
  20. to a specified URI. If successful, the call is removed from the queue.
  21. </para>
  22. <para>
  23. While in queue, recorded audio is streamed to the caller in an endless
  24. loop using the rtpproxy module and application. Each queue can be
  25. configured to use different audio files.
  26. </para>
  27. <para>
  28. The queues are defined in the database which allows for dynamic
  29. configuration of the queues. Each queue is assigned a specific
  30. URI to respond to and a location for the audio files.
  31. </para>
  32. <para>
  33. As each call arrives the database is updated to show the call
  34. status which allows outside processes to inspect the queue. It
  35. can also be inspected using a function to see how many calls are
  36. currently in queue.
  37. </para>
  38. <para>
  39. While in queue, all SIP messages for a call must pass through
  40. the mohqueue module so that it can accurately detect the call
  41. status.
  42. </para>
  43. </section>
  44. <section id="dependencies">
  45. <title>Dependencies</title>
  46. <section id="mod.depends">
  47. <title>Kamailio Modules</title>
  48. <para>
  49. The following modules must be loaded before this module:
  50. <itemizedlist>
  51. <listitem><emphasis>a database module</emphasis></listitem>
  52. <listitem><emphasis>sl module</emphasis></listitem>
  53. <listitem><emphasis>tm module</emphasis></listitem>
  54. <listitem><emphasis>rtpproxy module</emphasis></listitem>
  55. </itemizedlist>
  56. </para>
  57. </section>
  58. <section id="app.depends">
  59. <title>External Libraries or Applications</title>
  60. <para>
  61. The rtpproxy applications supported by the rtpproxy module (e.g.
  62. <ulink url="http://www.b2bua.org/wiki/RTPproxy">
  63. http://www.b2bua.org/wiki/RTPproxy</ulink>).
  64. </para>
  65. </section>
  66. </section>
  67. <section id="parameters">
  68. <title>Parameters</title>
  69. <section id="url.parms">
  70. <title><varname>db_url</varname> (str)</title>
  71. <para>
  72. The URL to connect to the database for the mohqueue tables.
  73. </para>
  74. <para>
  75. <emphasis>Default value for Kamailio.</emphasis>
  76. </para>
  77. <example>
  78. <title>Set <varname>db_url</varname>:</title>
  79. <programlisting format="linespecific">
  80. ...
  81. modparam ("mohqueue", "db_url", "mysql://kamailio:kamailiorw@localhost/kamailio")
  82. ...
  83. </programlisting>
  84. </example>
  85. </section>
  86. <section id="table.parms">
  87. <title><varname>db_qtable</varname> and <varname>db_ctable</varname> (str)</title>
  88. <para>
  89. <varname>db_qtable</varname> is the name of the table that defines
  90. the queues and <varname>db_ctable</varname> is the table that
  91. maintains the call status.
  92. </para>
  93. <para>
  94. <emphasis>"MOHQUEUES" for <varname>db_qtable</varname> and
  95. "MOHQCALLS" for <varname>db_ctable</varname>.</emphasis>
  96. </para>
  97. <example>
  98. <title>Set table names:</title>
  99. <programlisting format="linespecific">
  100. ...
  101. modparam ("mohqueue", "db_qtable", "mqueues")
  102. modparam ("mohqueue", "db_ctable", "mcalls")
  103. ...
  104. </programlisting>
  105. </example>
  106. </section>
  107. <section id="dir.parms">
  108. <title><varname>mohdir</varname> (str)</title>
  109. <para>
  110. Path to the directory where the audio files are stored. Audio files
  111. are usually relative to this directory although the value can be
  112. overridden by a directory specified in the queues table.
  113. </para>
  114. <para>
  115. <emphasis>None. If not set by the module it must be defined in the
  116. queues table.</emphasis>
  117. </para>
  118. <example>
  119. <title>Set default directory for audio files:</title>
  120. <programlisting format="linespecific">
  121. ...
  122. modparam ("mohqueue", "mohdir", "/var/kamailio/MOH")
  123. ...
  124. </programlisting>
  125. </example>
  126. </section>
  127. <section id="maxcalls.parms">
  128. <title><varname>moh_maxcalls</varname> (integer)</title>
  129. <para>
  130. Defines the maximum number of calls that can be placed in queue.
  131. It is the sum of all calls in all queues. It must be in the range
  132. of 1 to 5000. <emphasis>NOTE:</emphasis> it may be limited by the
  133. processing power of the server or the number of available rtpproxy
  134. ports.
  135. </para>
  136. <para>
  137. <emphasis>None. If not set by the module it must be defined in the
  138. queues table.</emphasis>
  139. </para>
  140. <example>
  141. <title>Set default directory for audio files:</title>
  142. <programlisting format="linespecific">
  143. ...
  144. modparam ("mohqueue", "mohdir", "/var/kamailio/MOH")
  145. ...
  146. </programlisting>
  147. </example>
  148. </section>
  149. </section>
  150. <section id="functions">
  151. <title>Functions</title>
  152. <section id="proc.func">
  153. <title>
  154. <function moreinfo="none">mohq_process ()</function>
  155. </title>
  156. <para>
  157. Checks to see if the current SIP message involves a queue. If it
  158. does it will process the message and return a TRUE value.
  159. </para>
  160. <para>
  161. In order for mohqueue to detect changes in the call it is necessary
  162. that all messages involving the call be processed through this
  163. function. The easiest way is to accomplish this is to place it at
  164. the beginning of the main route of the script.
  165. </para>
  166. <para>
  167. mohqueue calls are identified by an RURI that matches a queue URI.
  168. Once a call is placed in queue it checks the <varname>To</varname>
  169. header field along with the RURI to find a match, except in the case
  170. of a CANCEL which matches only on the RURI.
  171. </para>
  172. <para>
  173. This function has no parameters and must be called from a request route.
  174. </para>
  175. <para>
  176. <emphasis>Return code:</emphasis>
  177. <itemizedlist>
  178. <listitem>
  179. <emphasis>TRUE=successful and call in queue</emphasis>
  180. </listitem>
  181. <listitem>
  182. <emphasis>FALSE=failed, unrecognized URI or unable to place in queue</emphasis>
  183. </listitem>
  184. </itemizedlist>
  185. </para>
  186. <example>
  187. <title><function>mohq_process</function> usage:</title>
  188. <programlisting format="linespecific">
  189. ...
  190. request_route {
  191. # main route with limited processing
  192. ...
  193. # MOH queue?
  194. if (mohq_process ()) {
  195. xlog ("L_DBG", "Handled by mohqueue");
  196. exit;
  197. }
  198. # An error or not a MOH queue message; continue processing
  199. ...
  200. }
  201. ...
  202. </programlisting>
  203. </example>
  204. </section>
  205. <section id="send.func">
  206. <title>
  207. <function moreinfo="none">mohq_send (queue_name)</function>
  208. </title>
  209. <para>
  210. Normally calls enter the queue with an initial INVITE message that
  211. 1) has a RURI that matches a queue URI and 2) is passed through
  212. <function>mohq_proc ()</function>, which is the preferred method.
  213. </para>
  214. <para>
  215. This function is used when you wish to send a call into a queue that
  216. does not match the queue URI.
  217. </para>
  218. <para>
  219. It has only one parameter, the name of the queue, and must be called
  220. from the request route with an initial INVITE message. The queue name
  221. can be passed as a literal or pseudo-variable.
  222. </para>
  223. <para>
  224. <emphasis>Return code:</emphasis>
  225. <itemizedlist>
  226. <listitem>
  227. <emphasis>TRUE=successful and call in queue</emphasis>
  228. </listitem>
  229. <listitem>
  230. <emphasis>FALSE=failed, unable to place in queue</emphasis>
  231. </listitem>
  232. </itemizedlist>
  233. </para>
  234. <example>
  235. <title><function>mohq_send</function> usage:</title>
  236. <programlisting format="linespecific">
  237. ...
  238. # call is initial INVITE and ready for queue?
  239. if (some test) {
  240. if (mohq_send ("main")) {
  241. xlog ("L_DBG", "Sent call to main mohqueue");
  242. exit;
  243. }
  244. # failed to enter queue!
  245. ...
  246. }
  247. ...
  248. </programlisting>
  249. </example>
  250. </section>
  251. <section id="retrieve.func">
  252. <title>
  253. <function moreinfo="none">mohq_retrieve (queue_name, URI)</function>
  254. </title>
  255. <para>
  256. Retrieves the oldest call in a queue and redirects it to a URI.
  257. Although the function returns, the transfer of the call may not have
  258. completed since the new URI (operator) must answer the call.
  259. </para>
  260. <para>
  261. It has two parameters, the queue name and the URI to REFER the call
  262. to, both which can be passed as literals or pseudo-variables. It can
  263. be called from any route.
  264. </para>
  265. <para>
  266. <emphasis>Return code:</emphasis>
  267. <itemizedlist>
  268. <listitem>
  269. <emphasis>TRUE=successful, transfer started</emphasis>
  270. </listitem>
  271. <listitem>
  272. <emphasis>FALSE=failed, parameters are incorrect or there are no calls in queue</emphasis>
  273. </listitem>
  274. </itemizedlist>
  275. </para>
  276. <example>
  277. <title><function>mohq_retrieve</function> usage:</title>
  278. <programlisting format="linespecific">
  279. ...
  280. #!define MOHQNAME "operators"
  281. #!define CGROUP "sip:[email protected]"
  282. ...
  283. # redirect oldest call to operator call group
  284. if (mohq_retrieve (MOHQNAME, CGROUP)) {
  285. xlog ("L_DBG", "Retrieved call from mohqueue");
  286. exit;
  287. }
  288. # queue is empty or something went wrong
  289. }
  290. ...
  291. </programlisting>
  292. </example>
  293. </section>
  294. <section id="count.func">
  295. <title>
  296. <function moreinfo="none">mohq_count (queue_name, pvar)</function>
  297. </title>
  298. <para>
  299. Finds the number of calls that are in a queue. It will not count
  300. calls that are in the process of entering or exiting the queue.
  301. </para>
  302. <para>
  303. The function has two parameters, the name of the queue and the
  304. pseudo-variable which receives the count. The queue name can be
  305. passed as a literal or a pseudo-variable. It can be called from
  306. any route.
  307. </para>
  308. <para>
  309. <emphasis>Return code:</emphasis>
  310. <itemizedlist>
  311. <listitem>
  312. <emphasis>TRUE=successful, pseudo-variable contains count</emphasis>
  313. </listitem>
  314. <listitem>
  315. <emphasis>FALSE=failed, parameters are incorrect</emphasis>
  316. </listitem>
  317. </itemizedlist>
  318. </para>
  319. <example>
  320. <title><function>mohq_count</function> usage:</title>
  321. <programlisting format="linespecific">
  322. ...
  323. $var(mohq) = "operators";
  324. ...
  325. # more than 10 calls?
  326. mohq_count ("$var(mohq)", "$var(mohqcnt)");
  327. if ($var(mohqcnt) > 10) {
  328. xlog ("L_WARN", "$var(mohq) queue has $var(mohqcnt) calls!");
  329. }
  330. ...
  331. </programlisting>
  332. </example>
  333. </section>
  334. </section>
  335. <section id="database">
  336. <title>Database Schema</title>
  337. <para>
  338. mohqueue uses two external database tables to manage the queues and
  339. provide status information to outside processes. Internally, it keeps
  340. a volatile database in memory of call status. If the module is
  341. restarted it loses the internal database and clears the external
  342. one.
  343. </para>
  344. <para>
  345. On a reqular basis it checks the external table that defines the
  346. queues to see if the definition has changed. It makes this check
  347. under the following conditions: the queue has not been checked in the
  348. last 60 seconds <emphasis>AND</emphasis> no call is currently in
  349. queue or transitioning in or out. The last condition prevents
  350. existing calls from being adversely affected by queue redefinitions.
  351. </para>
  352. <section id="mohqueues.dbase">
  353. <title>MOHQUEUES Table</title>
  354. <para>
  355. This table controls the definition of the queue. The name is set by
  356. the <ulink url="#table.parms">db_qtable</ulink> parameter. There is
  357. no internal function to modify the table so it must be configured
  358. externally. It contains the following fields:
  359. <itemizedlist>
  360. <listitem>
  361. <emphasis>id</emphasis> (integer): unique identifier that is created
  362. automatically. <emphasis>Do not attempt to change this value.</emphasis>
  363. </listitem>
  364. <listitem>
  365. <emphasis>name</emphasis> (25-character string, required): the queue name.
  366. Duplicate names are not allowed.
  367. </listitem>
  368. <listitem>
  369. <emphasis>uri</emphasis> (100-character string, required): the URI of
  370. the queue. It should not include any parameters or headers (e.g.
  371. "sip:user@host;maddr=239.255.255.1" or "sip:user@host?subject=project")
  372. although it will match any RURI that contains this URI even if the
  373. RURI has parameters or headers. Duplicates are not allowed.
  374. </listitem>
  375. <listitem>
  376. <emphasis>mohdir</emphasis> (100-character string, optional): path to
  377. the directory where the audio files for the queue are stored. This path
  378. overrides the one provided by the <ulink url="#dir.parms">mohdir</ulink>
  379. parameter. If the directory is not accessible by the module the queue
  380. is not activated.
  381. </listitem>
  382. <listitem>
  383. <emphasis>mohfile</emphasis> (100-character string, required): the
  384. base name of the audio file. See the section about
  385. <ulink url="#audiofiles">audio files</ulink> for more information
  386. about file names. If no files matching this name are found in the
  387. directory the queue is not activated.
  388. </listitem>
  389. <listitem>
  390. <emphasis>debug</emphasis> (integer, required): enables debugging
  391. messages for the queue. If non-zero, it will send debugging messages
  392. to the log for conditions that involve the queue, whether or not
  393. Kamailio has logging enabled for debugging. If zero, it depends on
  394. Kamailio's log level.
  395. </listitem>
  396. </itemizedlist>
  397. </para>
  398. </section>
  399. <section id="mohqcalls.dbase">
  400. <title>MOHQCALLS Table</title>
  401. <para>
  402. This table contains the status of calls that are in queue, or
  403. transitioning in or out of a queue. The name is set by the
  404. <ulink url="#table.parms">db_ctable</ulink> parameter. This table
  405. is read-only for external processes and its contents should
  406. <emphasis>not be modified</emphasis>. It contains the following
  407. fields:
  408. <itemizedlist>
  409. <listitem>
  410. <emphasis>id</emphasis> (integer): unique identifier that is created
  411. automatically.
  412. </listitem>
  413. <listitem>
  414. <emphasis>mohq_id</emphasis> (integer, required): the id value of the
  415. queue.
  416. </listitem>
  417. <listitem>
  418. <emphasis>call_status</emphasis> (integer, required): the status of
  419. the call. 1=entering; 2=in queue (listening to MOH); 3=leaving
  420. </listitem>
  421. <listitem>
  422. <emphasis>call_from</emphasis> (100-character string, required): the
  423. contents of the <varname>From</varname> header field.
  424. </listitem>
  425. <listitem>
  426. <emphasis>call_id</emphasis> (100-character string, required): the
  427. contents of the <varname>Call-ID</varname> header field.
  428. </listitem>
  429. <listitem>
  430. <emphasis>call_contact</emphasis> (100-character string, optional):
  431. the contents of the <varname>Contact</varname> header field, if it
  432. exists.
  433. </listitem>
  434. <listitem>
  435. <emphasis>call_time</emphasis> (datetime, required): time the call
  436. entered the queue. If a <ulink url="#retrieve.func">retrieve</ulink>
  437. fails this time is not changed.
  438. </listitem>
  439. </itemizedlist>
  440. </para>
  441. </section>
  442. </section>
  443. <section id="audiofiles">
  444. <title>Audio Files</title>
  445. <para>
  446. When rtpproxy negotiates to determine which media to use in the audio
  447. stream it uses the files in the MOH directory as defined by the
  448. <ulink url="#mohqueues.dbase">MOHQUEUES</ulink> table. The table
  449. defines the location of the files and the base name used to identify
  450. each. The actual stream type depends on the RTP payload number that
  451. is part of the name. The complete file name for each stream is
  452. composed of <varname>mohdir/mohfile.type</varname>. For example,
  453. <varname>/var/kamailio/MOH/HeWillCall.8</varname> would be the file
  454. for payload type 8 (PCMA/8000).
  455. </para>
  456. <para>
  457. The supported types and their order of preference are:
  458. <itemizedlist>
  459. <listitem><emphasis>9</emphasis>: G722/8000</listitem>
  460. <listitem><emphasis>0</emphasis>: PCMU/8000</listitem>
  461. <listitem><emphasis>8</emphasis>: PCMA/8000</listitem>
  462. <listitem><emphasis>18</emphasis>: G729/8000</listitem>
  463. <listitem><emphasis>3</emphasis>: GSM/8000</listitem>
  464. <listitem><emphasis>4</emphasis>: G723/8000</listitem>
  465. <listitem><emphasis>15</emphasis>: G728/8000</listitem>
  466. <listitem><emphasis>5</emphasis>: DVI4/8000</listitem>
  467. <listitem><emphasis>7</emphasis>: LPC/8000</listitem>
  468. <listitem><emphasis>12</emphasis>: QCELP/8000</listitem>
  469. <listitem><emphasis>13</emphasis>: CN/8000</listitem>
  470. <listitem><emphasis>16</emphasis>: DVI4/11025</listitem>
  471. <listitem><emphasis>6</emphasis>: DVI4/16000</listitem>
  472. <listitem><emphasis>17</emphasis>: DVI4/22050</listitem>
  473. <listitem><emphasis>10</emphasis>: L16/44100</listitem>
  474. <listitem><emphasis>11</emphasis>: L16/44100</listitem>
  475. <listitem><emphasis>14</emphasis>: MPA/90000</listitem>
  476. </itemizedlist>
  477. </para>
  478. <para>
  479. See <ulink url="http://en.wikipedia.org/wiki/RTP_audio_video_profile">
  480. RTP Audio Video Profile</ulink> for more information about RTP
  481. payload types.
  482. </para>
  483. </section>
  484. </chapter>